Recommended settings to convert Opus to AAC

aacaudiocodecffmpegyoutube-dl

I am downloading some music from Youtube, and it seems that in most cases (popular videos), the best quality audio is an opus file.

I know that (1) Opus is the newest and more efficient codec, and (2) converting from one lossy codec to another is not recommended.

However, as I want to use the same file, i.e. using same container, across Windows/iOs/car, I want to convert to AAC or MP3.

I have read here that you can mitigate the generation loss to a certain extent by using a higher bitrate for the target codec.

So what settings (e.g. ffmpeg) would you recommend to convert an opus file to AAC to keep same audio quality (I know this is subjective …)?

According to the youtube-dl -F data it is 160kbs, but when downloaded, MediaInfo gives 127Kbps overall bitrate and 48Khz sampling rate.

Would 192kbs be a good choice for the AAC file? (I presume AAC is in any case a better choice than MP3?)
I know that from CD or lossless, VBR is most recommended, but for transcoding from Opus, would CBR be better?
And should I keep the 48khz sample rate from the opus file, or downsample to the usual 44.1khz of AAC?

And finally, youtube-dl also can download an AAC file of 128 kbs.
Given that opus is more efficient/better, quality will be higher at the same bitrate. But would transcoding the opus to AAC (e.g. at 192kbs/212kbs) maintain that quality difference, or would the transcoding (even to a higher bitrate) induce artefacts so that the audio quality of the 192kbs AAC file would actually be worse than the AAC 128kbs file ?

EDIT

Let me explain why I “conceptually” struggle with understanding how to determine optimized settings for transcoding.

In most cases, you start with lossless file (e.g. a 50Mb wav), and you choose encoder settings for quality (VBR) or desired bitrate (CBR/ABR). The encoder then does its hocus pocus (discard inaudible info, compression, etc.), which then give you a smaller lossy file, based on the settings you choose. For arguments sake, let’s say maybe 3Mb for a 128kbs MP3, 5-6Mb for a top quality VBR ( i.e. highest settings for lame or qaac), and 7-8Mb for a 320kbs CBR).

But in this case, the source file is a 5Mb 128kbs opus file. The first step in transcoding is to first decode the file (to a PCM stream?), and then encode again in the new format.

So is my understanding correct that the maximum information in the file is not more than 5Mb, so to encode (and if it is not a requirement to reduce file size) I should just use the highest possible quality VBR, or possibly a high CBR (256 or 320) to capture virtually all information still present in the opus file. The resulting file would in any case not be larger than the 5Mb, as I assume no new information can be invented/generated in the process (I will do some experimenting over the weekend to test this).

The first answer given seems to suggest this.

Best Answer

More generally, I would recommend to have a look at the FFmpeg Wiki page on AAC encoding. Here you will find tips on how to achieve the best quality, which involves:

  • using the libfdk_aac encoder instead of the built-in one (the encoder can make a huge difference in quality!)
  • using VBR — there is no need to constrain the rate or waste bits
  • turning off the high pass filter, as by default some high frequencies are lost during conversion

Thus, the following would work:

ffmpeg -i input.opus -c:a libfdk_aac -vbr 5 -cutoff 18000 output.m4a

This should be absolutely transparent to anyone's ears. You may even use -vbr 4 and check whether you can detect the difference. I guess you won't.


More specifically, you ask:

And finally, youtube-dl also can download an AAC file of 128 kbs. (…) But would transcoding the opus to AAC (…) maintain that quality difference, or would the transcoding (…) induce artefacts so that the audio quality (…) would actually be worse?

Great question that I don't know how to answer without conducting a formal listening test.

However, if you assume that stereo AAC at 128 kbps is at least good quality (but not excellent), you may forgo any conversion and use that directly if it sounds good to you. I think I would listen to the original Opus and AAC samples that you directly downloaded and try to do a blind test — can you reliably detect the difference? If no, then just use AAC and save yourself the conversion.

PS: I listened to a few music clips from YouTube with both the Opus and AAC variants and I personally liked Opus better — it seemed to have a bit more high-frequency spatiality to it. But don't consider that a scientifically sound conclusion!


Finally, there is a thread discussing a similar issue, and here, one user thinks that there is more aggressive psycho-acoustic shaping in VBR encoding, which may enhance already present artifacts when encoding a lossy file again. He concludes that ABR at a high bitrate may be better suited for such tasks.

Related Question