How to Compile FFmpeg with FriBidi and HarfBuzz
This guide provides a step-by-step walkthrough for compiling FFmpeg
from source with libfribidi and libharfbuzz
support on Linux-based systems. Enabling these libraries allows FFmpeg's
drawtext filter to properly shape complex scripts, handle
OpenType features, and correctly order bidirectional text, such as
Arabic or Hebrew, during video processing.
1. Install Build Tools and Dependencies
Update your package manager and install the necessary compilers, build tools, and the required development libraries. On Debian- or Ubuntu-based distributions, run:
sudo apt update
sudo apt install -y \
build-essential \
yasm \
nasm \
cmake \
git \
pkg-config \
libfreetype6-dev \
libfribidi-dev \
libharfbuzz-dev \
libfontconfig1-devlibfreetype6-dev: Handles font rendering.libharfbuzz-dev: Handles text shaping and OpenType font features.libfribidi-dev: Handles bidirectional (BiDi) text algorithms.libfontconfig1-dev: Allows font discovery and management.
2. Clone the FFmpeg Source Code
Clone the official FFmpeg source repository into your preferred working directory:
git clone https://git.ffmpeg.org/ffmpeg.git ffmpeg_sources
cd ffmpeg_sourcesIf you prefer a stable release over the development branch, check out a specific release tag:
git checkout release/6.13. Configure the Build
Run the ./configure script with the flags required to
enable text rendering, shaping, and bidirectional layout.
./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-nonfree \
--enable-libfreetype \
--enable-libharfbuzz \
--enable-libfribidi \
--enable-libfontconfigMake sure the configuration summary confirms that
freetype, harfbuzz, and fribidi
are enabled. If the script fails, inspect the
ffbuild/config.log file to identify missing dependencies or
pkg-config issues.
4. Compile and Install
Compile the source code using multiple cores, then install the binaries:
make -j$(nproc)
make installIf you configured a system-wide destination rather than a local
prefix, you may need to run sudo make install.
5. Verify the Installation
Ensure that the newly built binary is active and compiled with the target libraries:
$HOME/bin/ffmpeg -buildconfLook for --enable-libharfbuzz and
--enable-libfribidi in the output configuration list.
You can now use complex script shaping and bidirectional text using
the drawtext filter:
ffmpeg -f lavfi -i color=c=black:s=1280x720:d=5 \
-vf "drawtext=fontfile=/path/to/font.ttf:text='مرحبا بالعالم':fontcolor=white:fontsize=48:x=(w-text_w)/2:y=(h-text_h)/2" \
-c:a copy output.mp4