Skip to content

how to use hardware flter? #2218

Closed
Closed

Description

@MeshHun

Are there any examples for hardware filters?

Activity

  1. MeshHun commented on Mar 30, 2026

    @MeshHun
    Author
    cmd = [
            'ffmpeg', '-y',
            '-init_hw_device', 'd3d11va=dx', 
            '-init_hw_device', 'qsv=hw@dx', 
            '-filter_hw_device', 'hw',
            '-hwaccel', 'qsv',
            '-hwaccel_output_format', 'qsv',
            '-i', input_path,
            '-i', watermark_path,
            '-filter_complex', (
                f"[0:v]vpp_qsv=w={target_width}:h=-1[bg]; " 
                f"[1:v]format=bgra,hwupload,format=qsv[wm]; "    
                f"[bg][wm]overlay_qsv=x=W-w-10:y=H-h-10" 
            ),
            
    
            '-c:v', 'h264_qsv',
            '-global_quality', '28',
            '-preset', '4',         
            # '-look_ahead', '1',
            
            '-c:a', 'copy',
            output_path
        ]
    

    Pyav can do these?

  2. WyattBlue commented on May 6, 2026

    @WyattBlue
    Member

    PyAV currently supports hardware decoding (via HWAccel + av.open(..., hwaccel=...)) and hardware encoding (just pick an encoder like h264_qsv on the output stream) (see examples/basics/hw_decode.py)

    However, hardware filters like vpp_qsv, overlay_qsv, scale_qsv, hwupload, and hwdownload are not currently supported through PyAV's filter graph API. Those filters require attaching an AVHWDeviceContext to the filter graph (and/or an AVHWFramesContext to the buffer source via av_buffersrc_parameters_set), and PyAV's av.filter.Graph doesn't expose either of those bindings yet.

    So a direct PyAV port of your command isn't possible today. Workarounds:

    1. Software filter, hardware codecs: decode with QSV, transfer frames to system memory (frame.to_ndarray() / software overlay), then encode with h264_qsv. You lose the zero-copy benefit of vpp_qsv + overlay_qsv.
    2. Shell out to ffmpeg for the parts of the pipeline that need hardware filters; PyAV and the ffmpeg CLI can coexist.

    If anyone wants to take a shot at adding hw_device_ctx to Graph and hw_frames_ctx plumbing to the buffer source, that would be the path to making this work natively.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions