Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

sox - how to create mp3 file with bit rate 16kbps

Currently the command used is

    `sox input.wav -G -t mp3 -r 16k test.mp3`

But this is creating a file with bit rate 24.0 kbps.

How to make the bit rate of the out put file to 16.0 kbps?

like image 327
Shamis Shukoor Avatar asked Nov 03 '14 13:11

Shamis Shukoor


People also ask

What bit rate should I export MP3?

For music, 64 (AAC)/96 (MP3) kbps is a good general-purpose setting that will sound good most listeners. This is the standard bitrate for podcasts, for example, and it sounds great on most contemporary devices, including smart speakers and mobile devices.

What is a bit rate MP3?

Bitrate is the number of bits (or data) that are processed per unit of time. The average bitrate for an MP3 file is 128 kbits per second or kbps. A file created at this bitrate should have good quality and takes up about 1 Megabytes of data per minute of audio. Different bitrates yield varying sound quality.


1 Answers

In the sox formats manual you find, that it is the -C option. Below I quote the whole section because you may find it interesting.

However, if I call sox test.wav -C 16.01 test.mp3 my testfile (48kHz/16bit) is converted to 32kbps. If I call lame test.wav -b 16 -q 0 test.mp3 I get 16kbps but test.mp3 is converted to a samplerate of 8kHz. But if I really want to keep my 48kHz with lame test.wav -b 16 -q 0 --resample 48000 test.mp3 I also get 32kbps. So we see, there is a compromise between a high samplerate and a high compression ratio.

MP3 compressed audio; MP3 (MPEG Layer 3) is a part of the patent-encumbered MPEG standards for audio and video compression. It is a lossy compression format that achieves good compression rates with little quality loss.

Because MP3 is patented, SoX cannot be distributed with MP3 support without incurring the patent holder’s fees. Users who require SoX with MP3 support must currently compile and build SoX with the MP3 libraries (LAME & MAD) from source code, or, in some cases, obtain pre-built dynamically loadable libraries.

When reading MP3 files, up to 28 bits of precision is stored although only 16 bits is reported to user. This is to allow default behavior of writing 16 bit output files. A user can specify a higher precision for the output file to prevent lossing this extra information. MP3 output files will use up to 24 bits of precision while encoding.

MP3 compression parameters can be selected using SoX’s −C option as follows (note that the current syntax is subject to change):

The primary parameter to the LAME encoder is the bit rate. If the value of the −C value is a positive integer, it’s taken as the bitrate in kbps (e.g. if you specify 128, it uses 128 kbps).

The second most important parameter is probably "quality" (really performance), which allows balancing encoding speed vs. quality. In LAME, 0 specifies highest quality but is very slow, while 9 selects poor quality, but is fast. (5 is the default and 2 is recommended as a good trade-off for high quality encodes.)

Because the −C value is a float, the fractional part is used to select quality. 128.2 selects 128 kbps encoding with a quality of 2. There is one problem with this approach. We need 128 to specify 128 kbps encoding with default quality, so 0 means use default. Instead of 0 you have to use .01 (or .99) to specify the highest quality (128.01 or 128.99).

LAME uses bitrate to specify a constant bitrate, but higher quality can be achieved using Variable Bit Rate (VBR). VBR quality (really size) is selected using a number from 0 to 9. Use a value of 0 for high quality, larger files, and 9 for smaller files of lower quality. 4 is the default.

In order to squeeze the selection of VBR into the the −C value float we use negative numbers to select VRR. -4.2 would select default VBR encoding (size) with high quality (speed). One special case is 0, which is a valid VBR encoding parameter but not a valid bitrate. Compression value of 0 is always treated as a high quality vbr, as a result both -0.2 and 0.2 are treated as highest quality VBR (size) and high quality (speed).

like image 163
Frank Zalkow Avatar answered Sep 21 '22 12:09

Frank Zalkow