Compile FFmpeg with libfontconfig Support

Compiling FFmpeg with libfontconfig allows you to utilize system fonts and resolve font names dynamically when rendering text onto videos using filters like drawtext. This guide provides a straightforward, step-by-step walkthrough on how to install the necessary dependencies, configure the FFmpeg build options with fontconfig enabled, and compile the final binary on your system.

Step 1: Install System Dependencies

Before compiling, you must install the build tools and development libraries for both fontconfig and freetype.

On Ubuntu/Debian systems, run:

sudo apt update
sudo apt install build-essential yasm pkg-config libfontconfig1-dev libfreetype6-dev

On CentOS/RHEL/Fedora systems, run:

sudo dnf groupinstall "Development Tools"
sudo dnf install yasm pkgconfig fontconfig-devel freetype-devel

Step 2: Download FFmpeg Source Code

Clone the official FFmpeg Git repository to get the latest source code:

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

Step 3: Configure the Build

To compile FFmpeg with libfontconfig, you must explicitly enable it during the configuration step. Because libfontconfig relies on FreeType, you must enable libfreetype as well.

Run the configure script with the following flags:

./configure --enable-gpl --enable-libfreetype --enable-libfontconfig

If the configuration completes successfully, it will generate a Makefile. If it fails, check the ffbuild/config.log file to identify any missing development libraries.

Step 4: Compile and Install FFmpeg

Compile the source code. You can use the -j flag to utilize multiple CPU cores and speed up the compilation process:

make -j$(nproc)

Once the compilation is complete, install the FFmpeg binaries to your system:

sudo make install

Step 5: Verify the Installation

To confirm that FFmpeg was compiled correctly with libfontconfig support, check the version and configuration flags of your newly installed binary:

ffmpeg -version

Look for --enable-libfontconfig in the configuration block of the output. If it is present, FFmpeg is ready to use system fonts via fontconfig.