April 11, 2005

Linux – Converting Audio Files

A few ugly ducklings have crept into the flock. Amongst a herd of MP3s are some OGGs, FLACs and WMVs. How to deal with? How to deal with?
Converting OGG to WAV, WAV to MP3
Converting between MP3, FLAC and WAV
Converting WMA to MP3 (using mplayer)
As always with Linux, the key is in knowing which tool to use for which individual stage. Use lame to encode mp3s, flac to encode/decode flacs to/from wavs, and so forth.
Haven’t yet done the WMAs, due to mplayer availability.

UPDATE: I have now done the WMAs, and I modified the script slightly from the one in the link:


current_directory=$( pwd )

for i in *.wma ; do mplayer -vo null -vc dummy -af resample=44100 -ao pcm -waveheader “$i” && lame -m s -v -V 0 audiodump.wav -o “`basename “$i” .wma`.mp3″; done

rm audiodump.wav

Differences are:
1) The original files are left intact, so if something goes wrong then you haven’t lost all your data. Delete them manually afterwards.
2) I added -v -V 0 so that encoding is done using VBR at highest quality. Because I like it like that.
3) The original version crashed case (turned uppercase letters into lowercase) and changed spaces to underscores. By putting double quotes around the $i, it is no longer necessary to remove the spaces, and the removal of uppercase seemed a bit unnecessary to me in the first place.