This blog has moved! Redirecting...
You should be automatically redirected. If not, visit and update your bookmarks.

Friday, June 06, 2008

Re-encoding MP3 Files using LAME

I have some MP3 files encoded at a constant bitrate of 320kbps that my phone seems to have trouble playing smoothly. So, I looked into LAME.

The files I had were named using the following scheme:

01 - Title of track 01.mp3
02 - Title of track 02.mp3

I used the BASH for-loop construct to process the files:

$ for A in *.mp3;\ # Process one mp3 at a time
do B=${A%.mp3};\ # Extract track number and title
C=${B#?? -};\ # Extract the title
D=${B%% - *};\ # Extract the track number
lame --vbr-new -V0 -q0\ # Variable-bitrate, high-quality
--mp3input\ # Inputs are MP3 files
--tt "$C"\ # ID3v2 tags: title
--ta 'Artist Name'\ # ID3v2 tags: artist
--tl 'Album Title'\ # ID3v2 tags: album
--ty 2007\ # ID3v2 tags: year
--tn "$D"\ # ID3v2 tags: track no.
--tg 'GENRE'\ # ID3v2 tags: genre
"$A" processed/"$A";\ # Keep filename and save in ./processed/

Since no bit-rate bounds are explicitly provided, the re-encoded files can contain anything between 32kbps and 320kbps. The LAME man-page provides an extensive list of options and their meanings.