What is the effect of the "quality" option in SoX mp3 compression?
Asked Answered
O

2

6

I am converting audio files of several different formats to mp3 using SoX. According to the docs, you can use the -C argument to specify compression options like the bitrate and quality, the quality being after the decimal point, for example:

sox input.wav -C 128.01 output.mp3 (highest quality, slower)

sox input.wav -C 128.99 output.mp3 (lowest quality, faster)

I expected the second one to sound terrible, however, the audio quality between the two sounds exactly the same. If that is the case, I do not understand why one performs so much slower or what I would gain by setting the compression to higher "quality".

Can someone please tell me if there is a real difference or advantage to using higher quality compression versus lower quality?

P.S. I also checked the file size of each output file and both are exactly the same size. But when hashed, each file comes out with a different hash.

Osyth answered 6/8, 2013 at 22:14 Comment(0)
G
3

The parameters are passed on to LAME. According to the LAME documentation (section “algorithm quality selection”/-q), the quality value has an effect on noise shaping and the psychoacoustic model used. They recommend a quality of 2 (i.e. -C 128.2 in SoX), saying that 0 and 1 are much slower, but hardly better.

However, the main factor determining the quality remains the bit rate. It is therefore not too surprising that there is no noticeable difference in your case.

Gravelblind answered 8/8, 2013 at 22:26 Comment(4)
I followed your link to the LAME docs and did some research on Huffman encoding and the psychoacoustics model, but my impression is that these should still provide additional compression and strip out imperceptible sounds from the audio, resulting in a smaller file size. Using the best and the worst quality selection, I see no difference in file size (transcoding a 27.1 MB wav file to a 128 kbps mp3 on both -q 0 and -q 9 result in exactly 2,462,615 bytes each). Can you explain how that would be possible? Does it matter if I am using a constant bitrate? Thanks for your response, by the way.Osyth
@Michael Brook: When the encoder is told to produce 128 kb per second, it will output 128 kb per second, so the size of two files having the same length (in seconds) will be the same. The quality may still be different, because with a simpler model the encoder could be misguided into discarding different audio features that aren't imperceptible after all.Gravelblind
I see. So basically, the quality setting does not affect the file size whatsoever, it's just that setting it to a higher quality allows the encoder to make a more educated guess as to which parts of the audio it should emphasize and which parts are imperceptible. Correct?Osyth
@Michael Brook: Yes. Of course, it is different when you choose variable bit rate (VBR) mode, then the file size may vary.Gravelblind
C
1

For me faster with simple

time sox input.mp3 -C 128 output.mp3

real 0m7.417s user 0m7.334s sys 0m0.057s

time sox input.mp3 -C 128.02 output.mp3

real 0m39.805s user 0m39.430s sys 0m0.205s

Croissant answered 9/9, 2015 at 18:30 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.