Version 45 (modified by atomnuker, 4 years ago) (diff)


Guidelines for high quality lossy audio encoding

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

When should I transcode audio?

Avoid transcoding from a lossy format to the same or another lossy format when possible. Transcode to lossy from the lossless source (if you have it), or just copy the lossy source audio track instead of transcoding.

Another option if you have a lossless source is to transcode it to another lossless codec, like flac .

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 demonstrates what will happen if you re-encode a file 100 times:

Copying audio tracks

If the target container format supports the audio codec of the source file then consider just muxing it into the output file without re-encoding. MKV supports virtually any audio codec. This can be achieved by specifying 'copy' as the audio codec.

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/player 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 to use in the output file).

Audio encoders FFmpeg can use

FFmpeg can encode to a wide variety of lossy audio formats.

Here are some popular lossy 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, libshine
Opus: libopus

Based on quality produced from high to low:

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

For AAC only: (Because it is a little bit confusing, with 4 encoders available)

aac >= libfdk_aac > libfaac > 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 guide and there may be cases where a codec listed to the right will perform better than one listed to the left at certain bitrates.
The highest quality internal/native encoder available in FFmpeg without any external libraries is aac .

Please note it is not recommended to use vorbis for Vorbis encoding; use libvorbis instead.
Please note that wmav1,wmav2 and libvo_aacenc 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, Opus
WebMVorbis, Opus
OGGVorbis, Opus

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

Recommended minimum bitrates to use

The bitrates listed here assume 2-channel stereo and a sample rate of 44.1kHz or 48kHz. Mono may require fewer bits.

  • libopus Usable range >= 80Kbps. Recommended range >= 128Kbps
  • libfdk_aac default LC-AAC profile. Recommended range >= 128Kbps; see AAC Encoding Guide.
  • (libfdk_aac or libaacplus) -profile:a aac_he_v2 Usable range <= 48Kbps CBR. Transparency: Does not reach transparency. Use LC-AAC instead to achieve transparency
  • (libfdk_aac or libaacplus) -profile:a aac_he Usable range >= 48Kbps and <= 80Kbps CBR. Transparency: Does not reach transparency. Use LC-AAC instead to achieve transparency
  • libvorbis Usable range >= 96Kbps. Recommended range -aq 4 (>= 128Kbps)
  • libmp3lame Usable range >= 128Kbps. Recommended range -aq 2 (>= 192Kbps)
  • ac3 or eac3 Usable range >= 160kbps. Recommended range >= 160Kbps
  • libfaac Usable range >= 160kbps. Recommended range -q:a 330 -cutoff 15000 (>= 192Kbps).
    Example of usage:
    ffmpeg -i input.wav -c:a libfaac -q:a 330 -cutoff 15000 output.m4a
  • aac Usable range >= 32kbps (depending on profile and audio). Recommended rate >= 128Kbps
    Example of usage:
    ffmpeg -i input.wav output.m4a
  • libtwolame Usable range >= 192kbps. Recommended range >= 256Kbps
  • mp2 Usable range >= 320kbps. Recommended range >= 320Kbps

The vorbis, wmav1/wmav2 and libvo_aacenc encoders are not worth using.
The wmav1/wmav2 and libvo_aacenc encoders do not reach transparency at any bitrate.
The vorbis encoder does not use the bitrate specified in ffmpeg. On some samples it does sound reasonable, but the bitrate is very high.

To calculate the bitrate to use for multi-channel audio: (bitrate for stereo) x (channels / 2).
Example for 5.1(6 channels) Vorbis audio: 128Kbps x (6 / 2) = 384Kbps

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.