wiki:

Encode

/

HighQualityAudio


Version 15 (modified by llogan, 5 years ago) (diff)

spaces, nits, comments

Guidelines for high quality audio encoding

This guide is meant to help people new to encoding audio to use the correct encoders and settings.

When should I transcode audio?

Avoid transcoding from lossy to lossy if possible. Use the lossless source (if you have it) or just don't transcode by copying the source audio track.

Generation loss

Transcoding from a lossy format like MP3, AAC, Vorbis, Opus, WMA, etc. to the same or different lossy format might degrade the audio quality even if the bitrate stays the same (or higher). This quality degradation might not be audible to you but it might be audible to others.
This post on hydrogenaudio.org demonstrates what will happen if you re-encode a file 100 times: http://www.hydrogenaudio.org/forums/index.php?showtopic=100067

Copying audio tracks

If the target container format supports the audio codec of the source file then really consider just muxing it into the output file. MKV supports virtually any audio codec.
This can be achieved by specifying 'copy' as the audio codec. Example:
Transcoding a WebM file (with VP8 video/Vorbis audio) to a MKV file (with H.264 video/unaltered Vorbis audio):

ffmpeg -i someFile.webm -c:a copy -c:v libx264 outFile.mkv

In some cases this might not be possible, because the target device doesn't support the codec or the target container format doesn't support the codec.
Another reason to transcode might be that the source audio track is too big. (It has a higher bitrate than what you want in the output file)

Audio encoders ffmpeg can use

ffmpeg can encode to a wide variety of audio formats.

Here are some popular formats with encoders listed that ffmpeg can use:

Dolby Digital: ac3
Dolby Digital Plus: eac3
MP2: libtwolame, mp2
Windows Media Audio 1: wmav1
Windows Media Audio 2: wmav2
LC-AAC: libfdk_aac, libfaac, aac, libvo_aacenc
HE-AAC: libfdk_aac, libaacplus
Vorbis: libvorbis, vorbis
MP3: libmp3lame
Opus: libopus

Based on quality produced from high to low:

libopus >= libfdk_aac >= libvorbis >= libmp3lame > eac3/ac3 > libfaac >= libtwolame > mp2 >= aac > wmav2/wmav1 > vorbis > libvo_aacenc 

The >= sign means greater or the same quality.
Even though AAC should generally give better quality than MP3 at the same bitrates libmp3lame should give better quality output than libfaac.
This list is just a general idea and there might be cases where codecs listed to the right might perform better than those listed to the left at certain bitrates.
The highest quality internal/native encoder available in ffmpeg without any external libraries is eac3/ac3.

Please note it is not recommended to use libvo_aacenc for AAC encoding.
Please note it is not recommended to use vorbis for Vorbis encoding.
Please note that wmav1 or wmav2 don't seem to be able to reach transparency at any given bitrate.

Container formats

Only certain audio codecs will be able to fit in your target output file.

ContainerAudio formats supported
MKV/MKAVorbis, MP2, MP3, LC-AAC, HE-AAC, WMAv1, WMAv2, AC3, eAC3
MP4/M4AMP2, MP3, LC-AAC, HE-AAC, AC3
FLV/F4VMP3, LC-AAC, HE-AAC
3GP/3G2LC-AAC, HE-AAC
MPGMP2, MP3
PS/TS StreamMP2, MP3, LC-AAC, HE-AAC, AC3
M2TSAC3, eAC3
VOBMP2, AC3
RMVBVorbis, HE-AAC
WebMVorbis
OGGVorbis, Opus

Please note that there are more container formats available than those listed above.

Recommended minimum bitrates to use

Please note that the bitrates listed here assumes the input audio channels is Stereo and the sample rate is >= 44.1Khz. Mono could require less bits.

  • libopus Recommended usable range >= 64Kbps. Compression artifacts start becoming unnoticeable around 96Kbps
  • libfdk_aac default LC-AAC profile. Recommended usable range VBR level 3 to 5 (http://ffmpeg.org/trac/ffmpeg/wiki/AACEncodingGuide). Compression artifacts start becoming unnoticeable around VBR level 3 (Around 96Kbps)
  • (libfdk_aac or libaacplus) -profile:a aac_he_v2 Recommended usable range <= 48Kbps CBR. Transparency: Does not reach transparency. Use LC-AAC instead to achieve transparency
  • (libfdk_aac or libaacplus) -profile:a aac_he Recommended usable range >= 48Kbps and <= 80Kbps CBR. Transparency: Does not reach transparency. Use LC-AAC instead to achieve transparency
  • libvorbis Recommended usable range >= 96Kbps. Compression artifacts start becoming unnoticeable around 96Kbps
  • libmp3lame Recommended usable range >= 128Kbps. Compression artifacts start becoming unnoticeable around 128Kbps
  • ac3 or eac3 Recommended usable range >= 192kbps. Compression artifacts start becoming unnoticeable around 192Kbps
  • libfaac Recommended usable range >= 192kbps. Compression artifacts start becoming unnoticeable around 192Kbps. Some samples still show some artifacts
  • libtwolame Recommended usable range >= 192kbps. Compression artifacts start becoming unnoticeable around 192Kbps
  • mp2 Recommended usable range >= 192kbps. Artifacts not so annoying as other encoders. Compression artifacts start becoming unnoticeable around 320Kbps
  • aac Recommended usable range >= 300kbps. Compression artifacts start becoming unnoticeable around 300Kbps
  • vorbis Recommended usable range >= 280kbps. Compression artifacts start becoming unnoticeable around 280Kbps
  • wmav1 or wmav2 Recommended usable range >= ????kbps. Does not reach transparency. Notice artifacts on every bitrate. Broken?
  • libvo_aacenc Recommended usable range >= ????kbps. Does not reach transparency. Notice artifacts on every bitrate. Broken?

Please note Opus streams are currently not muxable in MKV containers. Only Ogg Containers are supported at the moment. MKV container support should be available in the future
When compatibility with hardware players doesn't matter then use libvorbis in a MKV container rather than libfaac when libfdk_aac isn't available
When compatibility with hardware players does matter then use libmp3lame or ac3 in a MP4/MKV container rather than libfaac when libfdk_aac isn't available
Transparency means the encoded audio sounds indistinguishable from the audio in the source file.

TODO: Add ABC/HR tests.