A full ffmpeg without root

I needed text overlays, AAC audio and H.264 video on a machine where I couldn't install anything. apt still did most of the work, just not the installing part.
The situation
The only ffmpeg on the machine came bundled with a browser automation tool. It was built with --disable-everything: enough to record a browser to WebM, nothing more. No drawtext, no libx264, no audio encoders. There was no sudo, so apt install ffmpeg was out.
Step 1: let apt list the packages
--print-uris makes apt calculate everything it would download, without installing anything. That calculation needs no root.
apt-get install --reinstall -y --print-uris ffmpeg 2>&1 \
| grep -oP "^'[^']+'" | tr -d "'" > uris.txt
wc -l uris.txt
On my machine that was 106 packages. Packages that are already installed are left out, which is what you want: the system already has them.
Step 2: download and unpack
dpkg-deb -x only extracts files. It doesn't touch the package database, so it doesn't need root either.
mkdir pkgs sysroot
cd pkgs && wget -q -i ../uris.txt && cd ..
for f in pkgs/*.deb; do dpkg-deb -x "$f" sysroot/; done
Step 3: point the loader at it
SYSROOT=$PWD/sysroot
LIB=$SYSROOT/usr/lib/x86_64-linux-gnu
export LD_LIBRARY_PATH=$LIB:$LIB/pulseaudio
$SYSROOT/usr/bin/ffmpeg -version
The second path is easy to miss. One PulseAudio library lands in a pulseaudio/ subfolder, and ffmpeg won't start without it. Adding that folder to LD_LIBRARY_PATH fixes it.
Check what you got
$SYSROOT/usr/bin/ffmpeg -hide_banner -filters | grep drawtext
$SYSROOT/usr/bin/ffmpeg -hide_banner -encoders | grep -E 'libx264|aac'
If both lines show up, you have the full build.
Limits
- The packages must come from the same distribution release as the machine, which is why asking that machine's own apt works.
- Nothing is installed system-wide. On a fresh machine you repeat the three steps, so keep them in a script.
Get new articles by email
Only when a new article is out. No ads. Details →