How to Compile FFmpeg with zscale

Compiling FFmpeg with the zscale filter allows you to utilize the high-quality zimg library for advanced image scaling, colorspace conversion, and HDR-to-SDR tone mapping. This step-by-step guide will walk you through installing the necessary dependencies, compiling the zimg library from source, and configuring FFmpeg with the --enable-libzimg flag to activate the zscale filter.

Step 1: Install Build Dependencies

Before compiling, you need to install the essential build tools and libraries. Run the following command on Debian/Ubuntu-based systems:

sudo apt update
sudo apt install -y build-essential git autoconf automake libtool pkg-config

Step 2: Compile and Install the zimg Library

The zscale filter in FFmpeg is a wrapper for the zimg library. You must compile and install zimg from its official source repository.

  1. Clone the zimg repository:

    git clone --recursive https://github.com/sekrit-twc/zimg.git
    cd zimg
  2. Generate the configuration scripts:

    ./autogen.sh
  3. Configure, build, and install the library:

    ./configure
    make -j$(nproc)
    sudo make install
  4. Update the shared library cache so your system recognizes the newly installed library:

    sudo ldconfig

Step 3: Download and Compile FFmpeg

With zimg installed, you can now configure and compile FFmpeg.

  1. Clone the FFmpeg source code:

    git clone https://git.ffmpeg.org/ffmpeg.git ffmpeg
    cd ffmpeg
  2. Run the configure script. You must include the --enable-libzimg flag. It is also recommended to enable GPL support via --enable-gpl:

    ./configure --enable-gpl --enable-libzimg
  3. Compile FFmpeg using all available CPU cores:

    make -j$(nproc)
  4. Install the compiled FFmpeg binary to your system:

    sudo make install

Step 4: Verify the Installation

To ensure that FFmpeg was compiled correctly and that the zscale filter is available, run the following command:

ffmpeg -filters | grep zscale

If the compilation was successful, the output will display the zscale filter details:

 ... zscale           V->V       Apply resize, colorspace, and depth conversion.