Converting Music: m4a files to mp3

Today I was trying to help a friend with some audio files. Her collection was quite large and needed to be converted from MPEG-4 format (.m4a) to MPEG-3 format (.mp3).

I wanted to maintain wanted preserve directory structure of her collection and make sure that I did not damage the original m4a file. In my friend’s collection each artist had its own directory and each album had its own directory within the artist directory. I suspect this is a typical layout for a digital music collection.

I could not find a Linux utility that would let me convert directly from m4a to mp3. But, I did find a couple of utilities that together would do the trick; faad and lame.

Using these utilities together I could convert the files from first from m4a to wav and then from wav to mp3.

A note of caution is the collection is large make sure you have enough room as this procedure will triple (or more) the amount of space used by the collection you are trying to convert.

1. Install faad and lame using apt-get:

apt-get install faad lame

2. Copy the collection to a directory on your Linux computer (e.g. /tmp/MusicCollection)

3. Create a 2 line bash script:

faad -o – “$1” | lame -h -b 192 – “${1%m4a}mp3”

My script is in a file called cvrt. After entering these two lines into this file save the file in your /tmp/MusicCollection directory and make the file executable:

chmod +x cvrt

What the script does is reads the name of a file, converts it to wav format useing ‘faad’ and feed this stream of data into the ‘lame’ program which converts the file to mp3 format. The file also creates the new file with the same file name except it changes the extention to mp3.

4. Use the cvrt script we just created in combination with the find command:

find /tmp/MusicCollection -name *.m4a -exec /tmp/MusicCollection/cvrt ‘{}’ ‘;’

This command will search the MusicCollection directory and all its sub-directories and feed each m4a file it finds into the cvrt script we just created, which will do all the conversion for us.

My friends collection was quite large and this process did take some time. However, the machine used to perform the conversion was not very fast. Your mileage may vary.