Add yuv422p to supported_np_pix_fmts - #2405
Merged
Merged
Conversation
yuv422p has been handled by both to_ndarray() and from_ndarray() since PyAV-Org#2054, but that PR did not add it to supported_np_pix_fmts, so the public set under-reports what the library converts. The existing checks are all of the form 'assert format in supported_np_pix_fmts', which cannot catch a missing entry, so the new test derives the answer from to_ndarray() over av.video.format.names instead. That needs 'names' in the format stub, which was missing.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
supported_np_pix_fmtsis described in the source as "pix_fmts supported byFrame.to_ndarray()andFrame.from_ndarray()", and it is exported inframe.pyi, but it is missingyuv422p.yuv422phas worked in both directions since #2054, whose patch never mentions the set — #1766 added the set in Feb 2025, #2054 added the format in Dec 2025.Sweeping all 267 names in
av.video.format.namesplus the advertised set (to cover aliases such asgray8, which is not innames) and callingto_ndarray()on a 32x16 frame: 86 formats convert, the set lists 85, andyuv422pis the only difference in either direction. On PyPIav18.1.0 it also round-trips byte-identically throughfrom_ndarray.Nothing caught it because every check on the set is
assert format in supported_np_pix_fmtsinsidetests/test_videoframe.py— the assertion iterates the set it is validating, so an omission cannot fail it.test_ndarray_yuv422p, added by #2054, is one of the tests without even that line. So rather than adding another such assertion alone, the new test derives the expected set fromto_ndarray()itself. It needsnamesinav/video/format.pyi, which was missing (mypyflags it), so that line is here too.Mutants, each rebuilt and the marker checked in the built module rather than the source:
test_ndarray_yuv422pand the new test both failyuv422pfromto_ndarrayso the set is right: the new test passes andtest_ndarray_yuv422pfails, which is what pins the directionyuv411p): only the new test fails, so the second loop in it is doing workmacOS arm64, Python 3.12, FFmpeg 8.1.2:
pytest testsgives 531 passed / 30 skipped / 55 subtests before and 532 / 30 / 55 after, both legs in the same session with the built module checked each time.ruff format --check,isort --check-onlyandmypy av testsare clean apart from the pre-existingav/video/plane.pyi:1 types.CapsuleTypeerror, which is identical on a clean tree here. NoCHANGELOG.rstentry, following #2054.AI assistance: the diff, the test and this description were drafted by Claude Opus 5 working as a coding agent in this repository.