youtube-dl: Download Opus audio or AAC audio?

10

9

No, this is not a duplicate of this question.

I have been using youtube-dl to download some music videos from YouTube. I noted that left to its defaults, youtube-dl will use bestvideo+bestaudio, and with recent videos, for bestaudio it will nearly invariably download the Opus track.

I know that, encoded from source, Opus tracks usually have better quality than AAC tracks at the same bitrate.

However, I also know that Opus audio is not supported by the MP4 container, and since uploads to YouTube does not (yet) support MKV, the original upload would be using AAC. Which means the Opus audio track will be a lossy-transcode from AAC, potentially reducing quality.

(FI, I have no problem playing the remuxed video+audio using MPC-HC + K-Lite Mega Codecs, and I also have no problem extracting the audio using ffmpeg -c:a copy and playing it using Foobar2000)

So, my question is: Do you think I should download the AAC track instead of the Opus track, or should I just let youtube-dl does its stuff? What benefit will I get downloading the Opus track compared to downloading the AAC track?

pepoluan

Posted 2016-03-05T15:12:10.583

Reputation: 962

1Good question. I thought the best approach is for youtube-dl to download the bestvideo one as-is, without re-encoding. I actually had been wondering why youtube-dl is doing lots of re-encoding lately. It is a known fact that whatever encoding method is, no matter how good it is, if encoding from a not-so-good source, it will make things worse than before. I.e., I really hope youtube-dl will download the best one as-is, without re-encoding, as much as possible. – xpt – 2016-03-05T15:21:20.990

Answers

6

You do not have to worry so much about the source audio being AAC because, even though YouTube recommends using it as well as the MP4 container, the MKV container and lossless codecs like PCM and FLAC are in fact supported (I've been using MKV + FLAC for years now on YouTube).

But even then, if the user does in fact upload their audio in AAC, YouTube will in fact still transcode it for their AAC encodes. YouTube also recommends uploading at 48KHz, but only their Opus encodes are in 48KHz - YouTube uses 44.1KHz for both AAC and Vorbis, so both of those encodes are likely to have been downsampled as well.

In the end, Opus should still be higher quality.

Nintendo Maniac 64

Posted 2016-03-05T15:12:10.583

Reputation: 96

1YOOOO... I never knew that YouTube accepts FLAC!!! (I know it already accepts MKV, but never realized about FLAC) Thanks for the info! – pepoluan – 2017-12-01T06:42:49.077

Aaaahh, and thank you about the information w.r.t. YouTube re-encoding audio tracks to AAC!! That's VERY eye-opening... I guess I'll download in Opus from now on. Marking your answer as 'the'! :-) – pepoluan – 2017-12-01T06:43:37.397

6

Not to commenting on the youtube-dl but trying to answer your Opus audio related questions.

As ffcvt suggested, "the Opus audio codec is becoming the best thing ever for compressing audio -- A 64K Opu audio stream is comparable to mp3 files of 128K to 256K bandwidth".

If you are interested, check this out for some comprehensive info on Opus, which includes links to Sound Examples you can test out yourself.

I know your are worrying about the lossy-transcode comparing to AAC because of the potentially reducing quality, however, let me tell you, most people won't notice any differences, including some sound experts. Of course your experience will be different. So test out those Sound Examples yourself and see how different you can tell from each of them, and find your comfortable level. If you want to fine tune the bandwidth parameters, ffcvt can help.

Overall, Opus is a new audio codec, and it will become a new standard for audio on the web. Features include:

  • Better compression than mp3/ogg/aac.
  • Good for both music and spoken word.
  • Dynamically adjustable bitrate, audio bandwidth, and coding delay.
  • Good for real-time and pre-recorded applications.

xpt

Posted 2016-03-05T15:12:10.583

Reputation: 5 548

Good points. But I wonder is there a benefit of downloading the Opus track, though? Even when Opus becomes the de facto standard for audio encoding, I don't think support for AAC playback will disappear... – pepoluan – 2016-03-05T20:58:00.063

1Agree. No argument with AAC encode/playback, and honestly, I don't know if there is ready-made Opus track for downloading or not either. But if there is one, and provided that you personally can't tell the differences between Opus & AAC track, I don't see the point of downloading the AAC track myself. Opus would be smaller, takes less time to download, and takes less space on disk too, yet it'd be exactly the same to human ears. – xpt – 2016-03-05T21:30:16.700

And how to detect Opus file bitrate? VLC doesn't show it in its info – Suncatcher – 2018-04-23T09:46:52.510

That's a different question, @Suncatcher. – xpt – 2018-04-23T13:58:21.270

1

AAC is likely slightly better, though at bitrates found on Youtube, there is not a large difference, so you should choose the format based on other requirements like compatibility.

While it is true that all video and audio on Youtube are transcoded, Opus does not gain an advantage from this as indicated by the current answer. Repeated transcodes using the same codec does not reduce quality as much as you would expect from a normal transcode. Since the encoder tends to make the same or similar decisions about what data to throw away, a second pass will actually tend to keep the same data that was preserved during the first pass, resulting in fewer differences between repeated transcodes.

Here is one test demonstrating this phenomenon: After 100-passes of AAC transcodes, the result is surprisingly high quality. Additionally, IIRC on certain codecs, if you repeatedly transcode with the same settings, quality will amazingly not drop below a certain threshold, reaching an asymptote that depends on bitrate.

Since most video software encodes the audio track as AAC, the AAC track Youtube provides is likely an AAC -> AAC transcode, which will be better than an AAC -> Opus transcode.

Additionally, Opus is not always the best option for music. Although Opus is very good at a variety of audio, it does not necessarily beat all other lossy codecs in every case. Opus was originally designed as a low bit rate, low latency, speech codec for telephony applications. And while many incremental improvements were made so that it could deal with a much larger variety of audio, it still shows weaknesses in a few areas as a result of that initial design decision.

For example, Opus has an Achilles' heel where tonal music can be glaringly bad. In the 64kbps listening test, it failed miserably on a harpsichord sample (#2) against AAC. In the 96kbps listening test, it failed again on a guitar sample (take_your_finger_from_my_hair) and was even beat by MP3! Opus was originally designed with a short MDCT window for low latency, so it occasionally shows odd problems in places where AAC doesn't. The short window creates low frequency resolution that must be compensated by increasing the bitrate in order to get good quality on tonal sounds, implemented in the encoder with tonality estimation.

goweon

Posted 2016-03-05T15:12:10.583

Reputation: 1 390

Keep in mind that the AAC encodes that YouTube makes seems to pretty solidly stick to ~128kbps while their Opus encodes can peak all the way up to ~160kbps. Additionally, the AAC encodes will have their audio spectrum cut off at ~16KHz while the Opus and even the Vorbis encodes will go all the way up to ~20KHz.

While it's not AAC, with a few of my own music uploads that used 320kbps 44100KHz MP3 (because I was unable to locate lossless versions), the Opus versions definitely sounded better. – Nintendo Maniac 64 – 2018-11-20T09:28:23.750

Derp, didn't know superuser has an edit-count limit. It was actually a 160kbps MP3 at 44100Hz (not KHz :P) which I mixed up with the other couple 44100Hz 320kbps MP3 uploads (which are actually missing Opus encodes). Additionally, somewhat older Opus encodes (as in maybe two years old) have even higher bitrates that can peak all the way to ~180kbps. I also will be trying to do some listening tests with YouTube by uploading AAC audio encoded from a lossless source at various bitrates and report back at some point. – Nintendo Maniac 64 – 2018-11-20T10:03:13.657

Opus on Youtube average 128kbps, same as AAC, which is also VBR. Additionally, most audio is transparent or very close at those settings. So there isn't that much of a difference there – goweon – 2018-11-21T19:32:23.127

I haven't done my listening tests just yet, but if you download the audio stream and play it back in foobar2000 and look at the status bar showing the current bitrate, you'll see that Opus is extremely variable and regularly if not most of the time goes above that 128kbps while AAC is much less varied and tends to stick much closer to that 128kbps. And again, YouTube's AAC encodes remove frequencies above 16KHz which by definition will make them lower fidelity regardless of how perceptible that actually is (especially since "normal" AAC encodes do not have this 16KHz "wall") – Nintendo Maniac 64 – 2018-11-21T19:40:36.933

However, Opus has an Achilles' heel where tonal music can be glaringly bad. In the 64kbps listening test, it failed miserably on a harpsichord sample against AAC. In the 96kbps test, it failed again on guitar and was even beat by MP3! Opus was originally designed with a short MDCT window for low latency telephony, not high quality music, so it occasionally shows odd problems in places where AAC doesn't. To get good quality on tonal music, you're forced to ramp up the bitrate dramatically, which was later built into the encoder, but it's still not really a solved problem. – goweon – 2018-11-21T19:50:06.937

But those listening tests you are referring to were comparing a nascent Opus encoder (~5 years ago) to extremely mature AAC, MP3, and Vorbis encoders. And considering Opus' low-latency nature, it's to be expected that it wouldn't be better at absolutely everything right off the bat. But even if it still isn't better at those specific types of music even today, one must consider that AAC certainly isn't better than even 1.0 Opus at other types of music (particularly more complicated electronic type genres that are all the rage anymore) – Nintendo Maniac 64 – 2018-11-21T23:31:16.673

@goweon Opus is 160Kbps at youtube.com now. have you done the test in the 128kbps and 160kbps? – Seandex – 2019-10-21T06:53:27.707

This is a misconception. Youtube does not serve Opus at 160k, even if it claims to. If you download the opus track, it actually sits closer to 100k for all videos, same as AAC and MP3. Additionally. You'd be hard pressed to hear any difference between AAC vs Opus at 160k, so the codec question becomes a bit moot. – goweon – 2019-10-21T17:38:44.140

0

Okay, I want to share what I finally do:

  • If it's a short clip, say <5m, I use default behavior
  • If it's a long-ish clip, so >5m, I use -f best

The reason is that, out of quite a number of downloads, I have come upon a couple of failures (cut audio, mostly) with default behavior. It seems that YouTube's Opus transcoding from AAC is buggy.

With short files, I can watch+listen for problems, and redownload using -f best if necessary.

Long files, though, are difficult to watch+listen properly (hearing fatigue + need to set aside some not quite insignificant time). So I just take the safe way out with -f best.

pepoluan

Posted 2016-03-05T15:12:10.583

Reputation: 962

1I don't seem to find any audio problems with long audio clips in .opus files extracted from webm containers. – jj_ – 2017-09-19T07:42:45.257

1@jj_ I might be just unfortunate, then :-D ... probably hitting a time when YouTube was glitching on their side. – pepoluan – 2017-12-01T06:44:37.803