enzo1982 / freac

The fre:ac audio converter project
https://www.freac.org/
GNU General Public License v2.0
1.33k stars 70 forks source link

CBR for Opus codec? #503

Closed rwayboy closed 1 year ago

rwayboy commented 1 year ago

Hello. Would it be possible to add CBR to Opus? At the moment, I can only use constrained VBR.

enzo1982 commented 1 year ago

Hi, you can uncheck the Enable variable bitrate encoding option in fre:ac's Opus configuration dialog. That will give you CBR mode.

rwayboy commented 1 year ago

Hi, you can uncheck the Enable variable bitrate encoding option in fre:ac's Opus configuration dialog. That will give you CBR mode.

I've tried that, but I still get a higher bitrate than the one I specify in opus codec settings. These are the settings I use: 11

When I check the bitrate of the output it looks like this: 22

As you can see, even though I specified 128, the output is 137.

enzo1982 commented 1 year ago

Could it be that you have large metadata like cover images embedded in the output file? Most applications displaying the bitrate include metadata in their calculation.

I can reproduce your result here with a song that has a cover image attached. With the cover image I get a 136 kbps file, without it I get 129 kbps.

Without large metadata, the file bitrate is approximately 1 kbps higher than the configured one due to Ogg container overhead.

rwayboy commented 1 year ago

Could it be that you have large metadata like cover images embedded in the output file? Most applications displaying the bitrate include metadata in their calculation.

I can reproduce your result here with a song that has a cover image attached. With the cover image I get a 136 kbps file, without it I get 129 kbps.

Without large metadata, the file bitrate is approximately 1 kbps higher than the configured one due to Ogg container overhead.

Yes, that could be it. Why does that happen though? And does it have any impact on the audio quality given the fact that is has larger bitrate? (I mean, does the audio file still "sound" like 128 or 137?)

enzo1982 commented 1 year ago

The size of the metadata does not have any effect on the audio quality. It will still sound like 128 kbps.

If you don't want cover images attached to your files, you can disable the Write cover art to tags option in the configuration dialog under Metadata->Cover art.

rwayboy commented 1 year ago

Thank you, this cleared things up for me.

Lee-Carre commented 9 months ago

@rwayboy

Why does that happen though? And does it have any impact on the audio quality given the fact that is has larger bitrate?

An Opus file is more than merely the audio data. At minimum, there's gonna be file-type headers, metadata about how the file was encoded (so that decoders know how to decode it), structure related to the container format (which needn't be Ogg; Matroska for example). There'll also be metadata related to enabling the decoder to accurately seek to different parts of the audio.

The audio itself will have been encoded at 128Kbps. Metadata and other overheads are then in addition to that for writing the file to the file-system.

I would strongly recommend Monty's Xiph tutorial videos, notably episode 1 Digital Media Primer, which gives an excellent overview of the fundamentals. If you prefer, since they're Creative Commons licensed, you'll likely find copies on your favourite video hosting/streaming Website/‘platform’/host/service/network, too.

It'd be interesting to know which tool you're using to yield a value for the file's bit-rate. At at guess, I'd say Media Info (which is really FFprobe (part of FFmpeg) wrapped in a GUI; better off using FFprobe directly), but difficult to tell from such a small display-capture.

At a file-system/file manager level, a simple (and quick + reliable (works on any file)) way of yielding an approximate value for the bit-rate (since it at least knows that its an audio file) is to take the file-length (bit-count) and divide by the duration (seconds). However, like enzo1982 said, the file-length also includes all the metadata (and other structure), not only the audio data. So, if there's a non-trivial amount of metadata, then the result of this simple calculation will deviate (further) from the audio bitrate. The more non-audio data in the file, the worse this deviation becomes.

For such tools to know the audio bitrate, they have to essentially be able to decode the specific media codec in use, which is rather more involved (and is fragile, since things change, and add bloat to tools which aren't about media playback).

Instead, if you want an accurate value for the audio bit-rate, then use a dedicated tool, such as FFprobe.


Would it be possible to add CBR to Opus?

I'm also curious why you actively want CBR (given the obvious efficiencies of VBR); what problem does this overcome?