The Complete Guide to Compiling FFmpeg with All Features on Ubuntu

FFmpeg is the Swiss Army knife of multimedia processing, capable of handling almost any audio or video task you can imagine. While you can install pre-built FFmpeg packages from your distribution’s repositories, compiling from source gives you access to the latest features and allows you to customize your build with exactly the components you need.

This guide walks you through compiling FFmpeg with a comprehensive set of features on Ubuntu, including handling common errors along the way.

Why Compile FFmpeg from Source?

  • Access to the latest features and bug fixes
  • Performance optimizations specific to your hardware
  • Support for additional codecs and filters not included in pre-built packages
  • Custom configurations tailored to your specific needs

Prerequisites

This guide assumes you’re running Ubuntu (tested on Ubuntu 24.04 Noble Numbat), have basic familiarity with the terminal, and have sudo privileges.

Step 1: Download FFmpeg Source Code

First, let’s create a directory for our build and download the latest FFmpeg source:

mkdir -p ~/ffmpeg_sources
cd ~/ffmpeg_sources
wget https://ffmpeg.org/releases/ffmpeg-7.1.1.tar.bz2
tar xjf ffmpeg-7.1.1.tar.bz2
cd ffmpeg-7.1.1

Step 2: Install Build Dependencies

FFmpeg requires various development libraries to enable its full feature set. Install them with this command:

sudo apt-get update && sudo apt-get install -y \
  autoconf \
  automake \
  build-essential \
  cmake \
  git \
  libass-dev \
  libfreetype-dev \
  libgnutls28-dev \
  libmp3lame-dev \
  libsdl2-dev \
  libtool \
  libva-dev \
  libvdpau-dev \
  libvorbis-dev \
  libxcb1-dev \
  libxcb-shm0-dev \
  libxcb-xfixes0-dev \
  meson \
  ninja-build \
  pkg-config \
  texinfo \
  wget \
  yasm \
  nasm \
  zlib1g-dev \
  libx264-dev \
  libx265-dev \
  libnuma-dev \
  libvpx-dev \
  libfdk-aac-dev \
  libopus-dev \
  libdav1d-dev \
  libtheora-dev \
  libfribidi-dev \
  libharfbuzz-dev \
  libfontconfig1-dev \
  libpulse-dev \
  libsoxr-dev \
  libspeex-dev \
  libxml2-dev \
  libzvbi-dev \
  libbs2b-dev \
  libsnappy-dev \
  libgsm1-dev \
  libopencore-amrnb-dev \
  libopencore-amrwb-dev \
  libbluray-dev \
  libssh-dev \
  libssl-dev \
  libopenal-dev \
  librubberband-dev \
  libfftw3-dev \
  libopenmpt-dev

Note: Package names can change between Ubuntu versions. If you encounter “Unable to locate package” errors, search for alternative package names with apt search.

Troubleshooting Package Issues

In Ubuntu 24.04 Noble, some package names have changed from previous versions:

  • libfreetype6-dev is now libfreetype-dev
  • git-core is now just git
  • libdc1394-22-dev is now libdc1394-dev

Some packages like libflite-dev might not be available in the standard repositories. You can either:

  • Skip installing them, and omit the corresponding feature from FFmpeg
  • Add additional repositories that contain them
  • Compile them from source (outside the scope of this guide)

Step 3: Configure FFmpeg

Now that we have the dependencies installed, we can configure FFmpeg with our desired features:

./configure \
  --prefix=/usr/local \
  --enable-gpl \
  --enable-version3 \
  --enable-nonfree \
  --enable-shared \
  --enable-libass \
  --enable-libfdk-aac \
  --enable-libfreetype \
  --enable-libmp3lame \
  --enable-libopus \
  --enable-libtheora \
  --enable-libvorbis \
  --enable-libvpx \
  --enable-libx264 \
  --enable-libx265 \
  --enable-pthreads \
  --enable-libspeex \
  --enable-libsoxr \
  --enable-libxml2 \
  --enable-libbluray \
  --enable-libfontconfig \
  --enable-libfribidi \
  --enable-libharfbuzz \
  --enable-libpulse \
  --enable-gnutls

Common Configuration Errors and Solutions

1. Missing FreeType Headers

fatal error: ft2build.h: No such file or directory
#include <ft2build.h>

Solution: Install the FreeType development package:

sudo apt-get install libfreetype-dev

2. NASM/YASM Not Found

nasm/yasm not found or too old. Use --disable-x86asm for a crippled build.

Solution: Install the NASM assembler:

sudo apt-get install nasm

3. LibASS Not Found

ERROR: libass >= 0.11.0 not found using pkg-config

Solution: Install the LibASS development package:

sudo apt-get install libass-dev

4. GnuTLS and OpenSSL Conflict

GnuTLS and OpenSSL must not be enabled at the same time.

Solution: Choose either GnuTLS or OpenSSL, not both:

# Either use
--enable-gnutls
# OR
--enable-openssl

Step 4: Compile and Install FFmpeg

After successful configuration, compile FFmpeg:

make -j$(nproc)

This command uses all your CPU cores for faster compilation. The process may take 10-30 minutes depending on your system’s performance.

Next, install FFmpeg to your system:

sudo make install

Finally, update the shared library cache:

sudo ldconfig

Step 5: Verify the Installation

Check that FFmpeg was installed correctly:

ffmpeg -version

You should see detailed version information, including all the libraries you enabled.

To see a complete list of supported encoders, decoders, and other features:

ffmpeg -buildconf
ffmpeg -encoders
ffmpeg -decoders
ffmpeg -filters

Customizing Your Build

The configuration options provided in this guide enable a comprehensive set of features, but FFmpeg supports many more. You can add or remove options based on your specific needs:

  • For hardware acceleration: --enable-nvenc--enable-cuda--enable-vaapi
  • For additional formats: --enable-libopenmpt--enable-libgsm
  • For audio processing: --enable-librubberband--enable-libsoxr

Consult the FFmpeg Compilation Guide for more options.

Troubleshooting Tips

  1. If compilation fails, check the error message carefully. It usually points to a missing dependency or configuration issue.
  2. If you see errors about libraries not being found, make sure you’ve installed all required development packages.
  3. The configuration log (ffbuild/config.log) contains detailed information about what was tested and what failed. Check this file for troubleshooting.
  4. You can reduce compilation time by only enabling the features you need.
  5. If you’re running out of disk space during compilation, you can use make clean to remove temporary files.

Conclusion

Compiling FFmpeg from source gives you maximum flexibility and the newest features. While it requires more effort than installing pre-built packages, the benefits in performance and functionality are well worth it for many users.

By following this guide, you should now have a fully featured FFmpeg installation optimized for your system. This powerful tool is now ready to handle your video and audio processing tasks with all the capabilities you’ve enabled.

Happy transcoding!

Leave a Reply

en_USEnglish