FFmpeg patch automation¶
The FFmpeg integration follows stable upstream release tags. The root build-config.env owns FFMPEG_REMOTE, FFMPEG_TAG and FFMPEG_COMMIT (the commit the tag names); the patch tooling reads all three from that file. Container ARG defaults are generated mirrors, and publication uses those defaults without a separate release override. Development branches, snapshots and prerelease tags are outside this channel.
A change to a libvmaf public surface that affects the integration updates the patch series in the same pull request (hard rule 11 in agent-hard-rules.md). The commands below are how to check and refresh it.
Shared FFmpeg fix series¶
Fixes to FFmpeg itself are not kept in ffmpeg-patches/. They live in vidiko/ffmpeg-patches, which publishes a signed release tarball per FFmpeg base, and every VMAFx FFmpeg build applies that series first and ffmpeg-patches/series.txt second (ADR-3143). build-config.env pins it:
| Key | Meaning |
|---|---|
FFMPEG_FIX_SERIES_REPO | URL of the repository that publishes the series |
FFMPEG_FIX_SERIES_TAG | the release tag |
FFMPEG_FIX_SERIES_SHA256 | sha256 of ffmpeg-patches-<tag>.tar.gz |
scripts/ci/ffmpeg-shared-series.sh is the only code that fetches and applies it. The patch-stack replay below, ffmpeg-patches/test/build-and-run.sh, the hosted FFmpeg jobs and the four container builds all call it:
# Apply to a checkout of FFMPEG_TAG (commits each patch with git am --3way):
scripts/ci/ffmpeg-shared-series.sh apply /path/to/ffmpeg
# Apply to an unpacked release archive that is not a Git checkout:
scripts/ci/ffmpeg-shared-series.sh apply --method apply /path/to/FFmpeg-n9.0.2
# Only download, verify and unpack into a new directory:
scripts/ci/ffmpeg-shared-series.sh fetch /tmp/ffmpeg-fix-series
The script stops, without applying anything, when:
- the tarball's sha256 is not the pinned one;
- the tarball's
base.envnames another FFmpeg tag or commit thanFFMPEG_TAG/FFMPEG_COMMIT; - a member of the tarball would be written outside its directory;
FFMPEG_FIX_SERIES_VERIFY=cosignis set and cosign is missing, or cosign refuses the release's signedSHA256SUMS.
A failed github.com release download is fetched again with gh release download through the forge API (needs gh and GH_TOKEN or a gh login). The output names the address that failed and the path that ran, while the sha256, SHA256SUMS and signature checks apply unchanged. FFMPEG_FIX_SERIES_DOWNLOAD_SECONDS (\(S\), default 120) bounds each direct download attempt and each forge API fallback attempt through the deadline helper. One script run makes at most \(N = 3\) download calls (tarball, SHA256SUMS and SHA256SUMS.sigstore.json), so the worst-case download time is \(N \times 2 \times S = 6 \times S\) (720 s at the default \(S = 120\)). scripts/ci/ffmpeg_patch_stack.py gives the script max(600, N * 2 * S + 120) seconds, so 840 s when \(S\) is unset.
Whatever the verify mode, the script also downloads the release's SHA256SUMS, prints the tarball's sha256 next to the line it lists and refuses a difference (FFMPEG_FIX_SERIES_SUMS_URL names another location; a FFMPEG_FIX_SERIES_URL override skips this unless it is set).
With the default FFMPEG_FIX_SERIES_VERIFY=auto the signature is checked when cosign is installed; the script's one-line summary says whether it was. The FFmpeg Patch Stack gate installs cosign and requires it. The verified tarball is cached under <cache root>/vmafx/ffmpeg-fix-series/ and unpacked afresh on every run; the container builds cache nothing (FFMPEG_FIX_SERIES_CACHE=none).
Series v0.5.0 holds 39 patches. 0001-0008 are listed below; 0009-0035 are feature and behaviour patches (qsvdec MP4 edit lists, the Dolby Vision dovi_reshape filter, the bt2408_hable tone map and dynamic peak detection for the software, OpenCL, VAAPI and Vulkan tone-map filters, hqdn3d for Vulkan, CUDA, OpenCL and VideoToolbox, a same-colour YUV repack in swscale and the Vulkan export query); their list is the release's series.txt. 0036-0039 are the GCC 15.2 fixes below. All of 0001-0008 but 0002 change FFmpeg's behaviour in every VMAFx build:
| Patch | File | Behaviour |
|---|---|---|
| 0001 | libavutil/vulkan.c | On a device with one queue family, a frame barrier no longer releases the frame to VK_QUEUE_FAMILY_IGNORED. |
| 0002 | 50 files | The GCC 14/16 diagnostics hardening that was ffmpeg-patches/0019; no change for VMAFx builds. |
| 0003 | libavcodec/nvenc.c, nvenc.h | hevc_nvenc with udu_sei=1 drops a user data unregistered SEI that exceeds NVENC's 1024-byte limit for non-VCL NAL units, with a warning, instead of failing the encode. |
| 0004 | libavcodec/nvenc.c, nvenc.h | h264_nvenc and hevc_nvenc do not write a user data unregistered SEI that NVENC would write truncated; the first one is a warning. |
| 0005 | libavutil/hwcontext_vaapi.c | A 10- or 12-bit (P010, P012) Vulkan frame maps to VAAPI: the DRM import accepts the GR1616 chroma plane Vulkan exports. |
| 0006 | libavutil/hwcontext_vulkan.c | The external-memory query of a frames context with DRM format modifier tiling carries the image format list the images are created with. |
| 0007 | libavutil/hwcontext_vulkan.c | On RADV, mapping a Vulkan frame to DRM waits on the CPU for the frame's work, because the importer does not honour the attached sync file. |
| 0008 | libavutil/vulkan.c, libavcodec/ffv1enc_vulkan.c | Command pools start their queue rotation at different queues of a family, and video pools stay on one queue, so decode and encode can run on separate engines. |
| 0036 | tests/checkasm/snowdsp.c | Includes intmath.h before the public headers, so x86/intmath.h no longer redefines av_popcount, av_popcount64 and av_zero_extend (test-only). |
| 0037 | libavcodec/aom_film_grain.c | Checks the predicted luma point count (GCC 15.2 -Wstringop-overflow). |
| 0038 | libavcodec/vvc/intra_template.c | Bounds the reference corner extension (GCC 15.2 -Wstringop-overflow). |
| 0039 | libavcodec/wmalosslessdec.c | Clears the subframe flags as an array. |
A fix to FFmpeg belongs in that repository, not in ffmpeg-patches/. To take a new series release, change the three keys together and run the refresh and the check below.
Check a change locally¶
python3 scripts/ci/ffmpeg_patch_stack.py --check \
--output-dir .workingdir/cache/ffmpeg-patch-stack/manual-check
The check fetches the configured release, applies the shared fix series and replays the complete patch series in order. It fails on a replay conflict or when patches need a canonical refresh. It leaves the tracked patch files and release setting unchanged. Inspect the command output and the diagnostics under the selected output directory when it fails.
The local hook¶
The ffmpeg-patches-apply-check hook runs --refresh against the configured release at both pre-commit and pre-push. It regenerates canonical patches after a successful replay. The hook framework stops the commit or push if tracked files changed, so review and stage those changes before retrying.
The hook runs when a change touches one of these inputs:
- the patch directory and the patch workflow;
- the CI helpers under
scripts/ci/; - the shared build configuration (
build-config.env); - public headers under
core/include/; - Meson build and options files.
An ordinary documentation edit does not select the hook. Install the hooks with make install-hooks; see Automated rule enforcement for what the installed hooks do.
The local FFmpeg source cache¶
The tool does not download FFmpeg on every run. It keeps one bare Git repository per remote and stores each fetched release commit in it under the tag's name, so the hook at every commit and push reads the commit from disk.
- Location:
$XDG_CACHE_HOME/vmafx/ffmpeg-patch-stack/<remote hash>/source.git. WithoutXDG_CACHE_HOMEit is~/.cache/..., on macOS~/Library/Caches/...and on Windows%LOCALAPPDATA%\....--cache-dir <dir>selects another root. - What is verified: the commit of the configured tag must equal
FFMPEG_COMMIT. A cache entry or a network fetch that names another commit fails with both commits in the message; the wrong commit is never stored or used. After a deliberate pin bump the first run fetches the new tag, and the old entry stays unused. - Which path ran: the command output and
receipt.json(source,target_source,cache) saycache hit,fetched into cacheor, for a newer release found by--latest,fetched (unpinned). A newer release has no pin yet: it is always fetched, and--refresh --latestwrites its commit toFFMPEG_COMMITtogether with the tag. - Concurrency: writers hold a lock file next to the repository (waiting at most ten minutes), and a ref moves only after its commit was fetched and verified, so parallel hooks share one entry.
- Self-repair: an empty or corrupt cache directory, or a ref whose objects are gone, is dropped and fetched again. A cached commit that differs from the pin is not repaired silently; delete the directory below to discard it.
To clear the cache, remove <cache root>/vmafx/ffmpeg-patch-stack/.
Refresh the configured release¶
python3 scripts/ci/ffmpeg_patch_stack.py --refresh \
--output-dir .workingdir/cache/ffmpeg-patch-stack/manual-refresh
The refresh regenerates the series only after every patch replays successfully. Review the resulting diff and diagnostics, then run the check again before committing. A conflict requires a code change and another complete replay; a failed refresh is not a valid replacement series. If filesystem failure or a second interruption also prevents rollback, the tool preserves adjacent .ffmpeg-refresh-<filename>-original-* backups for recovery. Keep these until the original files have been restored; the failure receipt identifies failed replacements when recovery can finish reporting.
Continuous checks and release discovery¶
The FFmpeg Patch Stack check registers on every ready pull request to master and every push to master. Two workflow jobs split the work:
| Trigger | What runs | Which release |
|---|---|---|
Pull request, push to master, manual dispatch | Contract tests on every event; fetch and replay of the complete series when the ADR-1140 impact planner selects it | The configured release (FFMPEG_TAG); never discovers a newer one |
| Schedule, 05:43 UTC daily (FFmpeg Release Refresh job) | --refresh --latest, see below | The newest stable upstream release |
The impact planner selects the expensive fetch and replay for core, patch, workflow or CI-authority changes. Unknown inputs take the full validation path. Documentation-only edits finish after the contracts without fetching FFmpeg.
The broad CI pre-commit job skips the ffmpeg-patches-apply-check hook because the independent required check owns its replay and impact routing. Local pre-commit and pre-push runs keep it enabled.
Scheduled release discovery¶
The scheduled updater owns upstream discovery. Renovate no longer opens separate FFmpeg pin-only updates that omit the series rebase. The job runs:
python3 scripts/ci/ffmpeg_patch_stack.py --refresh --latest \
--output-dir "$RUNNER_TEMP/ffmpeg-patch-refresh"
--latest is accepted only with --refresh. It discovers the highest stable nX.Y or nX.Y.Z upstream release tag and replays the complete series onto it. Development, RC and snapshot refs are excluded.
The pinned shared fix series targets one FFmpeg release. When a newer release exists, the refresh therefore stops with FFmpeg n9.1 is released, but the pinned shared fix series v0.5.0 targets n9.0.2 (with the tags of the day), writes nothing to the tree, and keeps the rebased candidate patches under <output-dir>/patches. Move FFMPEG_FIX_SERIES_TAG and FFMPEG_FIX_SERIES_SHA256 to a series release for the new FFmpeg together with FFMPEG_TAG and FFMPEG_COMMIT, then run --refresh.
The job uploads a ffmpeg-patch-refresh-<run-id>-<attempt> artifact, retained for 14 days, containing:
- the tool's diagnostics;
- the command log;
source-revision.txt;worktree-status.txt;proposed-refresh.patch.
The diff includes tracked generated configuration mirrors as well as the patch series. Review it against the recorded source revision before applying it to an isolated branch and running the configured-release check.
A replay conflict leaves the scheduled job failed and retains its diagnostics. The workflow has read-only repository permissions and creates no pull request, merge or release tag. The scheduled result is a proposal for maintainer review.
Test the automation contract¶
These tests cover replay behavior, hook triggers, PR-versus-schedule separation, impact routing and propagation of command failures through diagnostic capture.