Monday, May 17, 2010

Converting M4A to MP3

Today I started using Songbird on my Linux box. However, for some reason it doesn't want to play .m4a files. I looked into the solutions out there a bit but I didn't find anyhing that seemed to offer a solution. So my solution was to write a quick script to convert my .m4a files into .mp3 files. For this solution, you will need to have 3 programs installed

  • faad2
  • lame
  • id3cp (comes with id3lib)

The script will take any input files you give it, convert them from m4a to mp3 and then copy all of the ID3 tags over to the new file. It then moves the old m4a files to a new subdirectory and changes all the file extensions to mp3.

mkdir old_m4a_files

for i in $@
do
    echo "Converting: ${i%.m4a}.mp3"
    faad -o - "$i" | lame - "${i%.m4a}.mp3"
    id3cp "$i" "{$i%.m4a}.mp3"
    mv "$i" "old_m4a_files/$i"
done