How to Use libfdk_aac with FFmpeg

This article provides a straightforward guide on how to enable and use the high-quality Fraunhofer FDK AAC library (libfdk_aac) within FFmpeg. Because of licensing restrictions, using this library requires compiling FFmpeg from source with specific configuration flags. Below, you will find the steps to compile FFmpeg with FDK AAC support and the exact command-line syntax needed to encode your audio files.

Why libfdk_aac Requires Compilation

The FDK AAC library is considered the highest-quality AAC encoder available for FFmpeg. However, its license is incompatible with the GNU General Public License (GPL). Consequently, pre-built binary distributions of FFmpeg generally do not include libfdk_aac. To use it, you must compile FFmpeg yourself.

Step 1: Compile FFmpeg with FDK AAC

To compile FFmpeg with FDK AAC support, you must first install the libfdk-aac development headers on your system using your package manager (for example, sudo apt install libfdk-aac-dev on Debian/Ubuntu).

When configuring your FFmpeg build, you must explicitly include the --enable-libfdk-aac and --enable-nonfree flags. A standard configuration command looks like this:

./configure --enable-gpl --enable-libfdk-aac --enable-nonfree
make
sudo make install

The --enable-nonfree flag is required because of the FDK AAC license, and it permits the creation of a binary that can be used for personal or internal purposes.

Step 2: Basic Audio Encoding (CBR)

Once you have a compiled version of FFmpeg with libfdk_aac enabled, you can use it by specifying -c:a libfdk_aac in your command line. For Constant Bit Rate (CBR) encoding, use the -b:a flag to set the desired bitrate:

ffmpeg -i input.wav -c:a libfdk_aac -b:a 128k output.m4a

Step 3: Variable Bit Rate Encoding (VBR)

For better quality-to-space ratios, you can use Variable Bit Rate (VBR) mode. The libfdk_aac encoder uses the -vbr flag with a scale from 1 to 5, where 5 is the highest quality:

To encode a stereo file with high-quality VBR (Level 5):

ffmpeg -i input.wav -c:a libfdk_aac -vbr 5 output.m4a

Step 4: High-Efficiency AAC (HE-AAC)

The FDK library also supports High-Efficiency AAC (HE-AAC), which is ideal for very low bitrates (below 48 kbps). You can enable HE-AAC by specifying the profile:

ffmpeg -i input.wav -c:a libfdk_aac -profile:a aac_he -b:a 32k output.m4a