Repository navigation
Add VA-API hardware decoding (--vaapi, --vaapi-device) - #9
Open
bernhardberger wants to merge 1 commit into
Open
bernhardberger wants to merge 1 commit into
bernhardberger wants to merge 1 commit into
Conversation
Attach a VA-API device to the native libavcodec decoder so its default get_format uses the VAAPI hwaccel when the GPU supports the codec and profile, and decodes in software when it does not. Decoded surfaces are downloaded (NV12, or P010 which the existing 8-bit conversion handles) together with their frame properties, so pts, picture type, key frame flag and A53 caption side data are unchanged. The device is not attached when --qsv/--cuvid/--dxva2/--vdpau already selected a decoder, nor with lowres, which hwaccels do not implement. A device that cannot be opened is logged and decoding continues in software; 25 consecutive frame download failures abort instead of silently dropping frames.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Adds
--vaapiand--vaapi-device=<path>(implies--vaapi) for Intel and AMD GPUs on Linux. The device is attached to the native decoder rather than selecting a separate decoder, so libavcodec's default get_format uses the VAAPI hwaccel when the GPU supports the codec and profile and decodes in software when it does not (MPEG-2 on recent AMD GPUs, for example). Surfaces are downloaded with their frame properties, so pts, picture type, key frame flag and A53 captions pass through unchanged; 10-bit P010 goes through the existing 8-bit conversion.The device is not attached when
--qsv/--cuvid/--dxva2/--vdpaualready chose a decoder (cuvid would read the VAAPI context as CUDA), nor withlowres. An unusable device is logged and decoding falls back to software; 25 consecutive frame download failures abort rather than drop frames. With-v 1the log says whether VA-API is active for the stream. Only libavutil's generic hwcontext API is used, so builds without VAAPI compile unchanged and fall back at runtime.Verified on an AMD Radeon 760M (Mesa 25.0 radeonsi, FFmpeg 7.1) against the same binary without
--vaapi: cut list, frame CSV and SRT byte-identical on a 720p60 H.264 recording with 608 captions and on a HEVC Main10 clip; cut lists identical on two long 720p50 H.264 sports recordings and a 7 h SD MPEG-2 recording (software fallback); four concurrent--vaapiruns match a single run. Also checked--vaapi-device=/dev/null, a missing device,--cuvid --vaapi,--qsv --vaapiandlowres=1. Builds cleanly against libavcodec 59 (Debian 12), 60 (Ubuntu 24.04) and 61 (Debian 13).Timings with
thread_count=2, capped at two cores:--vaapiVA-API always saves CPU; wall time only drops when software decoding is the bottleneck. Low-bitrate H.264 decodes about as fast in software as through VA-API plus the download. On Main10 the per-frame P010 to YUV420P swscale conversion dominates (ffmpeg alone decodes and downloads that clip in 13 s); a luma-only conversion would be a separate change.