Skip to content

Conversation

@ndeybach
Copy link
Contributor

This pull request adds binding for find_best_pix_fmt_of_list, to the codec module.

The function helps determine the best pixel format for conversion given a source format and a list of candidates, and reports potential information loss. It helps do it without actually running a filter (such as the format filter), which is heavy and unnecessary when you just want the information as fast as possible in python...

Actual implementation:

  • Implemented the function in Cython in av/codec/codec.pyx, wrapping FFmpeg's avcodec_find_best_pix_fmt_of_list, . Added the corresponding Cython extern declaration for avcodec_find_best_pix_fmt_of_list in include/libavcodec/avcodec.pxd.
  • Added find_best_pix_fmt_of_list to the public API in av/codec/__init__.py and documented its signature and behavior in the type stub av/codec/codec.pyi. It handles both string and VideoFormat inputs.
  • Finds the best pixel format to convert to, given a source format and a list of candidates, returning both the best format and a bitmask of conversion losses.

Testing:

  • Added some test functions to tests/test_codec.py to verify correct behavior, edge cases, and error handling for find_best_pix_fmt_of_list.

Allows to test for which pixel format to target before conversion without actively running filters or similar.

- added logic / tests / type hints for avcodec_find_best_pix_fmt_of_list
- named it on python's side: find_best_pix_fmt_of_list
- forgot to run ruff linter before
- removed a forgottent space
@WyattBlue WyattBlue merged commit 3e5b4a1 into PyAV-Org:main Dec 16, 2025
6 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