Skip to content

Expose hardware devices to filter graphs - #2404

Open
happyme531 wants to merge 1 commit into
PyAV-Org:mainfrom
happyme531:upstream/filter-hw-device
Open

Expose hardware devices to filter graphs#2404
happyme531 wants to merge 1 commit into
PyAV-Org:mainfrom
happyme531:upstream/filter-hw-device

Conversation

@happyme531

Copy link
Copy Markdown

Summary

  • add a public HWDevice wrapper around an FFmpeg AVHWDeviceContext
  • allow Graph(hw_device=device) and attach an independent AVBufferRef to filters declaring AVFILTER_FLAG_HWDEVICE before initialization
  • keep a strong Python reference for the graph lifetime without exposing raw pointers
  • document and type the API, including VideoFrame as a valid buffer template

Motivation

Hardware filters such as hwupload require AVFilterContext.hw_device_ctx, but PyAV currently has no public way to provide one. This implements the device-context part of the hardware-filter plumbing discussed in #2218. AVHWFramesContext plumbing for hardware-decoded buffer sources remains separate work.

Lifetime handling

HWDevice owns the reference returned by av_hwdevice_ctx_create. Each compatible filter receives its own av_buffer_ref before avfilter_init_dict, and normal filter-context destruction releases that reference. The graph also retains the Python HWDevice object.

Validation

  • ruff format --check av tests
  • isort --check-only av tests
  • mypy av tests: success, 96 source files
  • ARM64 wheel built on RK3588 against FFmpeg 8.1
  • tests/test_filters.py: 18 passed
  • downstream RKMPP validation covered software-frame hwupload, hardware scaling, hwdownload, and direct DRM PRIME encoding

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