Compile FFmpeg with Libfribidi and Libharfbuzz

This guide provides a straightforward, step-by-step walkthrough on how to compile FFmpeg from source with libfribidi and libharfbuzz enabled. Integrating these libraries allows FFmpeg’s drawtext filter and subtitle renderers to handle advanced text shaping, complex scripts (like Arabic, Indic, or Thai), and correct bidirectional (right-to-left) text processing.

Step 1: Install Required Dependencies

Before compiling FFmpeg, you must install the development headers for libfribidi, libharfbuzz, and freetype (which works alongside them for font rendering).

On Ubuntu/Debian-based systems, run:

sudo apt update
sudo apt install -y build-essential yasm nasm pkg-config \
libfreetype6-dev libfribidi-dev libharfbuzz-dev libfontconfig1-dev

On CentOS/RHEL/Fedora-based systems, run:

sudo dnf groupinstall "Development Tools"
sudo dnf install -y yasm nasm pkgconfig \
freetype-devel fribidi-devel harfbuzz-devel fontconfig-devel

Step 2: Clone the FFmpeg Source Code

Clone the official FFmpeg git repository to get the latest stable source code:

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

Step 3: Configure the Build

Configure the compilation settings. To use libfribidi and libharfbuzz, you must explicitly enable them using the --enable-libfribidi and --enable-libharfbuzz flags. You also need --enable-libfreetype because text rendering relies on the FreeType engine.

Run the ./configure script:

./configure \
  --enable-gpl \
  --enable-nonfree \
  --enable-libfreetype \
  --enable-libfribidi \
  --enable-libharfbuzz \
  --enable-libfontconfig

Note: If the configuration fails, check the ffbuild/config.log file to identify missing libraries or incorrect paths.

Step 4: Compile and Install FFmpeg

Once configuration succeeds, compile the binaries using all available CPU cores to speed up the process, then install the compiled files to your system.

make -j$(nproc)
sudo make install

Step 5: Verify the Installation

To confirm that your newly compiled FFmpeg binary supports advanced text rendering, verify the configuration options in the version output:

ffmpeg -version

Look for --enable-libfribidi and --enable-libharfbuzz in the printed configuration string. If they are listed, your FFmpeg build is ready to render complex text and right-to-left languages.