​Advanced Audio Coding (AAC) is the successor format to MP3, and is defined in MPEG-4 part 3 (ISO/IEC 14496-3). It is often used within an MP4 container format; for music the .m4a extension is customarily used. The second-most common use is within MKV (Matroska) files because it has better support for embedded text-based soft subtitles than MP4. The examples in this guide will use the extensions MP4 and M4A.

FFmpeg can support three AAC-LC encoders (aac, libfaac, libfdk_aac) and one HE-AAC(v1/2) encoder (libfdk_aac). The licenses of libfaac and libfdk_aac are not compatible with the GPL, so the GPL does not permit distribution of binaries containing code licensed under these licenses when GPL-licensed code is also included. Therefore these encoders have been designated as "non-free", and you cannot download a pre-built ffmpeg that supports them. This can be resolved by compiling ffmpeg yourself.

See also Encode/HighQualityAudio for general guidelines on FFmpeg audio encoding (which also includes a comparison of which AAC encoder is best quality).

libfdk_aac

The Fraunhofer FDK AAC codec library. This is currently the highest-quality AAC encoder available with ffmpeg. Requires ffmpeg to be configured with --enable-libfdk-aac (and additionally --enable-nonfree if you're also using --enable-gpl). But beware, it defaults to a low-pass filter of around 14kHz (​details). If you want to preserve higher frequencies, use -cutoff 18000. Adjust the number to the upper frequency limit you prefer.

Constant Bit Rate (CBR) mode

These settings target a specific bit rate, with less variation between samples. It gives you greater control over file size, and it is compatible with the HE-AAC profile. As a rule of thumb, for audible transparency, use 64kb/s for each channel (so 128kb/s for stereo, 384 kb/s for 5.1 surround sound). Set the bit rate with the -b:a flag.

Examples

Convert and audio file to AAC in an M4A (MP4) container:

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

Convert 5.1 surround sound audio of a video, leaving the video alone:

ffmpeg -i input.mp4 -c:v copy -c:a libfdk_aac -b:a 384k output.mp4

Convert the video with libx264, with a target of fitting a 90-minute movie on a 700MB(=5734400kb) CD-ROM, mixing the audio down to two channels (Windows users should use NUL rather than /dev/null):

High-Efficiency AAC

This is a pair of AAC profiles tailored for low bit rates (version 1 and version 2). HE-AAC version 1 is suited for bit rates below 64kb/s (for stereo audio) down to about 48 kb/s, while HE-AAC version 2 is suited for bit rates as low as 32 kb/s (again, for stereo).

NOTE: HE-AAC version 2 only handles stereo. If you have mono, or want to down-mix to mono, use HE-AAC version 1.

Unfortunately, many devices that can play AAC-LC (the default profile for libfdk_aac) simply cannot play either version of HE-AAC, so this is not recommended for surround sound audio, which normally needs to be compatible with such hardware players. If you are only going to play it on your computer, or you are sure that your hardware player supports HE-AAC, you can aim for a bit rate of 160kb/s for version 1, or 128kb/s for version 2. As always, experiment to see what works for your ears.

HE-AAC version 1

HE-AAC version 2

Streaming and AAC Player Compatibility

By default when encoding AAC files using libfdk_aac the metadata ('moov' atom) is written after the audio stream ('mdat' atom) at the end of the file.
In order to enable streaming of the encoded file the 'moov' atom has to be moved before the 'mdat' atom. In addition some AAC player implementations have issues decoding such files.

FFmpeg offers the option '-movflags +faststart' covering that functionality which can be used during encoding:

ffmpeg -i input.wav -c:a libfdk_aac -movflags +faststart output.m4a

Existing m4a files can be modified with the "qt-faststart' program which is distributed with FFmpeg in the 'tools' directory

qt-faststart input.m4a output.m4a

Native FFmpeg AAC encoder

The native FFmpeg AAC encoder. This is currently the second highest-quality AAC encoder available in FFmpeg and does not require an external library like the other AAC encoders described here. This is the default AAC encoder.

Example using -b:a

ffmpeg -i input.wav -b:a 160k output.m4a

Note:-strict experimental was previously required for this encoder, but is unneeded since December 2015.

Example using -q:a

ffmpeg -i input.wav -c:a aac -q:a 2 output.m4a

Effective range for -q:a is around 0.1-2. This VBR is experimental and likely to get even worse results than the CBR.

libvo_aacenc

VisualOn AAC encoding library. Support for this library has been removed since FFmpeg 2.9/3.0. Use the native FFmpeg encoder instead: it is found to be better in almost all inputs.

libaacplus

​AAC+ encoding library. Support for this library has been removed since FFmpeg 2.9/3.0. Use the native FFmpeg encoder instead: it is found to be better in almost all inputs.

libfaac

Freeware Advanced Audio Coder. Requires ffmpeg configuration with --enable-libfaac --enable-nonfree. Note that you will not get as good results as with libfdk_aac.

Variable Bit Rate (VBR) Example

ffmpeg -i input.wav -c:a libfaac -q:a 100 output.m4a

Range for -q:a is 10-500 and is similar to using the -q option in standalone faac. 100 is a good value to try.

FAQ

Which encoder should I use? What provides the best quality?

Should I use AAC-LC or HE-AAC?

If you require a low audio bitrate, such as ≤ 32kbs/channel, then HE-AAC would be worth considering if your player or device can support HE-AAC decoding. Anything higher may benefit more from AAC-LC due to less processing. If in doubt use AAC-LC. All players supporting HE-AAC also support AAC-LC.