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: Changing minimum bitrate for VBR (LAME 3.98.3) (Read 28181 times) previous topic - next topic
0 Members and 1 Guest are viewing this topic.

Changing minimum bitrate for VBR (LAME 3.98.3)

I've been experimenting with various VBR options, and I'm slightly confused as to how LAME decides what birate to use for each frame. As I understand it, LAME will try different bitrates and select the lowest bitrate that achieves acceptable quality. When using -V 2, the general output is ~192 Kbps, but when altering the -b switch, the output results do not match what I would expect. On my particular test file, when using:

lame -V 2 <input> <output> I get:



Now, as I understand how VBR works, frames are encoded at a bitrate higher than 192 Kbps when LAME feels that their complexity warrants it. Less complex frames are encoded at a lower bitrate to save space without, presumably, sacrificing perceived quality. If, however, one wanted to be paranoid and not trust LAME's judgement on which frames can safely be encoded at less than 192 Kbps, setting -b 192 would raise the threshold to "guarantee" 192 Kbps quality or greater at the expense of efficient compression. I would assume that encoding this way could be seen as CBR+, i.e. you always get the minimum quality afforded by your minimum bitrate, while unlike CBR, VBR still allows LAME to exceed that bitrate when necessary. Consequently, my assumption would be that adding -b 192 to the mix would cause all the frames encoded at less than 192 Kbps to instead be encoded at 192, since it's the new minimum bitrate (except for silence). I would also assume that the number of frames encoded at a bitrate higher than 192 Kbps would remain unchanged, as those frames would still be complex enough to warrant a higher bitrate. However, when I use:

lame -V 2 -b 192 <input> <output> on my test file, I get:



My question, therefore, is why has the number of frames encoded at 224, 256, and 320 Kbps actually decreased instead of remaining the same? My only guess is that this comes from LAME attempting to maintain the desired quality level associated with -V 2, and since it cannot use bitrates less than 192, its only option is to reduce the number of times it uses higher bitrates so that the average can remain closer to 192. This, however, sounds like what ABR mode does, so I do not see why VBR mode would act this way. Is there a switch combination that would produce the result I expected, or am I misunderstanding the way VBR works and consequently such a result is impossible? Either way, thanks for reading and any guidance you can provide.

Changing minimum bitrate for VBR (LAME 3.98.3)

Reply #1
My guess would be when you change the minimum bitrate to -b192 that the encoder uses the bit reservoir more liberally in an attempt to not balloon the size up as much since it can not use smaller than 192kbps frames.
Nero AAC 1.5.1.0: -q0.45

Changing minimum bitrate for VBR (LAME 3.98.3)

Reply #2
My guess would be when you change the minimum bitrate to -b192 that the encoder uses the bit reservoir more liberally in an attempt to not balloon the size up as much since it can not use smaller than 192kbps frames.

That's an interesting theory. If I understand the purpose of the bit reservoir correctly, this would mean that the quality would be equal to my expected result while the file size remains low? If so, it would seem that I have underestimated LAME's ingenuity.

Changing minimum bitrate for VBR (LAME 3.98.3)

Reply #3
When using LAME in VBR mode, setting a low bitrate minimum doesn't affect audio quality. The minimum bitrate setting is used after encoding the frame, when audio data gets packaged into sufficient sized frames.

Changing minimum bitrate for VBR (LAME 3.98.3)

Reply #4
I see. Does that then mean that there is no way to raise the minimum bitrate in VBR mode in respect to audio quality?

Changing minimum bitrate for VBR (LAME 3.98.3)

Reply #5
When using LAME in VBR mode, setting a low bitrate minimum doesn't affect audio quality. The minimum bitrate setting is used after encoding the frame, when audio data gets packaged into sufficient sized frames.

Yes, and we had the same question in the lame command line thread.
Only thing I do't understand: why is audio data stream not exactly the same when using -Vx -b nnn as with plain -Vx? (I tried last night - foobar said that there is a difference, and peak difference isn't small).
lame3995o -Q1.7 --lowpass 17

Changing minimum bitrate for VBR (LAME 3.98.3)

Reply #6
[wild speculation]

Probably because the bit-reservoir is full (with wasted bits) most of the time and therefore it's not needed to go to higher bitrates that often. Without a minimum bitrate the reservor is empty or quite small since the encoder uses the smallest possible framesize.

So I guess minimum bitrate will smooth "quality peaks" out in terms of framesize. Maybe it can even improve quality for rare cases when frames exceed 320kbit and would otherwise have no bit-reservor to add extra bits. In that case it could make sense to add some kind of 2-pass encoding that increases frames that come before difficult passages to have a full bit-reservoir.

How big can the reservoir become? Is it even possible to add it to 320kbit frames?

Changing minimum bitrate for VBR (LAME 3.98.3)

Reply #7
What I don't understand is why there isn't at least the possibility of forcing LAME to use only bitrates greater than or equal to a certain value, if for some reason you want to ensure/maximize quality at the expense of file size. Since LAME can occasionally select the wrong bitrate in VBR mode, it seems like it would be a good failsafe to allow such a behaviour "just in case" and for the overly paranoid.

From the LAME documentation:

Quote
*NOTE* No psy-model is perfect, so there can often be distortion which
is audible even though the psy-model claims it is not!  Thus using a
small minimum bitrate can result in some aggressive compression and
audible distortion even with -V 0.  Thus using -V 0 does not sound
better than a fixed 256 kbps encoding.  For example: suppose in the 1 kHz
frequency band the psy-model claims 20 dB of distortion will not be
detectable by the human ear, so LAME VBR-0 will compress that
frequency band as much as possible and introduce at most 20 dB of
distortion.  Using a fixed 256 kbps framesize, LAME could end up
introducing only 2 dB of distortion.  If the psy-model was correct,
they will both sound the same.  If the psy-model was wrong, the VBR-0
result can sound worse.


Since the psy-model can be wrong, from what I'm reading in this topic, if you do happen to encounter a file that gets encoded with audible artifacts even at -V 0, your only option is to use -b 320 -q 0 instead. I realize that the chances of this happening at high bitrates like those used with -V 0/1/2 are unlikely, but still.


Changing minimum bitrate for VBR (LAME 3.98.3)

Reply #9
When using LAME in VBR mode, setting a low bitrate minimum doesn't affect audio quality.

Are you talking about the "psychological" audio quality?

Because in this case (Aleron Ives example), it does affect the bitrate (and then the quality) since it goes from 193 to 201 Kbps!

Changing minimum bitrate for VBR (LAME 3.98.3)

Reply #10
How big can the reservoir become? Is it even possible to add it to 320kbit frames?

Your speculation is right. The bit reservoir can grow up to 4088 bits. A 320 kbps frame, plus maximum previously unused bits from the reservoir, can result in a ~470 kbps peak. (use 3.99 and add --buffer-constraint maximum -b320, after encoding feed it into mp3repacker to make it VBR again)

Changing minimum bitrate for VBR (LAME 3.98.3)

Reply #11
Only thing I do't understand: why is audio data stream not exactly the same when using -Vx -b nnn as with plain -Vx? (I tried last night - foobar said that there is a difference, and peak difference isn't small).

What onkl said.

Changing minimum bitrate for VBR (LAME 3.98.3)

Reply #12
Since LAME can occasionally select the wrong bitrate in VBR mode, it seems like it would be a good failsafe to allow such a behaviour "just in case" and for the overly paranoid.

How do you determine the "occasionally wrong selected bitrate in VBR mode" ? Eye or ABX ?
When by eye, how do you know that a 32 kbps frame doesn't refer to 180 kbps of audio data ?

Changing minimum bitrate for VBR (LAME 3.98.3)

Reply #13
I've been experimenting with various VBR options, and I'm slightly confused as to how LAME decides what birate to use for each frame. As I understand it, LAME will try different bitrates and select the lowest bitrate that achieves acceptable quality.

LAME doesn't try bit-rates in VBR mode, well it actually worked that way in its very first incarnation, until mid 1999. LAME's psy model determines how much quantization noise is allowed, what block-type to select and how two channels are best represented. In VBR mode LAME encodes a frame with the allowed amount of quantization noise, and picks the smallest frame large enough to hold the audio data. In CBR mode, frame size is fix and bitrate distribution among granules and channels is determined by the psy model, and LAME tries to minimize the quantization noise until the desired bitrate is reached. (Note: current VBR uses a slightly different psy-model than for CBR)

Changing minimum bitrate for VBR (LAME 3.98.3)

Reply #14
Only thing I do't understand: why is audio data stream not exactly the same when using -Vx -b nnn as with plain -Vx? (I tried last night - foobar said that there is a difference, and peak difference isn't small).

What onkl said.

So is this correct?:
When using -V0 -b 320 there can be situations where the audio stream determined by the VBR mechanism can be placed into the current frame + bit reservoir of the previous frame(s), but it has to be simplified a bit in the case of pure -V0 due to lacking space.

So for those who don't care about the slightly increased encoding time but are nitpicking about quality: it's a good idea to use -V0 -b 320 and afterwards mp3repack the output to get rid of the unused space!?
lame3995o -Q1.7 --lowpass 17

Changing minimum bitrate for VBR (LAME 3.98.3)

Reply #15
I think -b 320 -q 0 will be better idea...

Audible differences (on problem samples) between -V 0 and -V 0 -b 320 is much smaller than between -V 0 and -b 320 -q 0

For me VBR sounds too bad with any settings

-V 0 vs -V 0 -b 320
🇺🇦 Glory to Ukraine!

Changing minimum bitrate for VBR (LAME 3.98.3)

Reply #16
CBR 320 takes roughly 100 kbps more on average than -V0 -b 320 | mp3packer. Other than that -V0 can produce better quality than CBR320 with specific samples as was found by I guess it was /mnt.

I was talking about potential quality impovement on (rare) occasion of -V0 -b 320 | mp3packer over plain -V0. Bitrate of these variants are nearly identical on average.
lame3995o -Q1.7 --lowpass 17

Changing minimum bitrate for VBR (LAME 3.98.3)

Reply #17
I was talking about potential quality impovement on (rare) occasion of -V0 -b 320 | mp3packer over plain -V0. Bitrate of these variants are nearly identical on average.


You're right. See my testing results, I've got little average bitrate increase (+10 kbps) and some quality improvement. 
But I'm not sure that quality improvement is possible without avg bitrate increase... I think it must be some bitrate redistribution (which requires psy model changes. or not?) to achieve higher quality with same file size

Quote
-V0 can produce better quality than CBR320 with specific samples


Does anyone can to provide this samples? 
🇺🇦 Glory to Ukraine!

Changing minimum bitrate for VBR (LAME 3.98.3)

Reply #18
Here is /mnt's post with the sample.
It was done with 3.98.2 though as the discussion in february about max bit reservoir/buffer size for 320 kbps frames led to the improvement robert gave us with 3.98.3. But that was later.

Bitrate difference for regular music (my standard test set of various kind of popular music):

-V0: 227 kbps
-V0 -b 320 | mp3packer: 234 kbps

I just ABXed eig -V0 against -V0 -b 320 | mp3packer. It wasn't difficult, -V0 -b 320 | mp3packer is clearly better.

I also tried the -V0 --ns-xxx variant I recently used, together with -b 320. It was clearly worse than -V0 -b 320. Obviously the generally increased quality demand by using --ns-xxx doesn't allow for high audio data bitrate when it's needed due to lack of space. Without -b 320 things should be even worse. So at least for pre-echo prone stuff it's not a good idea.
lame3995o -Q1.7 --lowpass 17

Changing minimum bitrate for VBR (LAME 3.98.3)

Reply #19
I encoded eig.wav with -V0 and -V0 -b320 settings:

-V0:
469127 bytes of MP3 data (249.427333 kbps) = minimum bitrate possible
Largest frame uses 9501 bits = 1188 bytes = 363.710156 kbps

-V0 -b320:
484181 bytes of MP3 data (257.431304 kbps) = minimum bitrate possible
Largest frame uses 10976 bits = 1372 bytes = 420.175000 kbps

Changing minimum bitrate for VBR (LAME 3.98.3)

Reply #20
@robert:

Would it be a difficult change if frame bitrate was always chosen in such a way that bit reservoir is always kept close to maximum when using -Vx (without -b n)?
That would keep available space for the audio data stream at maximum and wouldn't increase bitrate over what is needed by the VBR mechanism. It just inhibits reducing quality considered necessary due to lacking space (resp. restricts it only to the limits of the audio data stream given by the mp3 format).
lame3995o -Q1.7 --lowpass 17

Changing minimum bitrate for VBR (LAME 3.98.3)

Reply #21
Quote
Largest frame uses 10976 bits = 1372 bytes = 420.175000 kbps


And now, who will explain me how frame can use 420 kbps when the largest possible bitrate for frame is 320?
🇺🇦 Glory to Ukraine!


Changing minimum bitrate for VBR (LAME 3.98.3)

Reply #23
I don't fully understand what a bit reservoir really means and how it works in reality...
Where reserved bits are "physically" located? In previous frames?
🇺🇦 Glory to Ukraine!

Changing minimum bitrate for VBR (LAME 3.98.3)

Reply #24
And in frames that follow as well, I believe; that's correct.  The unused portion of a frame can hold data for other frames.  The point of VBR is to minimize the reservoir.  Mp3packer is designed to use the reservoir as efficiently as possible.