Skip to content

Compile FFmpeg by yourself

  • by

FFmpeg is an open-source video encode/decode CLI utility. It’s so powerful that nearly everyone has used it in some ways. Never mention those big companies like Microsoft, Google, Netflix, Amazon etc.

So… You may have a powerful workstation now. And it has a beefy CPU. (We won’t talk about hardware encoding today, because that will be so complicated and even myself haven’t figured out the correct way to integrate Intel QSV or NVENC into FFmpeg, there are weird errors everywhere. So we only talk about software encoding today, even that’s very slow compared to hardware encoding.)

Bullshit aside, let’s get started.

Requirements

You’ll need a Linux-based computer, with good CPU, otherwise you may spend A TON of time on compiling. I’m using Ubuntu here. But Debian is also okay.

A good network.

Be at least 5GB storage. (Come on, who don’t have that?)

Patience.

Compile and Install

Install dependencies.

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

sudo apt install libunistring-dev libaom-dev

Create a working directory.

mkdir -p ~/ffmpeg_sources ~/bin

Here I will compile all dependencies instead of installing them by the package manager, since compiling them is usually the best way to ensure both speed and compatibility.

I won’t talk about every step, that will make this article too long, so I will put all commands in one snippet.

Make sure your computer isn’t running anything CPU intensive, that will make the computer really slow, and everything will become really laggy.

cd ~/ffmpeg_sources && \
wget https://www.nasm.us/pub/nasm/releasebuilds/2.15.05/nasm-2.15.05.tar.bz2 && \
tar xjvf nasm-2.15.05.tar.bz2 && \
cd nasm-2.15.05 && \
./autogen.sh && \
PATH=”$HOME/bin:$PATH” ./configure –prefix=”$HOME/ffmpeg_build” –bindir=”$HOME/bin” && \
make -j$(nproc) && \
sudo make install

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 -j$(nproc) && \
sudo make install

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 -j$(nproc) && \
sudo make install

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 -j$(nproc) && \
sudo make install

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 -j$(nproc) && \
sudo make install

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 -j$(nproc) && \
sudo make install

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 -j$(nproc) && \
sudo make install

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

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 && \
sudo ninja install

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

Now all the dependencies are compiled and installed, it’s time to compile 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 -j$(nproc) && \
sudo make install && \
hash -r

It may take a while, but after it’s done. BOOM, your very own FFmpeg is in your home directory and installed as an executable.

Run FFmpeg to execute that.

Cool huh.

Hope you enjoy your very own FFmpeg and have a great day 🙂

References

FFmpeg official compilation guide: https://trac.ffmpeg.org/wiki/CompilationGuide/Ubuntu

Leave a Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.