1

Despite having used it for years, I very recently learnt (or maybe relearnt) that FFmpeg encodes by default even when not asked to, unless the streams are explicitly passed through with -c copy.

This led me to use ffprobe to check the codec of a video I recently encoded using minimal parameters, and I now realise the video was encoded with x264 and audio with libvorbis.

x264 is unsurprising since it's the current video standard, but libvorbis surprises me given that the FFmpeg wiki ranks it lower than libopus and libfdk_aac:

libopus – usable range ≥ 32Kbps. Recommended range ≥ 64Kbps
libfdk_aac default AAC LC profile – recommended range ≥ 128Kbps; see AAC Encoding Guide.
libfdk_aac -profile:a aac_he_v2 – usable range ≤ 48Kbps CBR. Transparency: Does not reach transparency. Use AAC LC instead to achieve transparency
libfdk_aac -profile:a aac_he – usable range ≥ 48Kbps and ≤ 80Kbps CBR. Transparency: Does not reach transparency. Use AAC LC 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
libtwolame – usable range ≥ 192Kbps. Recommended range ≥ 256Kbps
mp2 – usable range ≥ 320Kbps. Recommended range ≥ 320Kbps

I compiled my FFmpeg build with both libopus and libfdk_aac, so is there a reason the audio is defaulting to libvorbis here?

And is there a way to change these defaults to ensure FFmpeg will always use libfdk_aac (unless otherwise specified)?

Hashim Aziz
  • 11,898
  • 35
  • 98
  • 166

1 Answers1

2

Why does FFmpeg default to libvorbis?

I'm assuming you output to Matroska (.mkv). You can see the defaults with:

ffmpeg -h muxer=matroska
  Muxer matroska [Matroska]:
    Common extensions: mkv.
    Mime type: video/x-matroska.
    Default video codec: h264.
    Default audio codec: vorbis.
    Default subtitle codec: ass.

If you don't know the exact name of your muxer see ffmpeg -h muxers.

Why libvorbis? It's what is listed first in libavformat/matroskaenc.c:

AVOutputFormat ff_matroska_muxer = {
    .name              = "matroska",
    .long_name         = NULL_IF_CONFIG_SMALL("Matroska"),
    .mime_type         = "video/x-matroska",
    .extensions        = "mkv",
    .priv_data_size    = sizeof(MatroskaMuxContext),
    .audio_codec       = CONFIG_LIBVORBIS_ENCODER ?
                         AV_CODEC_ID_VORBIS : AV_CODEC_ID_AC3,
    .video_codec       = CONFIG_LIBX264_ENCODER ?
                         AV_CODEC_ID_H264 : AV_CODEC_ID_MPEG4,

Why libvorbis? It was changed to libvorbis from mp2 in 2011 with matroskaenc: saner default codecs. Back then libvorbis was pretty good.

Why libvorbis 10 years later?

  • Some users complain when things change.
  • Some developers complain when things change.
  • Perhaps nobody has submitted a patch to change it.
  • There are more important or interesting things to work on.
  • libopus is still kind of new.
  • libfdk_aac will never be the default as it is non-free.

And is there a way to change these defaults to ensure FFmpeg will always use libfdk_aac (unless otherwise specified)?

  • Just use -c:a libfdk_aac
  • or modify the source code and re-compile
  • or submit a patch to change the defaults
llogan
  • 57,139
  • 15
  • 118
  • 145
  • Great FFmpeg answer as always. Does FFmpeg have a Github or is everything still on mailing lists? As for changing the source code and recompiling, is it likely to be just the one place it needs changing, or a few? – Hashim Aziz Feb 25 '21 at 23:55
  • @HashimAziz Github is only used as a mirror. Development occurs on the ffmpeg-devel mailing list. Like the Linux kernel it is too big of a project to split the development into several places. For the source code you'll probably have to edit each muxer you're interested in. – llogan Feb 26 '21 at 00:01
  • 2
    *libopus is still kind of new.* --> It's over 13 years old. It's long been mature. – Gyan Feb 26 '21 at 04:42