wiki:CompilationGuide/Ubuntu

Compile FFmpeg for Ubuntu, Debian, or Mint

This guide for standard support releases of Ubuntu, Debian, and Linux Mint and will provide a local, non-system installation of FFmpeg with several external libraries.

You may also refer to the Generic Compilation Guide for additional information about compiling software.

Recent static builds are also available for lazy people or those who are unable to compile. The static builds do not support non-free libraries.

Note: FFmpeg is part of the Ubuntu packages and can be installed via apt-get install ffmpeg. You may still wish to compile if you want the latest version, experience a bug, or want to customize your build, and it will not interfere with the ffmpeg package in the repository.

This guide is designed to be non-intrusive and will create several directories in your home directory:

  • ffmpeg_sources – Where the source files will be downloaded. This can be deleted if desired when finished with the guide.
  • ffmpeg_build – Where the files will be built and libraries installed. This can be deleted if desired when finished with the guide.
  • bin – Where the resulting binaries (ffmpeg, ffplay, ffprobe, x264, x265) will be installed.

You can easily undo any of this as shown in Reverting Changes Made by This Guide.


Get the Dependencies

These are packages required for compiling, but you can remove them when you are done if you prefer:

sudo apt-get update -qq && sudo apt-get -y install \
  autoconf \
  automake \
  build-essential \
  cmake \
  git-core \
  libass-dev \
  libfreetype6-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 \
  zlib1g-dev

On Ubuntu 20.04 you may also need this command: (note)

sudo apt install libunistring-dev libaom-dev libdav1d-dev

Note: Server users can omit the ffplay and x11grab dependencies: libsdl2-dev libva-dev libvdpau-dev libxcb1-dev libxcb-shm0-dev libxcb-xfixes0-dev.

In your home directory make a new directory to put all of the source code and binaries into:

mkdir -p ~/ffmpeg_sources ~/bin

Compilation & Installation

This guide assumes that you want to install some of the most common third-party libraries. Each section provides you with the commands needed to install that library.

For each section, copy-paste the entire code-block into your shell.

If you do not require certain features, you may skip the relevant section (if it is not required) and then remove the appropriate ./configure option in FFmpeg. For example, if libvpx is not needed, skip that section and then remove --enable-libvpx from the Install FFmpeg section.

Tip: To significantly speed up the compilation process on systems with multiple cores, you can use the -j option with each make command to set the number of compilation jobs allowed to run simultaneously, such as make -j4. To set this to the number of available logical CPU cores, use make -j$(nproc). The -j option also works with the ninja build system used to compile some of the libraries in this guide. Using all cores may cause your machine to become slow or unresponsive.

NASM

An assembler used by some libraries.

If your repository provides nasm version ≥ 2.13 then you can install that instead of compiling:

sudo apt-get install nasm

Otherwise you can compile:

cd ~/ffmpeg_sources && \
wget https://www.nasm.us/pub/nasm/releasebuilds/2.16.01/nasm-2.16.01.tar.bz2 && \
tar xjvf nasm-2.16.01.tar.bz2 && \
cd nasm-2.16.01 && \
./autogen.sh && \
PATH="$HOME/bin:$PATH" ./configure --prefix="$HOME/ffmpeg_build" --bindir="$HOME/bin" && \
make && \
make install

libx264

H.264 video encoder. See the H.264 Encoding Guide for more information and usage examples.

Requires ffmpeg to be configured with --enable-gpl --enable-libx264.

If your repository provides libx264-dev version ≥ 118 then you can install that instead of compiling:

sudo apt-get install libx264-dev

Otherwise you can compile:

cd ~/ffmpeg_sources && \
git -C x264 pull 2> /dev/null || git clone --depth 1 https://code.videolan.org/videolan/x264.git && \
cd x264 && \
PATH="$HOME/bin:$PATH" PKG_CONFIG_PATH="$HOME/ffmpeg_build/lib/pkgconfig" ./configure --prefix="$HOME/ffmpeg_build" --bindir="$HOME/bin" --enable-static --enable-pic && \
PATH="$HOME/bin:$PATH" make && \
make install

libx265

H.265/HEVC video encoder. See the H.265 Encoding Guide for more information and usage examples.

Requires ffmpeg to be configured with --enable-gpl --enable-libx265.

If your repository provides libx265-dev version ≥ 68 then you can install that instead of compiling:

sudo apt-get install libx265-dev libnuma-dev

Otherwise you can compile:

sudo apt-get install libnuma-dev && \
cd ~/ffmpeg_sources && \
wget -O x265.tar.bz2 https://bitbucket.org/multicoreware/x265_git/get/master.tar.bz2 && \
tar xjvf x265.tar.bz2 && \
cd multicoreware*/build/linux && \
PATH="$HOME/bin:$PATH" cmake -G "Unix Makefiles" -DCMAKE_INSTALL_PREFIX="$HOME/ffmpeg_build" -DENABLE_SHARED=off ../../source && \
PATH="$HOME/bin:$PATH" make && \
make install

libvpx

VP8/VP9 video encoder/decoder. See the VP9 Video Encoding Guide for more information and usage examples.

Requires ffmpeg to be configured with --enable-libvpx.

If your repository provides libvpx-dev version ≥ 1.4.0 then you can install that instead of compiling:

sudo apt-get install libvpx-dev

Otherwise you can compile:

cd ~/ffmpeg_sources && \
git -C libvpx pull 2> /dev/null || git clone --depth 1 https://chromium.googlesource.com/webm/libvpx.git && \
cd libvpx && \
PATH="$HOME/bin:$PATH" ./configure --prefix="$HOME/ffmpeg_build" --disable-examples --disable-unit-tests --enable-vp9-highbitdepth --as=yasm && \
PATH="$HOME/bin:$PATH" make && \
make install

libfdk-aac

AAC audio encoder. See the AAC Audio Encoding Guide for more information and usage examples.

Requires ffmpeg to be configured with --enable-libfdk-aac (and --enable-nonfree if you also included --enable-gpl).

If your repository provides libfdk-aac-dev then you can install that instead of compiling:

sudo apt-get install libfdk-aac-dev

Otherwise you can compile:

cd ~/ffmpeg_sources && \
git -C fdk-aac pull 2> /dev/null || git clone --depth 1 https://github.com/mstorsjo/fdk-aac && \
cd fdk-aac && \
autoreconf -fiv && \
./configure --prefix="$HOME/ffmpeg_build" --disable-shared && \
make && \
make install

libopus

Opus audio decoder and encoder.

Requires ffmpeg to be configured with --enable-libopus.

If your repository provides libopus-dev version ≥ 1.1 then you can install that instead of compiling:

sudo apt-get install libopus-dev

Otherwise you can compile:

cd ~/ffmpeg_sources && \
git -C opus pull 2> /dev/null || git clone --depth 1 https://github.com/xiph/opus.git && \
cd opus && \
./autogen.sh && \
./configure --prefix="$HOME/ffmpeg_build" --disable-shared && \
make && \
make install

libaom

AV1 video encoder/decoder:

Warning: libaom does not yet appear to have a stable API, so compilation of libavcodec/libaomenc.c may occasionally fail. Just wait a day or two for us to catch up with these annoying changes, re-download ffmpeg-snapshot.tar.bz2, and try again. Or skip libaom altogether.

OR, you can try your repo sudo apt install libsvtav1-dev libsvtav1enc-dev libsvtav1dec-dev; the packages are available in the ubuntu/universe repo for 22.04, 24.04.

cd ~/ffmpeg_sources && \
git -C aom pull 2> /dev/null || git clone --depth 1 https://aomedia.googlesource.com/aom && \
mkdir -p aom_build && \
cd aom_build && \
PATH="$HOME/bin:$PATH" cmake -G "Unix Makefiles" -DCMAKE_INSTALL_PREFIX="$HOME/ffmpeg_build" -DENABLE_TESTS=OFF -DENABLE_NASM=on ../aom && \
PATH="$HOME/bin:$PATH" make && \
make install

libsvtav1

AV1 video encoder/decoder. Only the encoder is supported by FFmpeg, so building of the decoder is disabled.

Requires ffmpeg to be configured with --enable-libsvtav1.

cd ~/ffmpeg_sources && \
git -C SVT-AV1 pull 2> /dev/null || git clone https://gitlab.com/AOMediaCodec/SVT-AV1.git && \
mkdir -p SVT-AV1/build && \
cd SVT-AV1/build && \
PATH="$HOME/bin:$PATH" cmake -G "Unix Makefiles" -DCMAKE_INSTALL_PREFIX="$HOME/ffmpeg_build" -DCMAKE_BUILD_TYPE=Release -DBUILD_DEC=OFF -DBUILD_SHARED_LIBS=OFF .. && \
PATH="$HOME/bin:$PATH" make && \
make install

libdav1d

AV1 decoder, much faster than the one provided by libaom.

Requires ffmpeg to be configured with --enable-libdav1d.

If your repository provides libdav1d-dev, you can install that instead of compiling:

sudo apt-get install libdav1d-dev

Otherwise you'll need can build from source. Users whose distributions don't provide a recent enough version of meson (0.49.0 or newer) will need to install a more up-to-date version. This is easily done via the Python Package Index:

sudo apt-get install python3-pip && \
pip3 install --user meson

NASM version 2.14 or newer is required for AVX-512 support. See the NASM section for how to install/build. Alternatively, disable AVX-512 in Meson setup with -Denable_avx512=false.

To compile:

cd ~/ffmpeg_sources && \
git -C dav1d pull 2> /dev/null || git clone --depth 1 https://code.videolan.org/videolan/dav1d.git && \
mkdir -p dav1d/build && \
cd dav1d/build && \
meson setup -Denable_tools=false -Denable_tests=false --default-library=static .. --prefix "$HOME/ffmpeg_build" --libdir="$HOME/ffmpeg_build/lib" && \
ninja && \
ninja install

libvmaf

Library for calculating the VMAF video quality metric. Requires ffmpeg to be configured with --enable-libvmaf. Currently an issue in libvmaf also requires FFmpeg to be built with --ld="g++" for a static build to succeed.

To compile:

cd ~/ffmpeg_sources && \
wget https://github.com/Netflix/vmaf/archive/v3.0.0.tar.gz && \
tar xvf v3.0.0.tar.gz && \
mkdir -p vmaf-3.0.0/libvmaf/build &&\
cd vmaf-3.0.0/libvmaf/build && \
meson setup -Denable_tests=false -Denable_docs=false --buildtype=release --default-library=static .. --prefix "$HOME/ffmpeg_build" --bindir="$HOME/bin" --libdir="$HOME/ffmpeg_build/lib" && \
ninja && \
ninja install

FFmpeg

cd ~/ffmpeg_sources && \
wget -O ffmpeg-snapshot.tar.bz2 https://ffmpeg.org/releases/ffmpeg-snapshot.tar.bz2 && \
tar xjvf ffmpeg-snapshot.tar.bz2 && \
cd ffmpeg && \
PATH="$HOME/bin:$PATH" PKG_CONFIG_PATH="$HOME/ffmpeg_build/lib/pkgconfig" ./configure \
  --prefix="$HOME/ffmpeg_build" \
  --pkg-config-flags="--static" \
  --extra-cflags="-I$HOME/ffmpeg_build/include" \
  --extra-ldflags="-L$HOME/ffmpeg_build/lib" \
  --extra-libs="-lpthread -lm" \
  --ld="g++" \
  --bindir="$HOME/bin" \
  --enable-gpl \
  --enable-gnutls \
  --enable-libaom \
  --enable-libass \
  --enable-libfdk-aac \
  --enable-libfreetype \
  --enable-libmp3lame \
  --enable-libopus \
  --enable-libsvtav1 \
  --enable-libdav1d \
  --enable-libvorbis \
  --enable-libvpx \
  --enable-libx264 \
  --enable-libx265 \
  --enable-nonfree && \
PATH="$HOME/bin:$PATH" make && \
make install && \
hash -r

Tip: The configure error message XYZ not found using pkg-config is often misleading, namely when the library was found but,for instance, test compilation went wrong.
In case of trouble with configure, it may be helpful have a look at the log file it produces: ffbuild/config.log which contains a lot of detail.

Due to an unresolved x265 bug/feature with threads library (see https://bitbucket.org/multicoreware/x265_git/issues/371/x265-not-found-using-pkg-config) sometimes it's needed to add

--extra-libs="-lpthread" 

switch to the configure script, as suggested above. Otherwise ERROR: x265 not found using pkg-config might pop out.

Now re-login or run the following command for your current shell session to recognize the new ffmpeg location:

source ~/.profile

Compilation and installation are now complete and ffmpeg (also ffplay, ffprobe, lame, x264, & x265) should now be ready to use. The rest of this guide shows how to update or remove FFmpeg.

Usage

You can now open a terminal, enter the ffmpeg command, and it should execute your new ffmpeg.

If you need multiple users on the same system to have access to your new ffmpeg, and not just the user that compiled it, then move or copy the ffmpeg binary from ~/bin to /usr/local/bin.

Documentation

If you want to run man ffmpeg to have local access to the documentation:

echo "MANPATH_MAP $HOME/bin $HOME/ffmpeg_build/share/man" >> ~/.manpath

You may have to log out and then log in for man ffmpeg to work.

HTML formatted documentation is available in ~/ffmpeg_build/share/doc/ffmpeg.

You can also refer to the online FFmpeg documentation, but remember that it is regenerated daily and is meant to be used with the most current ffmpeg (meaning an old build may not be compatible with the online docs).


Updating FFmpeg

Development of FFmpeg is active and an occasional update can give you new features and bug fixes. First you need to delete (or move) the old files:

rm -rf ~/ffmpeg_build ~/bin/{ffmpeg,ffprobe,ffplay,x264,x265}

Now can just follow the guide from the beginning.


Reverting Changes made by this Guide

Remove the build and source files as well as the binaries:

rm -rf ~/ffmpeg_build ~/ffmpeg_sources ~/bin/{ffmpeg,ffprobe,ffplay,x264,x265,nasm}
sed -i '/ffmpeg_build/d' ~/.manpath
hash -r

You may also remove packages that have been installed from this guide:

sudo apt-get autoremove autoconf automake build-essential cmake git-core libass-dev libfreetype6-dev libgnutls28-dev libmp3lame-dev libnuma-dev libopus-dev libsdl2-dev libtool libva-dev libvdpau-dev libvorbis-dev libvpx-dev libx264-dev libx265-dev libxcb1-dev libxcb-shm0-dev libxcb-xfixes0-dev texinfo wget yasm zlib1g-dev

FAQ

Why install to ~/bin?

  • Avoids installing files into any system directories.
  • Avoids interfering with the package management system.
  • Avoids conflicts with the ffmpeg package from the repository.
  • Super simple to uninstall.
  • Does not necessarily require sudo or root: useful for shared server users as long as they have the required dependencies available.
  • ~/bin is already in the vanilla Ubuntu PATH (see ~/.profile).
  • User is free to move ffmpeg to any other desired location (such as /usr/local/bin).

Why are the commands in this guide so complicated?

It is to make compiling easy and convenient for the user. This guide:

  • Confines everything to the user's home directory (see the previous FAQ question above).
  • Is intended to be usable on all currently supported versions of Debian and Ubuntu.
  • Allows the user to choose if they want to compile certain libraries (latest and greatest) or to simply install the version from their repository (fast and easy but older).

This results in some various additional commands and configurations instead of the typical and simple ./configure, make, make install.

make[1]: Nothing to be done for 'all'/'install'

This is message from libvpx that occasionally makes users think something went wrong. You can ignore this message. It just means make is finished doing its work.

How do I compile to a 32-bit Ubuntu target on an Ubuntu 64-bit host?

sudo apt install gcc-multilib
./configure --extra-cflags="-m32"  --extra-ldflags="-m32" ...`
make clean
make

If You Need Help

Feel free to ask your questions at the #ffmpeg IRC channel or the ffmpeg-user mailing list.


Also See

Last modified 6 months ago Last modified on May 16, 2024, 9:02:13 PM
Note: See TracWiki for help on using the wiki.