Tips and techniques for building ffmpeg

FFMPEG is a powerful and essential tool for anyone who works with multimedia. It can transcode from nearly every format ever developed, to almost as many formats as it can decode. It can reconfigure media containers and copy streams from container to container without re-encoding the streams (which saves time and preserves quality). It can concatenate clips together into a stream, and produce video and audio clips from longer streams; at least one video editor application uses ffmpeg to do the actual editing. FFMPEG can take input from nearly any source, and produce streaming Internet broadcasts as well as writing to files. It also offers a dizzying array of filters, generators, and other processing options for video, audio, and still images.

Unfortunately, as a result of rights and licensing issues, a good part of ffmpeg’s functionality has to be provided by third party libraries. This can make ffmpeg a challenge to build—just finding and downloading the sources for all the different libraries is a job and a half. FFMPEG’s build script will also stop configuring if things are not just right, and the error messages tend to be somewhat cryptic. This list of tips is an attempt to alleviate some of the pain.

  • The ffmpeg website includes loads of guides and articles. The main one for building ffmpeg on Clear is the CompilationGuide/Centos – FFmpeg. (Like Clear, Centos is a derivative of Red Hat.)

  • Zeranoe has a website where he posts ffmpeg builds for Windows. What is useful here is his README files, posted to the same downloads page, where he lists URLs to all the libraries he uses.

  • FFMPEG takes the CLI front end/library back end model of software construction to extremes. It extracts objects from the third party libraries it uses, and creates its own libraries. Because ffmpeg generates so many files, it is probably best to use the default install location of /usr/local for ffmpeg, its libraries, and the third party libraries used to build it all.

  • FFMPEG relies heavily on pkgconfig to find the third party libraries it is told to use. The ‘path’ statement to help the ffmpeg build script find its libraries on most Clear installations would usually be:
    export PKG_CONFIG_PATH='/usr/local/lib/pkgconfig:/usr/local/lib64/pkgconfig:/usr/lib64/pkgconfig:/usr/lib64/haswell/pkgconfig'

  • FFMPEG does build nicely with the link-time optimizer, but putting -flto in the flags or configuring with --enable-lto tends to cause the build to fail with lots of undefined symbols. Instead, put -ffat-lto-objects in the flags (already there if you use the default CFLAGS that comes with Clear) so that the linker has a fallback. Do be sure to include --extra-ldflags='-flto -fuse-linker-plugin' --ar=gcc-ar.

  • FFMPEG builds three CLI binaries (ffmpeg, ffplay, and ffprobe), and provides the option to link them to the ffmpeg libraries statically or dynamically. I choose static build for ffmpeg and all the third party libraries on the presumption that the opportunity for the link-time optimizer to process all the code is maximized.

  • My command line to configure ffmpeg looks like this:
    ../ffmpeg/configure --pkg-config-flags=--static --extra-cflags=-I/usr/local/include --extra-ldflags='-L/usr/local/lib -L/usr/local/lib64 -flto -fuse-linker-plugin' --ar=gcc-ar --extra-libs='-lpthread -lm' --enable-libaom --enable-libmp3lame --enable-libopus --enable-libvidstab --enable-libvpx --enable-libx264 --enable-libx265 --enable-libvorbis --enable-libtheora --enable-libfdk-aac --enable-gpl --enable-version3 --enable-nonfree --disable-podpages

  • The third party libraries must be built with the same version of gcc that ffmpeg is built. I leave the third party libraries on my system, but have to rebuild them all before rebuilding ffmpeg.