Help - Search - Members - Calendar
Full Version: -q n switch
Hydrogenaudio Forums > Lossy Audio Compression > MP3 > MP3 - Tech
pika2000
Hello, i'm new to the board.

I know that Lame's -q n switch is to determine how long the encoder spending its time processing data. When I did not specify this switch, Lame seems to choose a big number (like 4) if I use high bitrate (eg. 320kbps), and lower number (like 2) if I use medium bitrate (eg. 160kbps). My question: If I use -q 2 for 224kbps, will it yield "better" result than, let's say, -q 4 224kbps? In high bitrates, does the longer encoding time provide any benefits?

Thanks.
shadowking
Probably not. Use --preset standard for best size / quality tradeoff. No use for these switches.

http://www.hydrogenaudio.org/forums/index.php?showtopic=203&
pika2000
I already know about the presets. My question is for my own curiosity. For example, a 320kbps CBR with -q 5 vs -q 2. Will the one with -q 2 still yield better quality then the faster -q 5?
NeoRenegade
Yes. -q 2 used to be the best because -q0 and -q1 were "broken". As it stands now, 0 and 1 work properly as far as I know, but 2 is viewed as the most worthwhile compromise between encoding quality and speed. Settings such as -q 7 and -q 9 are meant for speed.
cabbagerat
The best place to look is in the code itself:
From the 3.96 code (libmp3lame/lame.c lines 273 to 401) abbreviated:
CODE
   switch (gfp->quality) {
   case 9:            /* no psymodel, no noise shaping */
       gfc->filter_type = 0;
       gfc->psymodel = 0;
       gfc->quantization = 0;
       gfc->noise_shaping = 0;
       gfc->noise_shaping_amp = 0;
       gfc->noise_shaping_stop = 0;
       gfc->use_best_huffman = 0;
       break;
...  
   case 7:            /* use psymodel (for short block and m/s switching), but no noise shapping */
       gfc->filter_type = 0;
       gfc->psymodel = 1;
       gfc->quantization = 0;
       gfc->noise_shaping = 0;
       gfc->noise_shaping_amp = 0;
       gfc->noise_shaping_stop = 0;
       gfc->use_best_huffman = 0;
       break;
  ...
   case 2:
       gfc->filter_type = 0;
       gfc->psymodel = 1;
       gfc->quantization = 1;
       if (gfc->noise_shaping == 0)
           gfc->noise_shaping = 1;
       if (gfc->substep_shaping != 0)
        gfc->substep_shaping = 2;
       gfc->noise_shaping_amp = 1;
       gfc->noise_shaping_stop = 1;
       if (gfc->subblock_gain == -1)
           gfc->subblock_gain = 1;
       gfc->use_best_huffman = 1; /* inner loop */
       break;
 ...
   case 0:
       gfc->filter_type = 0; /* 1 not yet coded */
       gfc->psymodel = 1;
       gfc->quantization = 1;
       if (gfc->noise_shaping == 0)
           gfc->noise_shaping = 1;
       if (gfc->substep_shaping != 0)
        gfc->substep_shaping = 2;
       gfc->noise_shaping_amp = 2;
       gfc->noise_shaping_stop = 1;
       if (gfc->subblock_gain == -1)
           gfc->subblock_gain = 1;
       gfc->use_best_huffman = 2;
       break;
   }

I took out a bunch of stuff there to make it shorter, so you should go look at the whole thing yourself. This should give you a good idea of what the -q settings do. For real-world effect on quality, you will have to trust your ears.
Mike Giacomelli
I think in newer lame versions, q values below 2 just use more aggressive lossless encoding of the lossy compressed data in order to save a few percent, IIRC. So theres not much sense in useing them if you just want the transparency.
cabbagerat
QUOTE
I think in newer lame versions, q values below 2 just use more aggressive lossless encoding of the lossy compressed data in order to save a few percent, IIRC.

I thought so too, until I took a look at the code. As far as I can see from the LAME source, the only difference between -q1 and -q2 is -q1 sets noise_shape_amp to 2 instead of -q2's setting of 1. This is used in the (lossy) quantize step, so it appears as though -q1 over -q2 does have an effect on the lossy coding stage. I have no idea what the effect on transparency would be. From 3.96 liblame/quantize.c:
CODE

*  Three algorithms:
*  noise_shaping_amp
*        0             Amplify all bands with distort[]>1.
*
*        1             Amplify all bands with distort[] >= max_dist^(.5);
*                     ( 50% in the db scale)
*
*        2             Amplify first band with distort[] >= max_dist;
*
*  For algorithms 0 and 1, if max_dist < 1, then amplify all bands
*  with distort[] >= .95*max_dist.  This is to make sure we always
*  amplify at least one band.  

-q0 over -q1 changes the behaviour of the Huffman coding step, which is lossless. It doesn't seem the change offers a major increase in compression and seriously slows things down, so it's probably not that beneficial.

I might be wrong about this - I have only recently started working on understanding the LAME source, so I may be seriously misguided. Maybe Gabriel can tell me if I am right.
km9172
It's what you hear that counts. (Or maybe what you ABX.) I can hear a noticable difference between "--preset cbr 128" and --preset cbr 128 -q0" (or even between -q1 and -q0). (No, I haven't ABX'd it). Cymbals seem to be cleaner and there seems to be significantly fewer "garbled" noises.

Of course, this is CBR 128. smile.gif

I haven't tried -q0 it with --preset standard yet because I don't think I'll be able to tell the difference. I'm going to try it with -V5 and --preset medium, as I have heard some garbled or wavering sounds. I'm not sure if they are real or imagined, of if they are expected (as in: "it's medium bitrate dummy, it's going to happen"). Previous encodings I performed (before I discovered HA) with -q0 at medium bitrates (V5-V3) seemed to mostly take care of these, but I need to do more tests!

Oh, I'm using LAME 3.96.
David Nordin
QUOTE (km9172 @ Aug 1 2004, 08:10 AM)
I can hear a noticable difference between "--preset cbr 128" and --preset cbr 128 -q0" (or even between -q1 and -q0).  (No, I haven't ABX'd it).


Terms of Service on this forum requires you to ABX and supply data from such session to provide evidence of this sort of statement. If you don't comply you're sure to see warnings as consequence.
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2009 Invision Power Services, Inc.