Encoding AAC
Libav provides an experimental native encoder for aac and wraps higher quality third party libraries.
Available AAC encoders
Encoder name |
Title |
AAC Profiles |
Max Channels |
Modes |
Notes |
libfdk_aac |
LC, HE, HEv2, LD, ELD |
8 (7.1) |
CBR, VBR |
Non-free. Highest quality. A bit slower than others. |
|
aac |
Libav native (built-in) |
LC |
? |
? |
Experimental, but developing. |
libfaac |
Freware Advanced Audio Coder |
LC |
6 (5.1) |
VBR, ABR |
Very old. |
libvo_aacenc |
LC |
2 |
CBR |
Very poor. |
The Android Open Source Project included a simple AAC encoding library from VisualOn in early releases. In Android 4.1, the VisualOn library was replaced by a much more advanced AAC codec library from Fraunhofer, called the FDK ACC library for Android.
Libav native
The native encoder is experimental and known to have serious flaws, help on improving it is welcome. Do not use it in production
Fraunhofer FDK AAC
The Fraunhofer FDK AAC codec library replaced the VisualOn library in Android 4.1. It provides support for up to 8 channels (7.1 surround), multiple AAC advanced profiles and a number of fine tuning options.
The Fraunhofer FDK AAC page at Hydrogen Audio has more detailed information, not specific to Libav.
Building Fraunhofer AAC support
fdk-aac custom license is non-free, Libav compiled with it results being not redistributable.
Assuming your systems has libfdk_aac installed all you need to do is
./configure --enable-libfdk-aac --enable-nonfree
Once it is built and installed you can check for its availability
avconv -codecs | grep aac DEA.L. aac AAC (Advanced Audio Coding) (decoders: aac libfdk_aac ) (encoders: aac libfdk_aac )
Invocation
avconv -i source -vn -c:a libfdk_aac out.m4a
If the source material contains cover art, avconv will try to use it as a video stream and fail. Use -vn to ignore it. Libav is not able to embed cover art in m4a the same way it can with mp3.
Some Libav provides multiple providers for aac encoding always -c:v libfdk_aac to be sure.
Profiles
Profiles enforce a standard, ensuring compatibility with specific targets by restricting the encoding features used. By default AAC-LC is used since it is the most compatible.
Low Complexity, the default -profile:a aac_lc
High Efficiency, geared for bitrates in the 48-64kbps range -profile:a aac_he
High Efficiency v2, geared for bitrates down to 32kbps -profile:a aac_he_v2
Low Delay, geared for realtime usages (20ms algorithmic delay) -profile:a aac_ld
Enhanced Low Delay, as above, with lower delay even -profile:a aac_eld
High Efficiency profiles are suggested to encode multichannel audio.
avconv -i 5.1source -c:a libfdk_aac -profile:a aac_he_v2 -c:v h264 -preset medium -crf 25 out.mkv
Rate Control
Constant Bitrate
Supported by every profile, constant bitrate maps to the avconv option '-b:a'.
Depending on the profile, the rule of thumb is allotting at least 32kbps per channel in Low Complexity and Low Delay, 24kbps in High Efficiency and 16kbps for High Efficiency v2.
For normal stereo at least 80kbps and for 5.1 at least 256kbps are suggested.
avconv -i source -c:a libfdk_aac -b:a 80k out.mka
Variable Bitrate
Variable bitrate mode targets a quality level instead of a bitrate. The quality value is specified by the -vbr option. Values are 1-5.
VBR modes (-vbr) |
Maximum kbps/channel |
Profiles (-profile:a) |
1 |
20-32 |
aac_lc, aac_he, aac_he_v2 |
2 |
32-40 |
aac_lc, aac_he, aac_he_v2 |
3 |
48-56 |
aac_lc, aac_he, aac_he_v2 |
4 |
64-72 |
aac_lc |
5 |
96-112 |
aac_lc |
(See FDK:Bitrate Modes for detailed VBR bit rate calculations)
avconv -i source -c:a libfdk_aac -vbr 3 out.m4a
A deficiency in libfdk_aac 0.1.3 and earlier may cause a crash with high sample rates and VBR mode 5. Adding -ar 48000 to the avconv command line will sidestep this problem by resampling the audio before it gets to the FDK encoder. (See FDK:Issues for details)
Signaling
Signaling options have a severe impact on decoders compatibility. By default it is explicit_hierarchical when a global header is requested, implicit when the global header is disabled.
In order to be compatible with Flash player when using High Efficiency profiles the signalling has to be set to implicit.
avconv -i source -c:a libfdk_aac -profile aac_he_v2 -signaling implicit -f flv rtmp://server/app/room
latm encapsulation
The library provides -latm to encapsulate the data so it can be muxed correctly in TS streams. Use -header_period to set the number of frames the configuration extradata has to be emitted again.
avconv -i source -c:a libfdk_aac -latm 1 -header_period 50 out.ts
Low-pass filter
The encoder applies a low-pass filter (frequency cutoff) depending on the profile and the sampling rate requested. If the default cutoff cancels high pitch sounds that should be preserved -cutoff overrides it. Values up to 20kHz may be used. (See FDK:Bandwidth for details on default cutoff calculations)
avconv -i source -c:a libfdk_aac -ar 48k -cutoff 18k out.mka
VisualOn AAC
Spun off of the Google Android codebase, this encoder is quite basic but quite stable.
Building VisualOn AAC support
vo-aacenc is Apache-2.0 licensed, Libav compiled with it results being LGPL3 in order to be compatible.
Assuming your systems has vo-aacenc installed all you need to do is
./configure --enable-libvo-aacenc --enable-version3
Once it is built and installed you can check for its availability
avconv -codecs | grep aac DEA.L. aac AAC (Advanced Audio Coding) (decoders: aac libfdk_aac ) (encoders: aac libfdk_aac libvo_aacenc )
Invocation
avconv -i source -c:a libvo_aacenc -vn out.mp4
Some Libav provides multiple providers for aac encoding always -c:v libvo_aacenc to be sure.
Suggested settings
The VisualOn AAC encoder is rather spartan, supports up to 2 channels and the only setting supported is bitrate. It is suggested mainly because it is free-software compatible and redistributable. To achieve best results use the Fraunhofer one.
avconv -i source -c:a libvo_aacenc -b 64k out.m4a
Additional resources
Detailed Fraunhofer FDK AAC information at Hydrogen Audio Knowledgebase

