Repository navigation
Adding or Updating a Library
Read Contributing first. Open an issue and get the change agreed before you write it. Then read Architecture so the steps below make sense.
A library change touches the build of seven platforms. The traps below all happened in the v1.0.47 updates. Each one built green and shipped the wrong thing.
-
Find the pin. Versions are set in
ffmpeg-base.dockerfile, in theENVblock near the top (for exampleopenssl_version=4.0.3). Some steps set their own version at the top of the script (for examplewhisper_version=1.9.1inscripts/48-whisper.sh). -
Find the download. It is in
ffmpeg-base.dockerfile, or inside the script. A tarball goes throughfetch-pinnedand has a SHA-256. A git source has a tag. -
Change the version, and the SHA-256 with it. Compute the digest of the real upstream file:
sha256sum <file>. Do not copy a digest from a mirror page you did not check. -
Read the build script. Look for lines that depend on the old version: patches,
sededits, file names in the source tree. - Build all platforms you can. Per-platform differences are common. See Building Locally.
- Check what the binary really contains. A green build does not prove the library is the new one. See the traps below.
-
Open the PR into
dev. Name the old and the new version and say why.
-
Add the version to the
ENVblock inffmpeg-base.dockerfile. -
Add the download. Use
fetch-pinnedfor a tarball:fetch-pinned <file> <sha256> <mirror url> <upstream url> -
Add
scripts/NN-name.sh. Pick a number that puts it after everything it needs. FFmpeg itself is built after all numbered steps. Use an existing script of the same kind as a model. -
In the script, build into
${PREFIX}, then calladd_enable --enable-libnameso FFmpeg's configure uses it. Exit0on success,255to skip on a target, anything else to fail. -
Add a test. See Testing.
-
Say in the PR description what the library adds. The maintainers update Codecs and Libraries after the release.
A version number is a name. A SHA-256 is the file. Without it, a changed upstream tarball changes our binary and nobody notices.
fetch-pinned keeps a file only when its digest matches. It tries the pinned source mirror first and the upstream origin after it, so a mirror that is down does not stop a build, and a wrong file never gets through.
Meson projects can carry "wrap" files. When meson cannot find a dependency, it downloads and builds its own copy.
In glib, the build used --wrap-mode=forcefallback. glib then built its own zlib 1.3.1 and pcre2 10.44 into the Windows and Linux x86_64 binaries, whatever the pins said. Everything looked fine because the build was green.
What to do:
- Never use
forcefallbackfor a dependency we build ourselves. Use--wrap-mode=nodownloadso meson fails instead of downloading. - After configure, assert that no wrap was used.
scripts/50-librsvg.shfails whensubprojects/zlib-*orsubprojects/pcre2-*exists.
An edit like sed -i '412s/.../.../' works until upstream moves one line. Then it edits the wrong line, or nothing, and the build still passes.
What to do:
- Match by text, not by line number.
- Assert the result. Count the matches before and after, and fail when the count is not what you expect.
-
scripts/57-hls-master-playlist.shshows the pattern: it greps for the new text after thesedand exits with an error when it is missing. - For a patch,
git applyrefuses a patch whose context no longer matches. Thengrep -cfor a line that only the patched code has.scripts/48-whisper.shdoes both.
Some files in scripts/includes/ are whole copies of an FFmpeg file that replace the upstream file at build time.
| Copy | Replaces |
|---|---|
hlsenc.c, hlsplaylist.c, hlsplaylist.h, codecstring.c
|
the HLS muxer files (see HLS Master Playlist) |
af_whisper.c |
FFmpeg's whisper filter (see Whisper Word Timestamps) |
A copy is upstream's file at one release plus our changes. When FFmpeg moves on, the copy still holds the old file. It silently puts back what upstream fixed. This happened with FFmpeg 9.0.2: a copy based on 9.0 would have reverted two buffer-overrun fixes in the playlist parser of hlsenc.c.
So the build checks the SHA-256 of the upstream file each copy is based on. scripts/57-hls-master-playlist.sh and scripts/48-whisper.sh stop the build when FFmpeg's file is a different one.
When the check fails after an FFmpeg bump:
-
Get three files: the old upstream file (the one the copy is based on), our copy, and the new upstream file.
-
Merge them with a three-way merge:
git merge-file -p our-copy.c old-upstream.c new-upstream.c > merged.c -
Resolve any conflict by hand. Do not overwrite our copy with the new file.
-
Put the merged file in
scripts/includes/. -
Replace the SHA-256 in the build script with the SHA-256 of the new upstream file.
-
Rebuild and run the tests for the feature.
Never update only the digest. That turns off the check and brings the problem back.
A library that builds on Linux can fail or behave differently somewhere else.
| Platform | What to watch |
|---|---|
| darwin | Cross files and --archs flags. zlib needs --archs="-arch <arch>" passed as an array so the space stays inside one argument. Steps can be replaced by a file with the same name in scripts/includes/darwin/. |
| windows | The mingw-w64 toolchain lacks some headers. glib 2.88 needed three WinRT headers it does not have, so one upstream commit is reverted by scripts/includes/glib-win32-own-winrt-definitions.patch. |
| linux-x86_64 | Linked against the glibc 2.35 sysroot. The binary must start on every glibc from 2.35 up. |
| freebsd | Has its own link rules in scripts/includes/freebsd_link.sh. |
Build the platform you changed, and name in the PR the platforms you did not build.
A .patch in scripts/includes/ fixes something upstream did not fix yet. The header should say when to drop it. When you bump the library, check whether the new release has the fix. Example: whisper-security-backports.patch carries three whisper.cpp security fixes because whisper.cpp 1.9.5 also moves ggml by hundreds of commits, and ggml is what the filters were measured on.
- The base image changes when you edit
ffmpeg-base.dockerfile, so every platform rebuilds. - A maintainer builds and tests all platforms before merging.
- The Wiki is updated after the release, for what the release changed. See CI and Releases.
Users
Filters and components
- Filter-stemsplit
- Filter-lyricsalign
- Whisper-Language-Detection
- Whisper-Word-Timestamps
- Filter-trailingsilence
- Filter-keydetect
- Filter-beatdetect
- Filter-rubberband
- Muxer-Sprite-Sheet
- Muxer-Chapter-VTT
- Muxer-VOBsub
- Protocol-dvdread
- Protocol-OmniDrive
- Auto-Create-Directories
- AACS-and-BDplus
- HLS-Master-Playlist
- Subtitles-OCR
- HEVC-Alpha
Acceleration and codecs
Contributors