Script: M4A to MP3

Status
Not open for further replies.

Greg

Indeed.
Messages
1,600
It always annoys me to have to convert M4As for use on my MP3 player, etc., so I've created this BASH script to convert any M4As in a directory to MP3 all at once.

I kinda stole some of the the middle part with all the sed junk from somewhere on the internet, and I'd give him credit, but I don't remember where I got it from :umm:

To use it you need faad and lame.

Code:
#!/bin/bash
mkdir "MP3"
for file in *.m4a; do
faad -o "MP3/temp.wav" "$file"
faad -i "$file" 2>MP3/tags.txt
title=`grep 'title: ' MP3/tags.txt|sed -e 's/title: //'`
artist=`grep 'artist: ' MP3/tags.txt|sed -e 's/artist: //'`
album=`grep 'album: ' MP3/tags.txt|sed -e 's/album: //'`
genre=`grep 'genre: ' MP3/tags.txt|sed -e 's/genre: //'`
track=`grep 'track: ' MP3/tags.txt|sed -e 's/track: //'`
year=`grep 'year: ' MP3/tags.txt|sed -e 's/year: //'`
lame -h -b 192 --tt "$title" --ta "$artist" --tl "$album" --tn "$track" --ty "$year" "MP3/temp.wav" "MP3/$file".mp3
rm "MP3/temp.wav"
rm MP3/tags.txt
mv "MP3/$file".mp3 "MP3/$artist - $title".mp3
done
To use it just place it in /usr/bin/, navigate to your desired directory, and run it. It will create a separate folder named "MP3" for all of the MP3s, and will leave your original M4As alone. If you don't like how it names them then just edit line 15, you can figure it out. If your M4As don't have proper tags and it is screwing up the filenames, then comment out line 15 and the end result will probably be something like "originalfilename.m4a.mp3"

I posted this because I hate seeing the Linux section dead for so long :happy:
 
Very nice. I would be quite interested in the opposite conversion though. I would like to convert some audiobooks to m4a format for my iPod. I have tried one script from the Ubuntu forums with no luck.
 
If you can figure out how to encode an M4A file then let me know, the script would be fairly easy to modify.

To get the MP3 to WAV format, the following will work:
Code:
mpg123 -w file.wav file.mp3
but I have no idea how to get it to M4A.
 
Oh wow, looks like this is a little more complicated than just converting it to an M4A. I don't have an iPod, but if you need help getting that script working feel free to start a thread and I will try to help out.
 
Status
Not open for further replies.
Back
Top Bottom