Changes between Version 47 and Version 48 of Encode/AAC


Ignore:
Timestamp:
Feb 18, 2016, 10:05:23 AM (4 years ago)
Author:
llogan
Comment:

nits and cleanups

Legend:

Unmodified
Added
Removed
Modified
  • Encode/AAC

    v47 v48  
    1 = FFmpeg and AAC Encoding Guide =
    2 
    3 [[PageOutline(2-3, Contents)]]
     1[[PageOutline(1, Contents)]]
    42
    53[[http://en.wikipedia.org/wiki/Advanced_Audio_Coding|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.
     
    119----
    1210
    13 == libfdk_aac ==#fdk_aac
     11= libfdk_aac =#fdk_aac
    1412
    1513The 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 ([[http://wiki.hydrogenaud.io/index.php?title=Fraunhofer_FDK_AAC#Bandwidth|details]]). If you want to preserve higher frequencies, use `-cutoff 18000`.  Adjust the number to the upper frequency limit you prefer.
    1614
    17 Detailed information about the FDK AAC library (not FFmpeg specific) can be found at the [[http://wiki.hydrogenaud.io/index.php?title=Fraunhofer_FDK_AAC|Fraunhofer FDK AAC]] page in the HydrogenAudio Knowledgebase.
    18 
    19 === Constant Bit Rate (CBR) mode ===#fdk_cbr
    20 
    21 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.
    22 
    23 ==== Examples ====
     15Detailed information about the FDK AAC library (not FFmpeg specific) can be found at [http://wiki.hydrogenaud.io/index.php?title=Fraunhofer_FDK_AAC HydrogenAudio Knowledgebase: Fraunhofer FDK AAC].
     16
     17== Constant Bit Rate (CBR) mode ==#fdk_cbr
     18
     19These 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` option.
     20
     21=== Examples ===
    2422
    2523Convert and audio file to AAC in an M4A (MP4) container:
     
    4341}}}
    4442
    45 === Variable Bit Rate (VBR) mode ===#fdk_vbr
     43== Variable Bit Rate (VBR) mode ==#fdk_vbr
    4644
    4745Target a ''quality'', rather than a specific ''bit rate''. 1 is lowest quality and 5 is highest quality. Set the VBR level with the `-vbr` flag.
    4846
     47{{{
     48#!div style="border: 1pt dotted; margin: 1em; background-color: #fffff9;"
    4949'''Note:''' A bug exists in libfdk-aac 0.1.3 and earlier that will cause a crash when using high sample rates, such as 96kHz, with VBR mode 5. ([[http://wiki.hydrogenaud.io/index.php?title=Fraunhofer_FDK_AAC#Issues|details]]).
    50 
    51 VBR modes gives '''roughly''' the following bit rates per channel ([[http://wiki.hydrogenaud.io/index.php?title=Fraunhofer_FDK_AAC#Bitrate_Modes|details]]):
     50}}}
     51
     52VBR modes gives roughly the following bit rates per channel ([[http://wiki.hydrogenaud.io/index.php?title=Fraunhofer_FDK_AAC#Bitrate_Modes|details]]):
    5253
    5354||VBR||kbps/channel||AOTs||
     
    6061HE bit rates will be much lower.
    6162
    62 ==== Examples ====
     63=== Examples ===
    6364
    6465Convert an audio file to AAC in an M4A (MP4) container:
     
    7778
    7879{{{
    79 ffmpeg -i input.mp4 -c:v libx264 -crf:v 22 -preset:v veryfast \
     80ffmpeg -i input.mp4 -c:v libx264 -crf 22 -preset:v veryfast \
    8081-ac 2 -c:a libfdk_aac -vbr 3 output.mp4
    8182}}}
    8283
    83 === High-Efficiency AAC ===#fdk_he
     84== High-Efficiency AAC ==#fdk_he
    8485
    8586This 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).
    8687
    87 NOTE: HE-AAC version 2 only handles stereo. If you have mono, or want to down-mix to mono, use HE-AAC version 1.
     88{{{
     89#!div style="border: 1pt dotted; margin: 1em; background-color: #fffff9;"
     90'''Note:''' HE-AAC version 2 only handles stereo. If you have mono, or want to down-mix to mono, use HE-AAC version 1.
     91}}}
    8892
    8993Unfortunately, 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.
    9094
    9195
    92 ==== HE-AAC version 1 ====
     96=== HE-AAC version 1 ===
    9397
    9498{{{
     
    96100}}}
    97101
    98 ==== HE-AAC version 2 ====
     102=== HE-AAC version 2 ===
    99103
    100104{{{
     
    102106}}}
    103107
    104 === Streaming and AAC Player Compatibility ===#fdk_stream
    105 
    106 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.
    107 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.
    108 
    109 FFmpeg offers the option '-movflags +faststart' covering that functionality which can be used during encoding:
     108----
     109
     110= Native FFmpeg AAC encoder =
     111
     112The 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.
     113
     114{{{
     115#!div style="border: 1pt dotted; margin: 1em; background-color: #fffff9;"
     116'''Note:''' `-strict experimental` (or `-strict -2`) was previously required for this encoder, but it is [http://git.videolan.org/?p=ffmpeg.git;a=commit;h=d9791a8656b5580756d5b7ecc315057e8cd4255e no longer experimental] and these options are unnecessary since 5 December 2015.
     117}}}
     118
     119== Example using `-b:a` ==
     120
     121{{{
     122ffmpeg -i input.wav -c:a aac -b:a 160k output.m4a
     123}}}
     124
     125== Example using `-q:a` ==
     126
     127{{{
     128ffmpeg -i input.wav -c:a aac -q:a 2 output.m4a
     129}}}
     130
     131Effective range for `-q:a` is around 0.1-2. This VBR is experimental and likely to get even worse results than the CBR.
     132
     133----
     134
     135= libfaac =
     136
     137Freeware Advanced Audio Coder. Requires ffmpeg configuration with `--enable-libfaac --enable-nonfree`. Note that you will not get as good results as with `libfdk_aac`.
     138
     139== Variable Bit Rate (VBR) Example ==
     140{{{
     141ffmpeg -i input.wav -c:a libfaac -q:a 100 output.m4a
     142}}}
     143
     144Range for `-q:a` is 10-500 and is similar to using the `-q` option in standalone `faac`. 100 is a good value to try.
     145
     146== Average Bit Rate (ABR) Example ==
     147{{{
     148ffmpeg -i input.wav -c:a libfaac -b:a 192k output.m4a
     149}}}
     150
     151`libfaac` does not support a true Constant Bit Rate (CBR) mode.
     152
     153----
     154
     155= Deprecated/removed encoders =
     156
     157== libvo_aacenc ==
     158
     159!VisualOn AAC encoding library. [http://git.videolan.org/?p=ffmpeg.git;a=commit;h=e07e88cd82f78644ddcb10d7d3e0dd624fffe274 Support for this library has been removed]. Use the native FFmpeg encoder instead: it provides better quality and supports more than 2 channels.
     160
     161----
     162
     163== libaacplus ==
     164
     165[http://tipok.org.ua/node/17 AAC+] encoding library. [http://git.videolan.org/?p=ffmpeg.git;a=commit;h=9ba54c1b82a81581e5283da75c153a76f04324c0 Support for this library has been removed]. Use `libfdk_aac` instead for HE-AAC: it is consistently better in all bitrates.
     166
     167----
     168
     169= Metadata =
     170
     171You can add metadata to any of the examples on this guide:
     172
     173{{{
     174ffmpeg -i input ... -metadata author="FFmpeg Bayou Jug Band" -metadata title="Decode my Heart (Let's Mux)" output.mp4
     175}}}
     176
     177----
     178
     179= Progressive download =
     180
     181By default the MP4 muxer writes the 'moov' atom after the audio stream ('mdat' atom) at the end of the file. This results in the user requiring to download the file completely before playback can occur. Relocating this moov atom to the beginning of the file can facilitate playback before the file is completely downloaded by the client.
     182
     183You can do this with the `-movflags +faststart` option:
    110184
    111185{{{
     
    113187}}}
    114188
    115 Existing m4a files can be modified with the "qt-faststart' program which is distributed with FFmpeg in the 'tools' directory
    116 
    117 {{{
    118 qt-faststart input.m4a output.m4a
    119 }}}
    120 
    121 ----
    122 
    123 == Native FFmpeg AAC encoder ==
    124 
    125 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.
    126 
    127 ==== Example using `-b:a` ====
    128 
    129 {{{
    130 ffmpeg -i input.wav -b:a 160k output.m4a
    131 }}}
    132 
    133   '''Note:''' `-strict experimental` was previously required for this encoder, but is unneeded since December 2015.
    134 
    135 
    136 ==== Example using `-q:a` ====
    137 
    138 {{{
    139 ffmpeg -i input.wav -c:a aac -q:a 2 output.m4a
    140 }}}
    141 
    142 Effective range for `-q:a` is around 0.1-2. This VBR is experimental and likely to get even worse results than the CBR.
    143 
    144 ----
    145 
    146 == libfaac ==
    147 
    148 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`.
    149 
    150 ==== Variable Bit Rate (VBR) Example ====
    151 {{{
    152 ffmpeg -i input.wav -c:a libfaac -q:a 100 output.m4a
    153 }}}
    154 
    155 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.
    156 
    157 ==== Average Bit Rate (ABR) Example ====
    158 {{{
    159 ffmpeg -i input.wav -c:a libfaac -b:a 192k output.m4a
    160 }}}
    161 
    162 `libfaac` does not support a true Constant Bit Rate (CBR) mode.
    163 
    164 ----
    165 
    166 == libvo_aacenc ==
    167 
    168 !VisualOn AAC encoding library. [http://git.videolan.org/?p=ffmpeg.git;a=commit;h=e07e88cd82f78644ddcb10d7d3e0dd624fffe274 Support for this library has been removed]. Use the native FFmpeg encoder instead: it provides better quality and supports more than 2 channels.
    169 
    170 ----
    171 
    172 == libaacplus ==
    173 
    174 [http://tipok.org.ua/node/17 AAC+] encoding library. [http://git.videolan.org/?p=ffmpeg.git;a=commit;h=9ba54c1b82a81581e5283da75c153a76f04324c0 Support for this library has been removed]. Use libfdk_aac instead for HE-AAC: is consistently better in all bitrates.
    175 
    176 ----
    177 
    178 == Metadata ==
    179 You can add metadata to any of the examples on this guide:
    180 
    181 {{{
    182 ffmpeg -i input ... -metadata author="FFmpeg Bayou Jug Band" -metadata title="Decode my Heart (Let's Mux)" output.mp4
    183 }}}
    184 
    185 ----
    186 
    187 == FAQ ==
    188 === Which encoder should I use? What provides the best quality? ===
     189You can also use this option on existing MP4/M4A files. Since the audio is simply being [https://ffmpeg.org/ffmpeg.html#Stream-copy stream copied] there is no re-encoding occurring, just re-muxing, so therefore there is no quality loss:
     190
     191{{{
     192ffmpeg -i input.m4a -c:a copy -movflags +faststart output.m4a
     193}}}
     194
     195----
     196
     197= FAQ =
     198
     199== Which encoder provides the best quality? ==
    189200
    190201For AAC-LC the likely answer is: `libfdk_aac` > Native FFmpeg AAC encoder (`aac`) > `libfaac`.
    191202
    192 === Should I use AAC-LC or HE-AAC? ===
     203For AAC-HE you have one choice: `libfdk_aac`.
     204
     205== Should I use AAC-LC or HE-AAC? ==
    193206
    194207If 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.
    195208
    196 == Also See ==
     209----
     210
     211= Also See =
    197212
    198213* [[Encode/HighQualityAudio|Guidelines for high quality lossy audio encoding]]