Home > Music > Convert your MP3 bitrates via terminal

Convert your MP3 bitrates via terminal

Image courtesy of technabob.

I just had my machine reformatted for a new Ubuntu version and I spent hours the other night reorganizing my files.  I realized that among the ones taking up most of my disk space are my MP3 files.

MP3 is a lossy audio compression scheme, but you can actually take the option to reduce its bitrate (say for your small capacity MP3 player) without losing much of the quality.  Some music files are at 320kbps, but the standard rate is 128kbps.  You will realize that a file has a high bitrate if the size is too large for the song length.

You can calculate the size of an MP3 file using this:

z = (x * y) / 8

x = length of song (in seconds)
y = bitrate (in kilobits per second)
z = resultant file size (in kilobytes) – dividing by 8 gives the result in bytes

So let’s say you have an MP3 of length 3 minutes = 180 seconds.  At 128kbps, your file will be as big as:

z = (180*128)/8 = 2880kb = 2.880Mb

Compared to when you have it at 320kbps:

z = (180*320)/8 = 7200kb = 7.200Mb

Now that’s significant difference when you have thousands of MP3s in your disk.  Most people take the option to convert their MP3 files using a software (e.g. SoundConverter, another FOSS app).  But if you would like to keep things light on your machine, you would wish instead to install the library LAME (a recursive acronym meaning LAME Ain’t an MP3 Encoder).  For more information on this package, run: man lame.

So how does it work? To do the bitrate conversion, run on the terminal (as root):

 lame --mp3input -b <bitrate> <file.mp3> <destination.mp3> 

where the bitrate could range from 8 – 320, depending on your need.

If you have more than a handful of MP3 files, you can automate the conversion using the following shell script:

 for f in *.mp3 ; do lame --mp3input -b <bitrate> "$f" <path_to_destination>/"$f" ; done 

Note that leaving the destination parameter as null saves the file in the form file.mp3.mp3 while setting this parameter to your player’s location causes your file to land there.

[1] Wikipedia, 2010. MP3.
[2] Jhollington, 2004. kbps ?. iLounge Forums.
[3] Ubuntu Packages, 2010. Package: lame.
[4] Ubuntu Development Team, 2010. “lame” package. Launchpad.
[5] Vanadium, 2007. Convert MP3 bitrate. Ubuntu Forums.

  1. humayun shahid
    November 24, 2010 at 7:36 pm

    I am actually commenting here to find out how can i contact you ? your email please?

  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: