CompilationGuide - Ubuntu - FFmpeg
CompilationGuide - Ubuntu - FFmpeg
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.
autoconf \
automake \
build-essential \
cmake \
git-core \
libass-dev \
libfreetype6-dev \
libgnutls28-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
Note: Server users can omit the ffplay and x11grab dependencies: libsdl2-dev libva-dev
libvdpau-dev libxcb1-dev libxcb-shm0-dev libxcb-xfixes0-dev.
https://trac.ffmpeg.org/wiki/CompilationGuide/Ubuntu 1/8
8/17/2021 CompilationGuide/Ubuntu – FFmpeg
In your home directory make a new directory to put all of the source code and binaries into:
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.
NASM
An assembler used by some libraries.
If your repository provides nasm version ≥ 2.13 then you can install that instead of compiling:
cd ~/ffmpeg_sources && \
cd nasm-2.15.05 && \
./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.
If your repository provides libx264-dev version ≥ 118 then you can install that instead of compiling:
cd ~/ffmpeg_sources && \
cd x264 && \
https://trac.ffmpeg.org/wiki/CompilationGuide/Ubuntu 2/8
8/17/2021 CompilationGuide/Ubuntu – FFmpeg
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.
If your repository provides libx265-dev version ≥ 68 then you can install that instead of compiling:
Warning: Currently and unlike other libraries, you have to get the full libx265 repository (so remove --depth
1 argument in git clone). Indeed, it will be longer, but it is necessary to allow generating x265.pc file, which is
needed to build ffmpeg with --enable-libx265. Without this, ffmpeg build will be broken.
If you cannot, or don't want to get the full libx265 repository, please use the version provided by apt instead.
cd ~/ffmpeg_sources && \
cd x265_git/build/linux && \
make install
libvpx
VP8/VP9 video encoder/decoder. See the VP9 Video Encoding Guide for more information and usage examples.
If your repository provides libvpx-dev version ≥ 1.4.0 then you can install that instead of compiling:
cd ~/ffmpeg_sources && \
cd libvpx && \
make install
libfdk-aac
AAC audio encoder. See the AAC Audio Encoding Guide for more information and usage examples.
https://trac.ffmpeg.org/wiki/CompilationGuide/Ubuntu 3/8
8/17/2021 CompilationGuide/Ubuntu – FFmpeg
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:
cd ~/ffmpeg_sources && \
cd fdk-aac && \
make && \
make install
libmp3lame
MP3 audio encoder.
If your repository provides libmp3lame-dev version ≥ 3.98.3 then you can install that instead of compiling:
cd ~/ffmpeg_sources && \
wget -O lame-3.100.tar.gz
https://downloads.sourceforge.net/project/lame/lame/3.100/lame-3.100.tar.gz &&
\
cd lame-3.100 && \
make install
libopus
If your repository provides libopus-dev version ≥ 1.1 then you can install that instead of compiling:
cd ~/ffmpeg_sources && \
cd opus && \
./autogen.sh && \
./configure --prefix="$HOME/ffmpeg_build" --disable-shared && \
make && \
make install
https://trac.ffmpeg.org/wiki/CompilationGuide/Ubuntu 4/8
8/17/2021 CompilationGuide/Ubuntu – FFmpeg
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.
cd ~/ffmpeg_sources && \
cd aom_build && \
make install
libsvtav1
AV1 video encoder/decoder. Only the encoder is supported by FFmpeg, so building of the decoder is disabled.
cd ~/ffmpeg_sources && \
cd SVT-AV1/build && \
make install
libdav1d
If your repository provides libdav1d-dev, you can install that instead of compiling:
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:
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 && \
cd dav1d/build && \
https://trac.ffmpeg.org/wiki/CompilationGuide/Ubuntu 5/8
8/17/2021 CompilationGuide/Ubuntu – FFmpeg
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 && \
cd vmaf-2.1.1/libvmaf/build && \
ninja install
FFmpeg
cd ~/ffmpeg_sources && \
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 && \
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.
https://trac.ffmpeg.org/wiki/CompilationGuide/Ubuntu 6/8
8/17/2021 CompilationGuide/Ubuntu – 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:
You may have to log out and then log in for man ffmpeg to work.
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:
hash -r
You may also remove packages that have been installed from this guide:
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.
https://trac.ffmpeg.org/wiki/CompilationGuide/Ubuntu 7/8
8/17/2021 CompilationGuide/Ubuntu – FFmpeg
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).
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.
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.
Also See
Generic FFmpeg Compilation Guide
H.264 Video Encoding Guide
AAC Audio Encoding Guide
Note:
See TracWiki
for help on using the wiki.
https://trac.ffmpeg.org/wiki/CompilationGuide/Ubuntu 8/8