Tuesday, August 30, 2011

How to: Compress mp3 files in Linux

I was presented with a big problem. Covert 3.5gb of mp3 format files to fit into a space of 354mb! It could be done albeit a lot of time but I never done it in Linux. Also I knew that there would be a huge loss of quality in the compressed files so I have to choose and optimum and the required 354mb was not realistic. Which wasn't a huge problem, actually as long as I could get the file size down to less than a 1gb. So to Internet it was to do some research on the topic.

After reading several sites pertaining to the matter I was presented with two solutions. Lowering the bit rate of the files and re sampling the files. After a little bit more researching I found few contenders to the job that I had in hand.






1. Audacity
Audacity was a little bit complicated and full of features that I really did not need for the job. And I couldn't figure out how to do multiple files in one go (though I'm sure that feature is nevertheless there) So after a while of playing around with it I thought there would be a better tool for the job. What caught my attention most was that Audacity itself uses a smaller program to do the compression called Lame. As it turned out Lame was what I was looking for.


2- Sound converter.
This is the tool for the job! It's simple and easy, just add files and convert to your preferences. It's a sound converter, not just a compressor and to get it to output mp3 files you would need to go to the preferences dialogue and set the output as mp3. It can change the bit rate and re sample at the same time for multiple files. Just what I needed! However it wasn't the tool for the day. When I set the quality of output file to very low, I discovered that the lowest bit rate I could achieve is 64kbits which isn't low enough for my job. The creators of the tool could have put in 'insanely low' as an option like 'insanely high' option already available for the quality. On another day this tool would have been perfect. So my search goes on

Sound converter with my files needing compression

The preference dialogue. The 64kbit lower limit can be seen in this screenshot

3. Lame
Don't let the name fool you. This command line tool is just what I wanted. The only downside for the tool is that the processed files lose their ID3 tags so these files wont show up well on an mp3 player. There are work around for this problem but ID3 tags weren't of importance to me.

To change the bit rate to 24 the command is
lame --mp3input -b 24  < infile> < outfile>

To re sample the  file at 44.1Khz command is
lame --vbr-new --resample 44.1 < infile> < outfile>


To change bit rate for all mp3 files in a folder and putting the output files to a folder called 'compressed' the command is
for file in *.mp3; do lame --mp3input -b 24 "$file" "compressed/$file"; done

To resample all mp3 files in a folder and putting the output files to a folder called 'resampled' the command is
for file in *.mp3; do lame --vbr-new --resample 44.1 "$file" "resampled/$file"; done

After all my work was finished the file size was reduced to 747mb! That's down from 3.8gb. Not bad! Not bad at all. As seen in the screenshots this little tool is very nifty, shows a lot of information about what is happening during the compression and re sampling process


Re sampling

Compressing

Files needing compressing and re sampling
Progress. Two files completed

Finished. File size comparison

Humbly brought to you by Storm of Mort

0 comments:

Post a Comment