Skip to content

Add yuv422p to supported_np_pix_fmts - #2405

Merged
WyattBlue merged 1 commit into
PyAV-Org:mainfrom
dylanpulver:advertise-yuv422p
Sep 1, 2026
Merged

Add yuv422p to supported_np_pix_fmts#2405
WyattBlue merged 1 commit into
PyAV-Org:mainfrom
dylanpulver:advertise-yuv422p

Conversation

@dylanpulver

Copy link
Copy Markdown
Contributor

supported_np_pix_fmts is described in the source as "pix_fmts supported by Frame.to_ndarray() and Frame.from_ndarray()", and it is exported in frame.pyi, but it is missing yuv422p. yuv422p has 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.names plus the advertised set (to cover aliases such as gray8, which is not in names) and calling to_ndarray() on a 32x16 frame: 86 formats convert, the set lists 85, and yuv422p is the only difference in either direction. On PyPI av 18.1.0 it also round-trips byte-identically through from_ndarray.

Nothing caught it because every check on the set is assert format in supported_np_pix_fmts inside tests/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 from to_ndarray() itself. It needs names in av/video/format.pyi, which was missing (mypy flags it), so that line is here too.

Mutants, each rebuilt and the marker checked in the built module rather than the source:

  • revert the set entry: test_ndarray_yuv422p and the new test both fail
  • the opposite remedy, dropping yuv422p from to_ndarray so the set is right: the new test passes and test_ndarray_yuv422p fails, which is what pins the direction
  • advertise a format that does not convert (yuv411p): only the new test fails, so the second loop in it is doing work

macOS arm64, Python 3.12, FFmpeg 8.1.2: pytest tests gives 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-only and mypy av tests are clean apart from the pre-existing av/video/plane.pyi:1 types.CapsuleType error, which is identical on a clean tree here. No CHANGELOG.rst entry, 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.

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.
@WyattBlue
WyattBlue merged commit 06262e2 into PyAV-Org:main Sep 1, 2026
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants