Converting thousands of WMA files to MP3

Java
Max Rydahl Andersen

I've been using a Mac Mini for a while now to run my media center but recently I discovered that I actually had more than 8.000 songs in WMA format that iTunes silently ignores when importing.

This blog is about how I managed to get that converted without too much fuzz.

UI Conversion tools

There are many various conversion tools out there for OS X, Switch being one of the better ones but it does not seem to handle massive conversions very well. The Windows version has a command line interface that could be used but its just too much hassle.

If you got small set of files to convert then Switch works fine. Be aware that the latest Flip4Mac might cause problems for Switch, I had to use an older version (2.2.2.3) to make it work.

Because Switch and all other UI's I tried for OS X did not work well for large scale conversions I decided to find a way to do it via a command line. This allows me to easily control it and in case something fails restarting it from where it stopped is much easier than any UI tool.

Converting (non-DRM) files via command line on OS X (excl. Tags)

Note: The following converts the files fine, but tags are not maintained! Just be aware of this limitation! Using LameXP described below seem to copy tags better, but that requires a Windows installation.

For command line conversion under OS X you need Lame+MPlayer installed; I got mine installed by simply using MacPorts:
sudo port install mplayer
You might need to also install Flip4Mac in case there isn't another WMA decoder available.

After installing mplayer, create this shell script which convert a single file, name it convert.sh:
if (test -e "`dirname "$1"`"/"`basename "$1" .wma`.mp3"); then
 #echo mp3 $1 already exists
 test true
 else
 mplayer -vo null -vc dummy -af resample=44100 -ao pcm:waveheader "$1" && lame -m j -h --vbr-new -b 160 audiodump.wav -o "`dirname "$1"`"/"`basename "$1" .wma`.mp3"
 rm -f audiodump.wav
 fi
This script checks if a wma file given as input has a matching mp3 file in the same directory and if it has not it uses mplayer + lame to perform a direct conversion to mp3.

With the convert.sh script in place you can use the following command to convert all .wma files that does not have a matching .mp3:
find . -name "*.wma" -print0 | xargs -0 -n 1 -L 1 -I {} ./convert.sh "{}"
The -print0 and additional arguments to xargs is what ensures filenames with spaces, weird quotes or non-latin characters gets properly quoted.

Then you should see console output for all the conversions and get all your files converted nicely. It took my laptop about 24 hours to churn through my non-DRM WMA files.

In case you bump into a file that cannot be converted then check if the file is actually valid and can play somewhere else (i.e. on a Windows machine or with iTunes with right encodings installed) - if it can play, but Lame will not then it is mostly likely because it is a DRM protected WMA. I had about 2.500 of those (yeah, I forgot to disable DRM when converting parts of my CD collection ;(.

Conversion of DRM protected WMA files (incl. Tags)

There exists many weird applications which doc's state they can "break" the DRM encoding by letting iTunes play them and then record the digital output stream to write them to a virtual ISO image for then to convert them to mp3.

I tried many and most of them simply did not work out of the box or required massive tweaking to actually work but then the conversion took ages plus it was not very fault tolerent.

Therefore I decided to simply startup my Windows 7 virtual machine, Install LameXP and simply let it do all the work.

Again, I had many DRM files that needed conversion (2.500+) and adding them manually would take forever. Once again a little script made it much easier.

Create a file named check.sh with the following content:
if (test -e "`dirname "$1"`"/"`basename "$1" .wma`.mp3"); then
 #echo mp3 $1 already exists
 test true
 else
 echo $1
fi
Then use this script with the following one-liner:
find . -name "*.wma" -print0 | xargs -0 -n 1 -L 1 -I {} ./check.sh "{}" > needconversion.m3
Running this finds all files matching *.wma, passes them to xargs in a way so there won't be problems with quotes, spaces, etc. and then for every single found file calls the check.sh script and writes the result to the file "needconversion.m3u".

All there is left then is to Add the "needconversion.m3u" to LameXP and when it has spent a few minutes on importing it press the Encode button and let it do its business. On my laptop it takes about 10 sec. per file, thus 2.500 files takes about 7 hrs.

Be aware that LameXP as many other conversion UI's does not seem to cope well when you have many thousands files to convert, but it did though a good job with my 2.500 files at once. If someone know a good way to do similar conversion but via command line on windows I would love to hear.

Fixing Tags

To fix broken tags i'm experimenting with using Jaikoz which is a for pay Java app that uses MusicBrainz to match songs by acustic fingerprints. For now it looks to doing a great job of matching up the songs, but if someone knows how to copy tags from 6.000 WMA to their matching mp3 let me know :)