Compile FFmpeg with AMD AMF Support on Windows

This guide provides a straightforward, step-by-step walkthrough for compiling FFmpeg with AMD Advanced Media Framework (AMF) support on Windows. By enabling AMF, you can utilize your AMD Radeon graphics card for hardware-accelerated video encoding and decoding, resulting in faster processing times and lower CPU usage.

Prerequisites

To compile FFmpeg on Windows, you will use the MSYS2 environment, which provides a Unix-like build interface and the necessary compilers.

  1. Install MSYS2: Download and run the installer from the official MSYS2 website.

  2. Install Required Packages: Open the MSYS2 MinGW 64-bit terminal (do not use the MSYS terminal) and run the following command to update the package database and install the compiler toolchain, Git, and build tools:

    pacman -Syu
    pacman -S mingw-w64-x86_64-toolchain git make pkg-config diffutils yasm nasm

Step 1: Install AMD AMF Headers

FFmpeg requires the AMF SDK headers to compile with AMF support. Because AMF is a header-only library, you only need to copy the official header files to your MSYS2 include directory.

  1. In the MinGW 64 terminal, clone the AMD AMF repository:

    git clone https://github.com/GPUOpen-LibrariesAndSDKs/AMF.git
  2. Create the target AMF directory in your MSYS2 include folder:

    mkdir -p /mingw64/include/AMF
  3. Copy the header folders (core and components) into the new directory:

    cp -r AMF/amf/public/include/* /mingw64/include/AMF/

Step 2: Clone the FFmpeg Source Code

Clone the official FFmpeg git repository and navigate into the directory:

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

Step 3: Configure the Build

Configure the FFmpeg build environment. The crucial flag here is --enable-amf. You must also include --enable-gpl and --enable-nonfree because AMF compilation utilizes non-free components.

Run the configure script with the following parameters:

./configure \
  --arch=x86_64 \
  --target-os=mingw32 \
  --enable-gpl \
  --enable-nonfree \
  --enable-amf \
  --extra-cflags="-I/mingw64/include" \
  --extra-ldflags="-L/mingw64/lib"

Verify the output of the configuration script. Ensure that amf is listed under the enabled hardware accelerators / external libraries section.

Step 4: Compile and Install

Once the configuration completes successfully, compile the source code. You can speed up the build process by using multiple CPU threads with the -j flag (replace 8 with the number of CPU cores you wish to allocate):

make -j8

After the compilation finishes, install the compiled binaries to your MSYS2 environment:

make install

Step 5: Verify the Installation

To ensure that FFmpeg was built correctly and supports AMD AMF, run the following command:

ffmpeg -encoders | grep amf

You should see a list of AMF encoders, such as h264_amf and hevc_amf. You can now use these encoders in your FFmpeg commands to utilize AMD hardware acceleration.