Skip to content

Apply reformat shortcut to hardware frames too#2323

Open
CarlosRDomin wants to merge 1 commit into
PyAV-Org:mainfrom
CarlosRDomin:fix/hwframe-reformat-shortcut
Open

Apply reformat shortcut to hardware frames too#2323
CarlosRDomin wants to merge 1 commit into
PyAV-Org:mainfrom
CarlosRDomin:fix/hwframe-reformat-shortcut

Conversation

@CarlosRDomin

@CarlosRDomin CarlosRDomin commented Jun 22, 2026

Copy link
Copy Markdown
Contributor

This is a small follow-up to #2321

When VideoFrame.reformat is called on a hardware frame, PyAV first downloads it into a software frame. If that downloaded frame already matches the requested output format, size, colorspace and color range, we can return it directly instead of passing it through swscale. This avoids unnecessary e.g. nv12 -> nv12 swscale conversions after hardware download, which besides being inefficient actually modify pixel values even though no format/size conversion is requested. Without my change to reformatter.py, the test I introduce in test_decode.py fails on the latest PyAV (both main and 17.1.0).

The included test compares:

  • a hwaccel frame decoded with is_hw_owned=False, which PyAV downloads directly, and
  • a hwaccel frame decoded with is_hw_owned=True and then reformatted to the same software format.

With the shortcut, both paths preserve identical pixel data and the test passes.

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.

1 participant