Compile FFMPEG for Ubuntu

FFMPEG is Swiss army knife, powerful yet light-weighted, and you will find a lot of commercial products are based on that. Here is a tutorial on how to compile it under Ubuntu 22.04.1. The procedure would work under other Linux Debian distribution too.

  • Install compilers and development tools

If yo haven’t done, here are all needed compile tools, you need install them before you can compile ffmpeg.

sudo apt-get update -qq && sudo apt-get -y install 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 \
pkg-config texinfo wget yasm zlib1g-dev cmake nasm libx264-dev libx265-dev libnuma-dev libvpx-dev libfdk-aac-dev \
libmp3lame-dev libopus-dev openssl libssl-dev libmfx-dev libzmq3-dev libssh-dev libdrm-dev libopenal-dev \
zlib1g-dev uuid-dev libmnl-dev gcc make git autoconf autoconf-archive autogen automake pkg-config curl \
uuid-dev zlib1g-dev libjson-c-dev gcc make autoconf automake pkg-config autoconf libuv1-dev net-tools \
g++ build-essential libxslt-dev wmctrl libgeoip-dev ninja-build meson

  • Create work folders

We will create two forders for source the build, all depenances will be in them. You can remove them afterwards.

mkdir -p ~/ffmpeg_sources && mkdir -p ~/ffmpeg_build

  • Build AOM

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_SHARED=off -DENABLE_NASM=on ../aom && \
PATH=”$HOME/bin:$PATH” make -j$(nproc) && \
sudo make install

  • Optional build VMAF

VMAF is an Emmy-winning perceptual video quality assessment algorithm developed by Netflix. You will need it if you’re interested in video quality, especially comparison of encoded video and its source.

Remove optioin –enable-libvmaf if you dont need it.

cd ~/ffmpeg_sources && \
git clone https://github.com/Netflix/vmaf.git && \
cd ~/ffmpeg_sources/vmaf/libvmaf && \
meson build –buildtype release && \
sudo ninja -vC build && \
sudo ninja -vC build install

  • Optional build ZVBI

ZVBI is needed if you want to decode DVB Teletext subtitles.

Remove optioin –enable-libzvbi if you dont need it.

cd ~/ffmpeg_sources && \
wget https://sourceforge.net/projects/zapping/files/zvbi/0.2.35/zvbi-0.2.35.tar.bz2 && \
tar xvf zvbi-0.2.35.tar.bz2 && \
cd ./zvbi-0.2.35 && \
./configure –prefix=”/” –bindir=”/bin” && \
make -j$(nproc) && \
sudo make install

  • Optional build Zeromq

ZeroMQ is the asynchronous messaging library for distributed/concurrent computing that does not require a dedicated message broker/server. This messaging library has seen wide usage by a number of prominent companies while FFmpeg’s avformat code now makes optional use of it too. I found it’s very useful to send message to a running ffmpeg thread.

Remove optioin –enable-libzmq if you dont need it.

cd ~/ffmpeg_sources && wget https://github.com/zeromq/libzmq/releases/download/v4.3.4/zeromq-4.3.4.tar.gz && \
tar xvzf zeromq-4.3.4.tar.gz && \
cd zeromq-4.3.4 && \
./configure && \
sudo make install -j$(nproc) && \
sudo ldconfig

  • Optional build with ablity to decode SRT stream

Remove optioin –enable-libsrt if you dont need it.

cd ~/ffmpeg_sources && \
git clone https://github.com/Haivision/srt.git && \
cd ~/ffmpeg_sources/srt && \
./configure && \
make -j$(nproc) && sudo make install

  • Finally, download and build FFMPEG snpashot version

You maybe download a formal release version like this:

wget -O ffmpeg-5.1.tar.gz https://ffmpeg.org/releases/ffmpeg-5.1.tar.gz

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” \
–bindir=”/bin” \
–enable-gpl \
–enable-libaom \
–enable-libass \
–enable-libfdk-aac \
–enable-libfreetype \
–enable-libmp3lame \
–enable-libopus \
–enable-libvorbis \
–enable-libvpx \
–enable-libx264 \
–enable-libx265 \
–enable-nonfree \
–enable-libzvbi \
–enable-libzmq \
–enable-libmfx \
–enable-openssl \
–enable-libsrt \
–enable-libvmaf –enable-version3 && \
PATH=”$HOME/bin:$PATH” make -j$(nproc) && \
sudo make install && \
make tools/zmqsend
sudo cp tools/zmqsend /usr/bin/zmqsend
hash -r
cd ~/

ffmpeg should be installed and can be confirmed by “which ffmpeg && ffmpeg”

/usr/bin/ffmpeg
ffmpeg version 5.1 Copyright (c) 2000-2022 the FFmpeg developers
built with gcc 11 (Ubuntu 11.3.0-1ubuntu1~22.04)
configuration: –prefix=/home/engineering/ffmpeg_build –pkg-config-flags=–static –extra-cflags=-I/home/engineering/ffmpeg_build/include –extra-ldflags=-L/home/engineering/ffmpeg_build/lib –extra-libs=’-lpthread -lm’ –bindir=/bin –enable-gpl –enable-libaom –enable-libass –enable-libfdk-aac –enable-libfreetype –enable-libmp3lame –enable-libopus –enable-libvorbis –enable-libvpx –enable-libx264 –enable-libx265 –enable-nonfree –enable-libzvbi –enable-libzmq –enable-libmfx –enable-libssh –enable-openal –enable-opencl –enable-opengl –enable-libdrm –enable-cuda –enable-cuvid –enable-nvdec –enable-nvenc –enable-libnpp –extra-cflags=-I/usr/local/cuda/include –extra-ldflags=-L/usr/local/cuda/lib64 –enable-openssl –enable-libsrt –enable-libvmaf –enable-version3
libavutil 57. 28.100 / 57. 28.100
libavcodec 59. 37.100 / 59. 37.100
libavformat 59. 27.100 / 59. 27.100
libavdevice 59. 7.100 / 59. 7.100
libavfilter 8. 44.100 / 8. 44.100
libswscale 6. 7.100 / 6. 7.100
libswresample 4. 7.100 / 4. 7.100
libpostproc 56. 6.100 / 56. 6.100
Hyper fast Audio and Video encoder
usage: ffmpeg [options] [[infile options] -i infile]… {[outfile options] outfile}…