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.

4 Likes

One of the more powerful features that ffmpeg offers is the ability to chain audio and video filters, sources, and etc. into filtergraphs. Most of the individual filters have settings (some of them very complex) that can be tweaked when the defaults will not do. Sometimes, it is hard to know just how a particular filtergraph will affect the outcome of your video.

The ffmpeg package is designed to build three CLI binaries: ffmpeg, ffprobe, and ffplay. ffplay is designed to be a “testbed” for filtergraphs. It will accept any filtergraph that ffmpeg will, and plays the results immediately on the desktop.

The Simple DirectMedia Layer library (libsdl2) is required for ffplay to work; the ffmpeg build script will not build ffplay if libsdl2 is not detected. In turn, libsdl2 will not be able to render video and audio on Clear Linux unless the following two bundles are installed before libsdl2 is built:

devpkg-libX11
devpkg-pulseaudio

So, if you want ffplay,

  1. install the bundles
  2. build libsdl2
  3. build ffmpeg (libsdl2 will be autodetected)

Besides being a testbed for ffmpeg, ffplay is an excellent media player in its own right. It is not susceptible to video tearing and pixellating, seamlessly plays variable bit-rate video files, and seems to handle many other video files that give VLC all sorts of trouble.

Well, while that may be true for Centos, it’s not true for Clear Linux.

{shrug} Seemed reasonable, since the ffmpeg build instructions for centos work for CL, and CL has RPM-handling tools available. So, what is CL descended from?

It’s pretty much built from scratch from the ground up - https://www.youtube.com/watch?v=ZQnfgO1rCFE

3 Likes
--enable-hardcoded-tables

may be a useful option.

It results in an increase of approximately 15% in the size of libavcodec, the main library impacted by this change. It enables savings in table generation time, done once at codec initialization, since by hardcoding the tables, they do not need to be computed at runtime.

By default, this is not enabled.

1 Like