aacencodingguide – ffmpeg

4
11/16/13 AACEncodingGuide – FFmpeg https://trac.ffmpeg.org/wiki/AACEncodingGuide 1/4 Last modified 6 days ago FFmpeg and AAC Encoding Guide Advanced Audio Coding (AAC) is the successor format to MP3, and is defined in MPEG4 part 3 (ISO/IEC 144963). It is often used within an MP4 container format; for music the .m4a extension is customarily used. The secondmost common use is within MKV (Matroska) files because it has better support for embedded textbased soft subtitles than MP4. The examples in this guide will use the extensions MP4 and M4A. FFmpeg can support four AACLC encoders (aac , libfaac , libfdk_aac , libvo_aacenc ) and two AACHE encoders (libaacplus and libfdk_aac ). The licenses of libaacplus , libfaac , and libfdk_aac are not compatible with the GPL and distribution of binaries containing code licensed under these licenses when GPLlicensed code is also included is not permitted. Therefore these encoders have been designated as "nonfree", and you cannot download a prebuilt ffmpeg that supports them. This can be resolved by compiling ffmpeg. libfdk_aac Fraunhofer FDK AAC codec library. This is currently the highestquality 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 lowpass filter of around 14kHz. 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 HEAAC 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 90minute movie on a 700MB(=5734400kb) CDROM, mixing the audio down to two channels (Windows users should use Contents libfdk_aac Constant Bit Rate (CBR) mode Variable Bit Rate (VBR) mode HighEfficiency AAC Native FFmpeg AAC encoder libvo_aacenc libfaac Metadata FAQ Which encoder should I use? What provides the best quality? Should I use AACLC or AACHE? I get an error about "experimental codecs". What does this mean? Also See

Upload: aston-hamilton

Post on 13-Jan-2016

8 views

Category:

Documents


0 download

DESCRIPTION

AACEncodingGuide – FFmpeg

TRANSCRIPT

Page 1: AACEncodingGuide – FFmpeg

11/16/13 AACEncodingGuide – FFmpeg

https://trac.ffmpeg.org/wiki/AACEncodingGuide 1/4

Last modified 6 days ago

FFmpeg and AAC Encoding Guide Advanced Audio Coding (AAC) isthe successor format to MP3, andis defined in MPEG­4 part 3(ISO/IEC 14496­3). It is oftenused within an MP4 containerformat; for music the .m4aextension is customarily used.The second­most common use iswithin MKV (Matroska) filesbecause it has better support forembedded text­based softsubtitles than MP4. The examplesin this guide will use theextensions MP4 and M4A.

FFmpeg can support four AAC­LC encoders (aac, libfaac, libfdk_aac, libvo_aacenc) and twoAAC­HE encoders (libaacplus and libfdk_aac). The licenses of libaacplus, libfaac, andlibfdk_aac are not compatible with the GPL and distribution of binaries containing code licensedunder these licenses when GPL­licensed code is also included is not permitted. Therefore theseencoders have been designated as "non­free", and you cannot download a pre­built ffmpeg thatsupports them. This can be resolved by compiling ffmpeg.

libfdk_aac

Fraunhofer FDK AAC codec library. This is currently the highest­quality AAC encoder availablewith 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 filterof around 14kHz. If you want to preserve higher frequencies, use -cutoff 18000. Adjust thenumber 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 yougreater 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.1surround 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 a700MB(=5734400kb) CD­ROM, mixing the audio down to two channels (Windows users should use

Contentslibfdk_aacConstant Bit Rate (CBR) modeVariable Bit Rate (VBR) modeHigh­Efficiency AAC

Native FFmpeg AAC encoderlibvo_aacenclibfaacMetadataFAQWhich encoder should I use? What provides the best quality?Should I use AAC­LC or AAC­HE?I get an error about "experimental codecs". What does this mean?

Also See

Page 2: AACEncodingGuide – FFmpeg

11/16/13 AACEncodingGuide – FFmpeg

https://trac.ffmpeg.org/wiki/AACEncodingGuide 2/4

NUL rather than /dev/null):

Variable Bit Rate (VBR) mode

Target a quality, rather than a specific bit rate. 1 is lowest quality and 5 is highest quality. Test itout and use the lowest setting that works for you. This mode is not compatible with AAC­HE, butfor AAC­LC (the default for ffmpeg, and most compatible AAC profile) it should probably bepreferred, since it allows the encoder greater flexibility to distribute bits as it sees fit. Set theVBR level with the -vbr flag.

According to this hydrogenaudio post, the VBR modes (on average, over a number of files) givethe following bit rates per channel (so for stereo, double the bit rate; for 5.1 surround sound,multiply it by six):

VBR kb/s/channel1 322 403 48­564 645 80­96

Examples

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

ffmpeg -i input.wav -c:a libfdk_aac -vbr 3 output.m4a

Convert the audio only of a video:

ffmpeg -i input.mp4 -c:v copy -c:a libfdk_aac -vbr 3 output.mp4

Convert the video with libx264, and mix down audio to two channels:

ffmpeg -i input.mp4 -c:v libx264 -crf:v 22 -preset:v veryfast \-ac 2 -c:a libfdk_aac -vbr 3 output.mp4

High­Efficiency AAC

This is a pair of AAC profiles tailored for low bit rates (version 1 and version 2). VBR mode is notcompatible with AAC­HE so a bitrate is declared. AAC­HE version 1 is suited for bit rates below64kb/s (for stereo audio) down to about 48 kb/s, while AAC­HE version 2 is suited for bit rates aslow as 32 kb/s (again, for stereo).

Unfortunately, many devices that can play AAC­LC (the default profile for libfdk_aac) simplycannot 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 playit on your computer, or you are sure that your hardware player supports AAC­HE, you can aimfor a bit rate of 160kb/s for version 1, or 128kb/s for version 2. As always, experiment to seewhat works for your ears.

ffmpeg -y -i input.mp4 -c:v libx264 -b:v 933k -preset:v veryfast -pass 1 -an /dev/null && \ffmpeg -i input.mp4 -c:v libx264 -b:v 933k -preset:v veryfast -pass 2 \-ac 2 -c:a libfdk_aac -b:a 128k output.mp4

Page 3: AACEncodingGuide – FFmpeg

11/16/13 AACEncodingGuide – FFmpeg

https://trac.ffmpeg.org/wiki/AACEncodingGuide 3/4

AAC­HE version 1

ffmpeg -i input.wav -c:a libfdk_aac -profile:a aac_he -b:a 64k output.m4a

AAC­HE version 2

Native FFmpeg AAC encoder

The native FFmpeg AAC encoder is included with ffmpeg and is does not require an externallibrary like the other AAC encoders described here. Note that you will not get as good results aswith libfdk_aac. This is considered an experimental encoder, so -strict experimental or -strict -2 is required.

Example using -q:a

ffmpeg -i input.wav -strict experimental -c:a aac -q:a 6 output.m4a

Effective range for -q:a is probably 0.1­10 (unverified). If ffmpeg ignores -q:a then get a newerbuild (see ticket #1346).

Example using -b:a

ffmpeg -i input.wav -strict experimental -c:a aac -b:a 240k output.m4a

Note: -cutoff 15000 was previously recommended for this encoder, but this is nowautomatically applied since 2012 July.

libvo_aacenc

VisualOn AAC encoding library. Requires ffmpeg configuration with --enable-libvo-aacenc. Thishas the advantage of not being non­free, and is included by some distributors, but is a ratherpoor encoder compared to libfdk_aac and even the native FFmpeg AAC encoder according to Quality Assessment of FFmpeg AAC and a mailing list post. This encoder supports up to 2channels, is CBR only, and does not work with -q:a/-qscale:a.

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

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 libfdk_aac -profile:a aac_he_v2 -b:a 32k output.m4a

Page 4: AACEncodingGuide – FFmpeg

11/16/13 AACEncodingGuide – FFmpeg

https://trac.ffmpeg.org/wiki/AACEncodingGuide 4/4

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 goodvalue to try.

Average Bit Rate (ABR) Example

ffmpeg -i input.wav -c:a libfaac -b:a 192k output.m4a

libfaac does not support a true Constant Bit Rate (CBR) mode.

Metadata

You can add metadata to any of the examples on this guide:

FAQ

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

For AAC­LC the likely answer is: libfdk_aac > libfaac > Native FFmpeg AAC encoder (aac) >libvo_aacenc.

Should I use AAC­LC or AAC­HE?

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

I get an error about "experimental codecs". What does this mean?

Some encoders, such as the native FFmpeg AAC encoder (aac), are considered experimental andrequire the addition of -strict experimental or -strict -2 (same thing, different name) toyour command as an output option. Otherwise you may see:

Also See

Guidelines for high quality lossy audio encoding

ffmpeg -i input ... -metadata author="FFmpeg Bayou Jug Band" -metadata title="Decode my Heart (Let's Mux)" output.mp4

The encoder 'aac' is experimental but experimental codecs are not enabled, add '-strict -2' if you want to use it.