Research-2166: what VMAFx touches in FFmpeg, measured (RC4 WP15)¶
- Status: Active
- Workstream: ADR-2165
- Last updated: 2026-10-07
An audit of the FFmpeg patch series, its build hygiene, the correctness of the paths the vmafx filters take, and every other place the repository builds an FFmpeg command line or an FFmpeg image. Everything below was run, not read, unless a row says UNVERIFIED. User documentation is ffmpeg.md; the series is described in ffmpeg-patches/README.md.
1. Method¶
- Tree: the series of
rc4/api-wp9-ffmpeg(24 patches:0001to0020and thevmafxpatches0021to0024) on FFmpegn9.0.2, replayed one commit per patch (python3 scripts/ci/ffmpeg_patch_stack.py --check). - Compilers on the development host: gcc 16.2.1 and clang 23.1.1. gcc 14, clang 22 and MSVC were not available; the Windows legs of CI do not build FFmpeg, so MSVC is unmeasured.
- Each compiler built the unpatched release and the patched tree with x264, aom and SVT-AV1 enabled (so patch
0007compiles) and-Wextraadded to FFmpeg's own warning set. Clang's full-tree log was produced withmake -Otarget, because parallel clang output interleaves. The per-patch counts rebuild only the 36 objects the series touches, serially, and attribute each diagnostic to a patch withgit blame. - Runtime: the CPU filter against the
vmafCLI on the 576x324 pair and the 4K BBB pair; CUDA on an RTX 4090 (host frames,hwupload, and NVENC to NVDEC loopback); an AddressSanitizer, UndefinedBehaviorSanitizer and LeakSanitizer FFmpeg build over 17 option and error paths. - Frame-rate, end-of-stream and report-path probes use the files of
python/test/resource/yuv; they are reproduced bypython3 ffmpeg-patches/test/vmafx_filter_check.py contract.
2. The series¶
17 of the 24 patches are retired by WP10 (0001 to 0006, 0008, 0010 to 0018, 0020); 0007, 0009, 0019 and 0021 to 0024 stay. vf_libvmaf.c grows from 828 to 2408 lines because four filters share it. Dead code today: the Vulkan shims 0004 and 0006 (601 patch lines, the Vulkan hunks of nine other patches, a pkg-config probe of a removed header on every configure), the cpumask / gpumask / score_fmt tables copied four times, and three options that only log a line (-pass-autotune, -vmaf-profile, -vmafx-profile).
Against FFmpeg master (c0c7684, 9.1-dev) the patches that add lines inside sorted lists (configure, libavfilter/Makefile, allfilters.c, doc/filters.texi) conflict whenever upstream adds a neighbour: 0008, 0013, 0021, 0022. 0019 conflicts in lcevc_parser.c and svq1enc.c (19 of its 50 files changed upstream). 0007, 0009, 0023 and 0024 replay unchanged. The filter sources are already generated from ffmpeg-patches/src/ at replay time; the list edits are the remaining context-sensitive hunks.
3. Build hygiene¶
Compiler diagnostics, full tree, FFmpeg's default warning set:
| Compiler | Unpatched n9.0.2 | Series |
|---|---|---|
| gcc 16.2.1 | 42 | 7 (none in a file of the series: Vulkan stack-usage, unused-function, calloc-transposed-args, an SDL header) |
| clang 23.1.1 | 6 | 6 (the same six: VAAPI AV1 deprecated fields, unused-function, macro-redefined) |
The 36 translation units of the series and of 0019: 28 default-flag diagnostics before 0019 on gcc, 0 after; 0 on clang. Under -Wextra, 50 (gcc) and 55 (clang) diagnostics sit on lines the series authored; 44 and 49 of them are -Wmissing-field-initializers on the closing {NULL} of an AVOption table, the FFmpeg-wide convention (589 and 618 of the unpatched tree's diagnostics are the same class). The rest, identical on both compilers, were six: vf_vmafx.c host_wrap() (unused s), the Vulkan shim hunk in vf_libvmaf.c, and four -Wsign-compare lines 0019 introduced in a64multienc.c, svq1enc.c and vlc.c. No translation unit of the series uses a deprecated FFmpeg API (-Wdeprecated-declarations: 0 on both compilers).
4. Correctness findings (all reproduced)¶
| Finding | Evidence | State |
|---|---|---|
| A reference shorter than the main stream is scored against its last frame: 24 reference frames under 48 main frames gave 89.659227, the CLI over the 24 pairs 96.580028 | contract check "short reference" | fixed, ADR-2165 |
| Frame rates 25 and 30 fps pair by timestamp without a message (81.745866 against 95.938231 at one rate) | contract check "unequal frame rates" | warned, counted |
A filter with no scored frame (enable=0) fails the command: vmafx_flush on an empty context returns -22, exit 187 | contract check "timeline-disabled" | fixed |
log_path in a missing directory failed after the last frame, exit 0, no report | contract check "unwritable log_path" | fixed |
-qpfile on libx264 (patch 0007) cannot work: libx264 has no qpfile key (CLI only), x264_param_parse refuses it and the encoder does not open; the aom and SVT-AV1 branches encode | ffmpeg -c:v libx264 -qpfile on libx264 165 | fixed in a separate PR (patch 0007) |
-frames:v N on the output scores N or N+1 pairs (CUDA 4K: 60 against 62 host frames, VMAF 77.745 against 78.055) | two identical CUDA runs | documented: cut each input |
Checked and clean: metadata=1 returns every frame in order (also with a short reference, a late reference and a timeline-disabled filter); n_stats windows by seconds and by frames equal the CLI pooled offline; the CUDA filter on host frames, on hwupload frames and on the NVDEC loopback of patch 0024 is bit-identical to vmaf --backend cuda (golden pair 722 of 722 values, 4K 452 of 452, loopback 96 frames imported on the device, 0 host); 17 option and error paths under ASan, UBSan and LSan report nothing (FFmpeg side; libvmafx is not instrumented). Not measured: the SYCL, HIP and VAAPI / DRM paths (no libvmafx build of those backends here); drm_open() creates the device from device= and not from the frames' DRM device, which would import on the wrong GPU of a host with two GPUs of one vendor (UNVERIFIED).
5. Where time goes (RC7 backlog; profiled, not tuned)¶
| Measurement | Result |
|---|---|
CPU, 4K, 40 frames, threads=0 | filter 1.475 to 1.610 s, CLI 1.469 to 1.545 s |
CPU, same, threads=4 | filter 0.79 to 0.88 s, CLI 0.78 to 0.85 s |
perf share of the CPU run | libvmafx 91.2 %, libc 2.7 %, FFmpeg 0.07 % |
| Hot frames of the default model at 4K | quick_select 6.8 %, picture_copy 3.9 %, decimate_generic_uint8_and_convert_to_10b 4.2 %, then ADM and motion kernels at 5 to 7 % each |
| CUDA, 4K, 60 frames | host frames 0.424 s, hwupload import 0.48 to 0.49 s, CLI 0.438 to 0.443 s |
The filter adds nothing measurable on the CPU; the hwupload copy costs more than the library's own host path on a short run. Not measured: framesync queue depth (no knob), window cost, SYCL and HIP imports. The tool pipelines of section 6 spawn a process and write a raw file per probe.
6. FFmpeg outside the patches¶
The sweep covered the Go packages (pkg/encoder, pkg/hwdevice, pkg/ffencode, pkg/corpus, pkg/fast, pkg/hdr, pkg/bisect, pkg/predictor, pkg/saliency), tools/vmaf-tune, ai/scripts, the container files and the workflows, and the recipes under docs/. The state rows T-FFMPEG-*-2026-10-07 in state.md carry the findings; the groups are:
- Commands that cannot work: NVENC constant-quality probes without
-b:v 0are capped at FFmpeg's 2 Mbit/s default; the per-shot probe passes a frame index to-ss(seconds);-master_displayand-max_clldo not exist forhevc_nvencin 9.0.2;-x264-params qpfile=is ignored by libx264; several features each append their own-x265-params/-svtav1-paramsand FFmpeg keeps the last; two recipes feed NV12 straight tolibvmaf_cuda, which acceptsyuv420pandyuv444p16only. - No image or CI job configures
--enable-libvmafx, and the check scriptvmafx_filter_check.pyruns in no workflow, so the new filters are compiled nowhere outside the replay. - Needless host copies (RC7): every score decodes to a raw YUV file and spawns the
vmafCLI; no tool scores through an FFmpeg graph.