Changes between Initial Version and Version 1 of Encode/AAC


Ignore:
Timestamp:
Jan 11, 2013, 3:21:23 AM (6 years ago)
Author:
evilsoup
Comment:

This seemed like the biggest omission on the wiki so far...

Legend:

Unmodified
Added
Removed
Modified
  • Encode/AAC

    v1 v1  
     1= FFmpeg and AAC Encoding Guide =
     2
     3[[PageOutline(2-3, Contents)]]
     4
     5[[http://en.wikipedia.org/wiki/Advanced_Audio_Coding|AAC, Advanced Audio Coding]], is the successor format to MP3, and is defined in MPEG-4 part 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 matroska MKV files (used 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.
     6
     7== libfdk_aac ==#fdk_aac
     8
     9This is currently the highest-quality AAC encoder available with ffmpeg. Requires ffmpeg to be configured with `--enable-libfdk_aac`.
     10
     11`-afterburner 1` enables 'high-quality' mode. It doesn't add any noticeable length to the encoding time, or increase the filesize; so unless you have a specific reason not to, you should use it.
     12
     13=== Variable Bit Rate (VBR) mode ===#fdk_vbr
     14
     15These settings target a ''quality'', rather than a specific ''bit rate''. 1 is lowest quality (though still pretty good) and 5 is highest quality. For some people with some files, even a VBR of 1 is indistinguishable from CD-quality audio; test it out and use the lowest setting that works for you. This mode is not compatible with [[#fdk_he|AAC-HE]], but for AAC-LC (the default for ffmpeg, and most compatible [[http://en.wikipedia.org/wiki/Advanced_Audio_Coding#Modular_encoding|AAC profile]]) it should probably be preferred, since it allows the encoder greater flexibility to distribute bits as it sees fit: high-tempo, large dynamic range audio (like dubstep or rock music) requires more bits to encode then low-tempo, low dynamic range audio (like whalesong, or a recorded lecture - though there are special speech codecs that you should consider for the latter). Set the VBR level with the `-vbr:a` flag.
     16
     17According to [[http://www.hydrogenaudio.org/forums/index.php?showtopic=95989|this hydrogenaudio post]], the VBR modes (on average, over a number of files) give the following bit rates per channel (so for stereo, double the bit rate; for 5.1 surround sound, multiply it by six):
     18
     19||VBR||kb/s/channel||
     20||1||32||
     21||2||40||
     22||3||48-56||
     23||4||64||
     24||5||80-96||
     25
     26==== Examples ====
     27
     28Convert an audio file to AAC in an M4A (MP4) container:
     29
     30{{{
     31ffmpeg -i input.wav -c:a libfdk_aac -vbr:a 3 -afterburner:a 1 output.m4a
     32}}}
     33
     34Convert the audio only of a video:
     35
     36{{{
     37ffmpeg -i input.mp4 -c:v copy -c:a libfdk_aac -vbr:a 3 -afterburner:a 1 output.mp4
     38}}}
     39
     40Convert the video with [[x264EncodingGuide#crf|libx264]], and mix down audio to two channels:
     41
     42{{{
     43ffmpeg -i input.mp4 -c:v libx264 -crf:v 22 -preset:v veryfast \
     44-ac 2 -c:a libfdk_aac -vbr:a 3 -afterburner:a 1 output.mp4
     45}}}
     46
     47=== Constant Bit Rate (CBR) mode ===#fdk_cbr
     48
     49These settings target a specific bit rate, with less variation between samples. It will get you slightly lower quality for the bit rate it gives than the VBR mode would; but it gives you greater control over filesize, 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.
     50
     51==== Examples ====
     52
     53Convert and audio file to AAC in an M4A (MP4) container:
     54
     55{{{
     56ffmpeg -i input.wav -c:a libfdk_aac -b:a 128k -afterburner:a 1 output.m4a
     57}}}
     58
     59Convert 5.1 surround sound audio of a video, leaving the video alone:
     60
     61{{{
     62ffmpeg -i input.mp4 -c:v copy -c:a libfdk_aac -b:a 384k -afterburner:a 1 output.mp4
     63}}}
     64
     65Convert the video with [[x264EncodingGuide#twopass|libx264]], with a target of fitting a 90-minute movie on a 700MB(=5734400kb) CD-ROM, mixing the audio down to two channels:
     66
     67{{{
     68ffmpeg -i input.mp4 -c:v libx264 -b:v 933k -preset:v veryfast -pass 1 -an /dev/null \
     69ffmpeg -i input.mp4 -c:v libx264 -b:v 933k -preset:v veryfast -pass 2 -ac 2 -c:a libfdk_aac -b:a 128k -afterburner:a 1 output.mp4
     70}}}
     71
     72=== High-Efficiency AAC ===#fdk_he
     73
     74This is a pair of AAC profiles tailored for low bit rates (version 1 and version 2). AAC-HE version 1 is suited for bit rates below 64kb/s (for stereo audio) down to about 48 kb/s, while AAC-HE version 2 is suited for bit rates as low as 32 kb/s (again, for stereo).
     75
     76Unfortunately, many devices that can play AAC-LC (the default profile for fdk_aac) simply cannot play either version of AAC-HE, 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 AAC-HE, 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.
     77
     78The following examples are taken from [[http://ubuntuforums.org/showpost.php?p=12421935&postcount=34|this ubuntuforum post]].
     79
     80==== AAC-HE version 1 ====
     81
     82{{{
     83ffmpeg -i input.wav -c:a libfdk_aac -profile:a aac_he -b:a 64k -afterburner:a 1 output.m4a
     84}}}
     85
     86==== AAC-HE version 2 ====
     87
     88{{{
     89ffmpeg -i input.wav -c:a libfdk_aac -profile:a aac_he_v2 -b:a 32k -afterburner:a 1 output.m4a
     90}}}
     91
     92== ffmpeg AAC ==
     93
     94If your version of ffmpeg isn't built with `--enable-libfdk_aac`, you can use ffmpeg's internal AAC encoder. Note that you will not get as good results as with fdk_aac.
     95
     96==== Example ====
     97
     98{{{
     99ffmpeg -i input.wav -strict experimental -c:a aac -b:a 128k output.m4a
     100}}}