Compile FFmpeg with fdk-aac on Windows

This guide provides a step-by-step walkthrough for compiling a custom FFmpeg binary with the high-quality Fraunhofer FDK AAC library (libfdk-aac) on Windows. Due to licensing conflicts between the GPL and the non-free FDK AAC license, pre-compiled public binaries containing both cannot be legally distributed. By using the MSYS2 build environment, you can compile and link these components directly on your machine.

Step 1: Install MSYS2

  1. Download the MSYS2 installer from the official site and install it on your system (recommended path: C:\msys2).

  2. Once installed, open the MSYS2 MinGW 64-bit terminal (do not use the standard MSYS terminal).

  3. Update the package database and core packages:

    pacman -Syu

    If prompted to close the terminal, close it, reopen MSYS2 MinGW 64-bit, and run the command again until everything is up to date.

Step 2: Install Build Dependencies

Run the following command in the MSYS2 MinGW 64-bit terminal to install the necessary compilers, build tools, and utilities:

pacman -S --needed base-devel mingw-w64-x86_64-toolchain mingw-w64-x86_64-cmake mingw-w64-x86_64-nasm git

Press Enter to select all default packages when prompted.

Step 3: Clone and Compile fdk-aac

  1. Clone the fdk-aac source code:

    git clone https://github.com/mstorsjo/fdk-aac.git
    cd fdk-aac
  2. Configure and install the library as a static build:

    autoreconf -fiv
    ./configure --prefix=/mingw64 --disable-shared --enable-static
    make -j$(nproc)
    make install
    cd ..

Step 4: Clone and Configure FFmpeg

  1. Clone the latest FFmpeg source repository:

    git clone https://git.ffmpeg.org/ffmpeg.git ffmpeg
    cd ffmpeg
  2. Configure FFmpeg with --enable-libfdk-aac and the mandatory --enable-nonfree flag:

    ./configure \
      --prefix=/mingw64 \
      --enable-gpl \
      --enable-nonfree \
      --enable-libfdk-aac \
      --disable-shared \
      --enable-static \
      --pkg-config-flags="--static"

Step 5: Compile FFmpeg

Compile the binary using all available CPU cores:

make -j$(nproc)
make install

The compilation process can take several minutes depending on your system's hardware.

Step 6: Verify the Installation

  1. Check if the newly built ffmpeg.exe is working:

    ffmpeg -version

    The output should show --enable-libfdk-aac and --enable-nonfree in the configuration banner.

  2. Verify that the libfdk_aac encoder is available:

    ffmpeg -encoders | grep libfdk_aac

The compiled ffmpeg.exe file will be located in your MSYS2 directory under C:\msys2\mingw64\bin\ffmpeg.exe. You can copy this executable to any directory on Windows or add C:\msys2\mingw64\bin to your Windows system PATH environment variable.