Skip to content

Add hardware-accelerated encoding via add_stream(hwaccel=...)#2326

Merged
WyattBlue merged 1 commit into
mainfrom
patch
Jun 24, 2026
Merged

Add hardware-accelerated encoding via add_stream(hwaccel=...)#2326
WyattBlue merged 1 commit into
mainfrom
patch

Conversation

@WyattBlue

Copy link
Copy Markdown
Member

Previously PyAV only supported hardware decoding. Passing a hardware encoder (e.g. h264_vaapi) software frames failed at avcodec_open2 with EINVAL because no hw_device_ctx/hw_frames_ctx was ever set up.

add_stream now accepts a hwaccel argument. For an encoder it attaches the device context, lazily builds the hw_frames_ctx in open() once width/height/pix_fmt are known, and uploads software frames to the device in _prepare_frames_for_encode. HWAccel setup now also accepts encoders, which advertise the HW_FRAMES_CTX method rather than HW_DEVICE_CTX.

fixes #2156

Previously PyAV only supported hardware decoding. Passing a hardware
encoder (e.g. h264_vaapi) software frames failed at avcodec_open2 with
EINVAL because no hw_device_ctx/hw_frames_ctx was ever set up.

add_stream now accepts a hwaccel argument. For an encoder it attaches the
device context, lazily builds the hw_frames_ctx in open() once
width/height/pix_fmt are known, and uploads software frames to the device
in _prepare_frames_for_encode. HWAccel setup now also accepts encoders,
which advertise the HW_FRAMES_CTX method rather than HW_DEVICE_CTX.

fixes #2156
@WyattBlue WyattBlue merged commit b0560f2 into main Jun 24, 2026
8 checks passed
@WyattBlue WyattBlue deleted the patch branch June 24, 2026 01:21
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.

VA-API encoding fails on Ubuntu 25.10 with PyAV 16.1.0

1 participant