Skip to main content

Topic: Changing minimum bitrate for VBR (LAME 3.98.3) (Read 19706 times) previous topic - next topic

0 Members and 1 Guest are viewing this topic.
  • Aleron Ives
  • [*][*][*]
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.

  • DreamTactix291
  • [*][*][*][*][*]
  • Members (Donating)
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.
  • Last Edit: 21 March, 2010, 08:23:18 PM by DreamTactix291
Nero AAC 1.5.1.0: -q0.45

  • Aleron Ives
  • [*][*][*]
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.

  • robert
  • [*][*][*][*][*]
  • Developer
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.

  • Aleron Ives
  • [*][*][*]
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?

  • halb27
  • [*][*][*][*][*]
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

  • onkl
  • [*][*][*]
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?
  • Last Edit: 22 March, 2010, 04:57:54 AM by onkl

  • Aleron Ives
  • [*][*][*]
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.

  • ojdo
  • [*][*][*][*][*]
Changing minimum bitrate for VBR (LAME 3.98.3)
Reply #8
[lossy codec] for the overly paranoid.

I think the overly paranoid should simply use a lossless codec instead.

  • Bodhi
  • [*][*][*][*]
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!
  • Last Edit: 22 March, 2010, 06:45:27 AM by Bodhi

  • robert
  • [*][*][*][*][*]
  • Developer
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)

  • robert
  • [*][*][*][*][*]
  • Developer
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.

  • robert
  • [*][*][*][*][*]
  • Developer
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 ?

  • robert
  • [*][*][*][*][*]
  • Developer
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)

  • halb27
  • [*][*][*][*][*]
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!?
  • Last Edit: 22 March, 2010, 11:41:31 AM by halb27
lame3995o -Q1

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
  • Last Edit: 22 March, 2010, 11:53:09 AM by Steve Forte Rio

  • halb27
  • [*][*][*][*][*]
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.
  • Last Edit: 22 March, 2010, 12:12:17 PM by halb27
lame3995o -Q1

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? 
  • Last Edit: 22 March, 2010, 12:32:55 PM by Steve Forte Rio

  • halb27
  • [*][*][*][*][*]
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.
  • Last Edit: 22 March, 2010, 12:56:54 PM by halb27
lame3995o -Q1

  • lvqcl
  • [*][*][*][*][*]
  • Developer
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

  • halb27
  • [*][*][*][*][*]
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

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?
  • Last Edit: 22 March, 2010, 01:24:40 PM by Steve Forte Rio

  • greynol
  • [*][*][*][*][*]
  • Global Moderator
Changing minimum bitrate for VBR (LAME 3.98.3)
Reply #22
You know what a bit reservoir is, right?
  • Last Edit: 22 March, 2010, 03:23:27 PM by greynol
13 February 2016: The world was blessed with the passing of a truly vile and wretched person.

Your eyes cannot hear.

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?
  • Last Edit: 22 March, 2010, 01:49:44 PM by Steve Forte Rio

  • greynol
  • [*][*][*][*][*]
  • Global Moderator
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.
13 February 2016: The world was blessed with the passing of a truly vile and wretched person.

Your eyes cannot hear.