Skip to main content

Notice

Please note that most of the software linked on this forum is likely to be safe to use. If you are unsure, feel free to ask in the relevant topics, or send a private message to an administrator or moderator. To help curb the problems of false positives, or in the event that you do find actual malware, you can contribute through the article linked here.
Topic: CBR, VBR and bit reservoir (Read 17725 times) previous topic - next topic
0 Members and 1 Guest are viewing this topic.

CBR, VBR and bit reservoir

I'm a bit confused... I've read several documents concerning the MP3 standard but I'm not sure I inderstood well:

The MP3 ISO standard does not support VBR encoding. Which means that the uncompressed signal is devided into equal frames (1152 samples). Using VBR encoding would involve deviding the signal to unequal frames.

Instead of doing that, MP3 uses CBR frame deviding but during quantization it allocates more bits to frames that are more complex by using the bit reservoir.

In addition there are MP3 encoders which do not strictly follow the ISO standard. These encoders devide the uncompressed signal into unequal frames and therefore use VBR encoding. And if this is right, do these non-standarised encoder also use the bit reservoir?

Are all the above correct?
Thank you in advance!

CBR, VBR and bit reservoir

Reply #1
Wait, are you saying VBR would not be legal? If yes, that is wrong - VBR IS legal and every MP3 player is required to support decoding of VBR MP3s. As far as I know, VBR also uses bit reservoir, especially for 320 kbps frames where the bitrate cannot go higher.

CBR, VBR and bit reservoir

Reply #2
I think you are confusing compressed and uncompressed frame sizes.  MP3 frames always decode to 1152 samples, regardless of the bitrate.  However, the amount of compressed bits can vary from frame to frame (within the selectable bitrates)  This is what VBR means.

CBR, VBR and bit reservoir

Reply #3
Each mp3 file can be imagined as a stream of audio frames and transport frames which are moving pretty much - but not entirely - synchroneously.

An audio frame always consists of the encoding of 1152 samples.
A transport frame is what consecutively makes up for the mp3 file.

Using CBR means each transport frame consists of the same number of bits according to one of the standardized frame bitrates (320 kbps, 256 kbps, 224 kbps, ...).
In it's easiest form one transport frame takes up exactly one audio frame.
However the mp3 concept is more flexible. If the encoder decides that a transport frame has more space than is needed for the actual audio frame, it can use the remaining space for the next audio frame.
This way audio frames need not be of constant size, audio data bitrate can vary (within the limits that this bit reservoir concept puts and which make sure that audio frames are moving pretty synchroneously with transport frames).

For a higher degree of audio data bitrate variation transport frame bitrate can vary as well, and this is what we call VBR. This is well within the standard.

When people say that an encoder does not obey the standard this usually has to do with certain buffer sizes and with bit reservoir usage on 320 kbps frames. The standard isn't very clear in this respect.

From a more practical viewpoint it's not the standard or encoders not obeying the standard that is of concern but implementation details of certain decoders. Unfortunately there are decoders out there which don't allow for VBR or even high bitrate frames at all. Usually this has nothing to do with the standard.

If you have to care about such things, you can take care of bad decoders on the encoding side: use CBR 224 as well as Lame's strict-iso option.
lame3995o -Q1.7 --lowpass 17

CBR, VBR and bit reservoir

Reply #4
Halb27, I'm not sure I understand the difference between audio frames and transport frames. So, let me be more specific:

As far as I know the first step of an MP3 encoder is the segmentation into frames of samples. Is this frame size constant or variable? (I understand that it is constant - 1152 samples). And does this has to do with the encoding being CBR or VBR? The bit reservoir is used in CBR, VBR or in both??

And another question... From what you're saying the MP3 ISO standard includes VBR. What about Layers I and II. Do they support VBR?

CBR, VBR and bit reservoir

Reply #5
Quote
As far as I know the first step of an MP3 encoder is the segmentation into frames of samples. Is this frame size constant or variable? (I understand that it is constant - 1152 samples).

It is always 1152 samples.

Quote
And does this has to do with the encoding being CBR or VBR?

It doesn't. CBR or VBR is related to the size of the compressed frames in bits (not samples!). The size of the compressed frames in bits is allowed to vary in which case we speak of VBR.

Quote
The bit reservoir is used in CBR, VBR or in both??

Bit reservoir can be used in both.

Quote
From what you're saying the MP3 ISO standard includes VBR. What about Layers I and II. Do they support VBR?

Layer II supports VBR for encoding (not really in a good way, but still), but it is not mandatory for layer II decoders to support this.
"We cannot win against obsession. They care, we don't. They win."

CBR, VBR and bit reservoir

Reply #6
Bit reservoir can be used in both CBR and VBR mode; it's up to the encoder. You can even tell LAME not to use a bit reservoir at all.

As far as I know, frame size is constant and is 1152 samples for MPEG 1 Layer II and III and MPEG 2(.5) Layer II. For MPEG 1 Layer I it's 384, for MPEG 2(.5) Layer I it's 192 and for MPEG 2(.5) Layer III it's 576. These figures are based on a PDF I read years ago. Edit: Anyways, the size should remain constant over the whole stream.

Layer I does not support VBR, Layer II can support VBR and Layer III has to support VBR as far as I know.

CBR, VBR and bit reservoir

Reply #7
Quote
And does this has to do with the encoding being CBR or VBR?

It doesn't. CBR or VBR is related to the size of the compressed frames in bits (not samples!). The size of the compressed frames in bits is allowed to vary in which case we speak of VBR.


When you say "compressed frame" what exactly do you mean? Do you mean the compressed (quantized, coded) representation of an input frame?

CBR, VBR and bit reservoir

Reply #8
When you say "compressed frame" what exactly do you mean? Do you mean the compressed (quantized, coded) representation of an input frame?

stephanV certainly was talking about the encoded representation of an input frame.
lame3995o -Q1.7 --lowpass 17

CBR, VBR and bit reservoir

Reply #9

When you say "compressed frame" what exactly do you mean? Do you mean the compressed (quantized, coded) representation of an input frame?

stephanV certainly was talking about the encoded representation of an input frame.


So... if I understand well, in CBR mode there is a constant size for every compressed frame. How can that happen when the bit reservoir is used in CBR mode?


When you say "compressed frame" what exactly do you mean? Do you mean the compressed (quantized, coded) representation of an input frame?

stephanV certainly was talking about the encoded representation of an input frame.


So... if I understand well, in CBR mode there is a constant size for every compressed frame. How can that happen when the bit reservoir is used in CBR mode?


When you say "compressed frame" what exactly do you mean? Do you mean the compressed (quantized, coded) representation of an input frame?

stephanV certainly was talking about the encoded representation of an input frame.


So... if I understand well, in CBR mode there is a constant size for every compressed frame. How can that happen when the bit reservoir is used in CBR mode?


CBR, VBR and bit reservoir

Reply #11
Bit reservoir uses unused space from previous frames.

But if a previous frame leaves some space unused then its size will not be equal to the sizes of the other frames. Which means the encoding is not CBR


CBR, VBR and bit reservoir

Reply #13
If a 30x30x30 cm box is full and another 30x30x30 cm one is not, it doesn't mean that one box is smaller.


If the box you are saying is a compressed frame then there is no bit saving since "empty" means zero-valued bits.

pffff..... i'm mixed up!!!

CBR, VBR and bit reservoir

Reply #14
drrat,
The bit reservoir uses part of the current compressed frame to provide data for the next frame.  Each frame is going to be the same size, just that the data isn't evenly distributed between the frames.

CBR, VBR and bit reservoir

Reply #15
[So... if I understand well, in CBR mode there is a constant size for every compressed frame. How can that happen when the bit reservoir is used in CBR mode?

The "compressed frame" or (my words:) audio frame is the encoded data representation of 1152 samples.
Even with CBR the amount of bits used for an audio frame can vary from frame to frame depending on what the encoder does.
An mp3 stream consist of a sequence of frames (I called them transport frames) each of which carries the same amount of bits when using CBR.
Now the encoder has to put the audio frames into the equal sized frames. Because of the variable sized audio frames there may be space left in a frame. This free space need not be left free but can be partially used for the next audio frame. This mechanism is the bit reservoir.

Of course the encoder doesn't do these things by chance. If the current music is easy to encode (temporary silence for instance) it can represent the current 1152 samples with a small audio frame. It will do so and use the space left in  the current (transport) frame for the next audio frame. This way the encoder can save up space for more complex musical parts.

By this audio frame bitrate can be much higher then 320 kbps as space from the previous transport frame can be used.
lame3995o -Q1.7 --lowpass 17

CBR, VBR and bit reservoir

Reply #16
Time for instructional images by Klyith! In these pictures, the line at the bottom shows time and each box above it is an mp3 frame. Each tick is 1152 samples, but how much actual time that represents would depend on the sample rate of the audio.

This is CBR

Each frame is the same size.

This is VBR

Same number of frames in each unit of time, but the frames have a variable amount of bits contained.

This is a bit reservoir on a CBR mp3.

It's hard to explain with words, but easy to see in a picture. The blue frame is taking some unused space from the red frame, which would otherwise be wasted, and using it to effectively add "space" to it's own frame. So while the frames are a fixed size, the data that they contain is a bit variable.

Edits: I got the vbr screwed up the first time. There's nothing like trying to explain something to understand it better yourself!

CBR, VBR and bit reservoir

Reply #17
Time for instructional images by Klyith! In these pictures, the line at the bottom shows time and each box above it is an mp3 frame.


Klyith! Very nice explanation! I get the point!

But:
Since in VBR you have variable size of frames, which means you don't waste any bits, why use the bit reservoir on a VBR stream? What I mean, what advantage does the bit reservoir add to VBR?

CBR, VBR and bit reservoir

Reply #18
Even in VBR the frames must all be one of the defined sizes. If the bit reservoir were not used then some space would be wasted each time the number of bits needed was not equal to exactly one of these sizes.

CBR, VBR and bit reservoir

Reply #19
Even in VBR the frames must all be one of the defined sizes. If the bit reservoir were not used then some space would be wasted each time the number of bits needed was not equal to exactly one of these sizes.


OK! Now it's clear. Thanx to all

Just one more question: Other CODECs in CBR mode, do they use anything like the bit reservoir?



 

CBR, VBR and bit reservoir

Reply #23
What about OGG?

Yes Vorbis (technically ogg is the container, vorbis is the codec) has a reservoir.

It is variable, defaulting to 2 seconds of audio data at the average encoding bitrate, so actual size is dependent on what quality value you use. None of the standard encoders expose the setting to change the reservoir, but it can be altered at compile.

Edit:
Quote
' date='Nov 28 2006, 12:25' post='452816']OGG is not CBR. it only works in CBR when forcing the VBR engine to not fluctuate.
VBR codecs have reservoirs too, as was mentioned above.

CBR, VBR and bit reservoir

Reply #24
VBR also uses bit reservoir, especially for 320 kbps frames where the bitrate cannot go higher.

Hm, i like that! So the quality of VBR mp3 could be even higher than of 320 kbps CBR (aka "insane" in LAME)?    I wasn't thinking about that before!