How to Compile FFmpeg with libxml2 for DASH

This guide provides a straightforward, step-by-step walkthrough on how to compile FFmpeg from source with libxml2 enabled. Enabling libxml2 is required for FFmpeg to parse and process XML-based Dynamic Adaptive Streaming over HTTP (DASH) manifests (.mpd files) during media playback, streaming, or transcoding.

Step 1: Install Dependencies and libxml2

Before compiling FFmpeg, you must install the necessary build tools and the development headers for libxml2.

For Ubuntu/Debian systems, run:

sudo apt update
sudo apt install build-essential yasm pkg-config libxml2-dev zlib1g-dev

For CentOS/RHEL/Fedora systems, run:

sudo dnf groupinstall "Development Tools"
sudo dnf install yasm pkgconfig libxml2-devel zlib-devel

For macOS (using Homebrew), run:

brew install xcode-select --install
brew install yasm pkg-config libxml2

Step 2: Download the FFmpeg Source Code

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

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

Alternatively, you can download a specific stable release from the official FFmpeg website and extract it.

Step 3: Configure the Build with libxml2

Run the configure script with the --enable-libxml2 flag. You may also want to include --disable-shared and --enable-static to build a standalone binary, or add other codecs as needed.

./configure --enable-libxml2 --enable-gpl --enable-nonfree

If you are on macOS and installed libxml2 via Homebrew, you may need to point the compiler to the correct path using pkg-config. Run this command before configuring:

export PKG_CONFIG_PATH="/usr/local/opt/libxml2/lib/pkgconfig:$PKG_CONFIG_PATH"

Verify the configuration output. Scroll up or check the ffbuild/config.log file to ensure that libxml2 was successfully detected.

Step 4: Compile and Install FFmpeg

Compile the binary using multiple CPU cores to speed up the process. Replace $(nproc) with the number of available cores (or $(sysctl -n hw.ncpu) on macOS):

make -j$(nproc)

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

sudo make install

Step 5: Verify the Installation

To verify that FFmpeg was compiled successfully with libxml2 support, check the version and configuration flags of the installed binary:

ffmpeg -version

Look for --enable-libxml2 in the configuration block of the output. If it is present, FFmpeg is now ready to parse and process DASH manifests.