How to Compile FFmpeg with OpenH264 Support

Compiling FFmpeg with OpenH264 support allows you to utilize Cisco’s H.264 encoder/decoder library, which is useful for WebRTC and applications requiring a royalty-free H.264 codec. This guide provides a direct, step-by-step walkthrough to prepare your system, install the OpenH264 library, configure FFmpeg with the appropriate compilation flags, and build the binaries.

Step 1: Install Build Dependencies

Before compiling, you need to install the necessary build tools and libraries. On Debian-based systems (like Ubuntu), run the following command:

sudo apt update
sudo apt install -y build-essential git pkg-config yasm nasm

Step 2: Install the OpenH264 Library

You must have the OpenH264 development headers and library installed. You can install it via your package manager or compile it from source.

Option A: Install via Package Manager (Easiest)

On Ubuntu/Debian:

sudo apt install -y libopenh264-dev

Option B: Compile OpenH264 from Source

If the package is not available in your repository, compile it manually:

git clone https://github.com/cisco/openh264.git
cd openh264
make
sudo make install
cd ..

Step 3: Download the FFmpeg Source Code

Clone the official FFmpeg git repository and navigate into the directory:

git clone https://git.ffmpeg.org/ffmpeg.git ffmpeg
cd ffmpeg

Step 4: Configure FFmpeg with OpenH264

Configure the build. You must explicitly enable libopenh264.

./configure --enable-libopenh264 --enable-gpl

Note: If you compiled OpenH264 from source and installed it to a custom directory, you may need to specify the path using the PKG_CONFIG_PATH environment variable before running configure (e.g., export PKG_CONFIG_PATH=/usr/local/lib/pkgconfig).

Step 5: Compile and Install FFmpeg

Compile the source code using multiple CPU cores to speed up the process, then install the compiled binaries:

make -j$(nproc)
sudo make install

Step 6: Verify the Installation

Confirm that FFmpeg has been compiled successfully and that the OpenH264 encoder is available:

ffmpeg -encoders | grep openh264

If successful, the output will list libopenh264 as an available H.264 encoder.