FFmpeg - Encode AAC
AAC (Advanced Audio Coding) is a modern, efficient audio codec widely used for streaming, broadcasting, and high‑quality distribution. FFmpeg supports several AAC encoders, but libfdk_aac remains one of the highest‑quality options when available.
This article provides a practical, reliable command for encoding AAC audio with predictable output quality and file size, and explains the reasoning behind the settings.
Overview
libfdk_aac is an external library that offers excellent audio quality, especially at low and medium bitrates. When you need consistent bitrate, stereo output, or compatibility with HE‑AAC modes, the -b:a (bitrate) approach is usually the most predictable.
The following command encodes an input file to AAC using libfdk_aac, targeting a specific bitrate:
ffmpeg -i <input.file> -c:a libfdk_aac -ac 2 -b:a 128k <output.file>
Explanation of Parameters
-c:a libfdk_aac
Selects the excellent-quality Fraunhofer FDK AAC encoder.
-ac 2
Forces 2 audio channels (stereo).
-b:a 128k
Sets the audio bitrate.
Choosing the Right Bitrate
When targeting audible transparency, a simple rule of thumb is:
- 64 kbit/s per channel
- Stereo: 128 kbit/s
- 5.1 surround: 384 kbit/s
HE-AAC Compatibility
libfdk_aac can produce AAC-LC, HE-AAC, and HE-AAC v2. Bitrate-based encoding (-b:a) ensures profile compatibility.
Common Variations
High-quality stereo (192 kb/s)
ffmpeg -i input.wav -c:a libfdk_aac -b:a 192k output.m4a
Low-bitrate streaming (64 kb/s HE-AAC)
ffmpeg -i input.wav -c:a libfdk_aac -b:a 64k output.m4a
Surround sound (5.1 – 384 kb/s)
ffmpeg -i input.wav -c:a libfdk_aac -ac 6 -b:a 384k output.m4a