m4a (acc) to mp3

My mp3 player (which has just survived a trip round the washing machine) doesn’t support m4a files so I needed a way to mass convert the audio files. Also the plugin bmp-m4a (beep media player m4a plugin) doesn’t seem to be that stable for me.
Here is the shell script that I wrote to do this. It requires the two programs “faad” and “lame“. For ubuntu users these can be found in the repsitories/synaptics/apt
faad is an ACC decoder/player and lame is an MP3 encoder.

#!/bin/bash
#aac convert mp3
#Michael G D Wood (X3N)
for m4afile in *.m4a
do
echo —- Convert to wav —
echo faad “$m4afile” -o “$m4afile.wav”
faad “$m4afile” -o “$m4afile.wav”
echo — Encode to mp3 —
newfile=`echo $m4afile | sed -e ’s/.m4a//g’`
lame -h “$m4afile.wav” “$newfile.mp3″
echo — Removing wav files —
rm “$m4afile.wav” -f
done

Download: m4atomp3.sh  Simply run this script in the directory of m4a files. e.g. sh /downloaded/to/m4atomp3.sh
Two modifications that you might consider to make life easier:
1) Add “rm $m4afile” -f after the line “rm  “m4afile.wav” -f” [line 13] . This would remove the m4a version of the file, not having this results in you having 2 versions of your files one in mp3 format and one in m4a (the original)
2) Add a outer for loop, ie nest the original for loop. You could do this to make the script go into a set of directories and preform the convertor. e.g. for targetdirectory in $directorylist do cd $targetdirectory .. then the original for loop.
If you need any help/customisations/what ever with this leave me a comment.

2 Responses to “m4a (acc) to mp3”

  1. Neil Greenwood Says:

    The line
    newfile=`echo $m4afile | sed -e ’s/.m4a//g’`
    can be replaced by
    newfile=${m4afile//.m4a/}

    See http://www.raphink.info/string-edition-in-bash-replacements for more info.

  2. admin Says:

    Thanks I was searching for that functionality that makes it neater. Although my sources tell me that using the backticks and sed should make it more portable, as in, works in all implimentations of bourne shell.

Leave a Reply