Compile FFmpeg from Source with VP9 libvpx
This guide provides a straightforward, step-by-step walkthrough for
compiling FFmpeg from source code with libvpx enabled,
allowing you to encode high-quality VP9 video. You will learn how to
install the necessary build prerequisites, compile the latest version of
libvpx, and configure and install FFmpeg with VP9 support
on a Linux-based system.
Step 1: Install Dependencies and Build Tools
Before compiling, you need to install the essential compilation tools and libraries. Update your package manager and install the required packages.
For Ubuntu/Debian-based systems, run:
sudo apt update
sudo apt install -y build-essential git pkg-config yasm nasm clean-up cmakeNote: yasm or nasm are highly
recommended for optimizing the assembly code performance of both
libvpx and FFmpeg.
Step 2: Create a Workspace Directory
Create a directory structure to keep your source code and build files organized:
mkdir -p ~/ffmpeg_sources ~/ffmpeg_build ~/binStep 3: Download and Compile libvpx
libvpx is the official VP8/VP9 video encoder library
from the WebM project. To compile it from source:
Navigate to the source directory and clone the repository:
cd ~/ffmpeg_sources git clone --depth 1 https://chromium.googlesource.com/webm/libvpx.gitMove into the directory, configure the build, compile, and install it:
cd libvpx ./configure --prefix="$HOME/ffmpeg_build" --disable-examples --disable-unit-tests --enable-vp9-highbitdepth --as=yasm make -j$(nproc) make install
Step 4: Download and Compile FFmpeg
With libvpx compiled, you can now configure FFmpeg to
link against it.
Navigate to the source directory and clone the FFmpeg repository:
cd ~/ffmpeg_sources git clone --depth 1 https://git.ffmpeg.org/ffmpeg.git ffmpegMove into the FFmpeg directory:
cd ffmpegConfigure the build. You must define the paths to the newly compiled
libvpxinside~/ffmpeg_buildusingPKG_CONFIG_PATH: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="$HOME/bin" \ --enable-gpl \ --enable-libvpx \ --enable-nonfreeCompile and install FFmpeg:
PATH="$HOME/bin:$PATH" make -j$(nproc) make install hash -r
Step 5: Verify the Installation
To verify that your newly compiled FFmpeg binary is installed and includes VP9 support, run the following commands:
Check the binary location and version:
~/bin/ffmpeg -versionVerify that the libvpx-vp9 encoder is available:
~/bin/ffmpeg -encoders | grep libvpxThe output should list libvpx-vp9 as an active encoder,
indicating the compilation was successful. You can now use FFmpeg to
encode WebM VP9 videos.