Ok so here is what I have done to convert a mp3 to m4a to make it play on my iPhone through linux. For starter, we want to convert it to a wav file so that there is no loss in quality. I read that if you convert from mp3 to m4a directly you are bound to loose some quality which makes sense. Mp3 and m4a are compressed files after all. Here are all the files that you will need.
Linux (… duh.)
Mplayer
Faac
mp3info
mp3splt
Here is the basic conversion from mp3 to wav using mplayer.
mplayer -ao pcm testing.mp3 -ao pcm:file="testing.wav"
And then I put the wav file in faac and gave it some tag.
faac testing.wav -o sleeping.m4a -w --title Test --album Test
There you go. They are some really nice commands for faac which could be nice to pass to from a script. Hum… So here is a script that will cut to the first 40 seconds and convert an mp3 to a m4a while keeping the tags for that track. It’s a bit dirty but eh, it’s free and useful (to me anyway).
lightx@HIGH:~/bin$ cat mp3tom4a.sh
#!/bin/bash
name=$(basename $0)
#
#did you pass any command?
#
if [ -z "$1" ]
then
echo “Usage: $name trackname.mp3″
exit 1
fi
#
#keep the mp3 ID3 tag information and put it in /tmp
#
mp3info -p “File:%f\nTitle:%t\nArtist:%a\nAlbum:%l\nTrack:%n\n” $1 > /tmp/mp3scan.txt
trackname=$(cat /tmp/mp3scan.txt | grep File | cut -d”:” -f 2 | cut -d”.” -f1)
title=$(cat /tmp/mp3scan.txt | grep Title | cut -d”:” -f 2)
artist=$(cat /tmp/mp3scan.txt | grep Artist | cut -d”:” -f 2)
album=$(cat /tmp/mp3scan.txt | grep Album | cut -d”:” -f 2)
track=$(cat /tmp/mp3scan.txt | grep Track | cut -d”:” -f 2)
#
#split the first 40 second
mp3splt $1 0.0 0.40 -o out.mp3
#
#convert to wav
mplayer -ao pcm out.mp3 -ao pcm:file=”out.wav”
#
#encoding to m4a
faac out.wav -w –artist “$artist” –title “$title” –album “$album” –track “$track” -o $trackname.m4a
#
#cleaning up
rm out.wav out.mp3
Dirty indeed, but I like it. I could expend this little bash script to have a second and third option which would be to cut from X time to Y time. Shouldnt be that hard to implement but I don’t feel like doing it right now anyways. The 40 second limit is because of my iPhone. Apparently you can only use 40.04 sec not 40.05 via Rogue Software.
1. Actually, ringtone files (currently) have a hard ceiling of exactly 40.04 seconds. MakeiPhoneRingtone will pass off files of any length, but the Ringtones tab in the iPhone area of iTunes won’t show files longer than 40.04 seconds. I used Fission to determine exact file lengths. 40.04 works, and 40.05 doesn’t. Bizarre, but true. ↩
2 Comments
“For starter, we want to convert it to a wav file so that there is no loss in quality. I read that if you convert from mp3 to m4a directly you are bound to loose some quality which makes sense. Mp3 and m4a are compressed files after all.”
Just because you decompress the mp3, the resulting wav doesn’t have the quality there was before (otherwise the audio player could also recover it). There is not point at all in having an intermediate wav, except if you don’t have a direct mp3 to m4a converter.
Just use soundkonverter
More easy imposible.