Princess Cornflakes

Too trashy to print on a cereal box

Archive for May 2010

use lame to convert directory of .wav files to .mp3

with one comment

If you use Ubuntu (or any other distribution of Linux) it can be surprisingly hard to convert a whole directory of .wav files to .mp3.

There is a utility called “lame” which works pretty well converting a single .wav file, i.e.:

lame filename

but who wants to sit there typing “lame” over and over again?

Oh sure, you could convert all the files using “find -exec” like this:

find . -name "*wav" -exec lame {} \;

But then you will find out how “lame” lame truly is! It leaves the “.wav” file endings, attaches a “.mp3” to them and this:

White Line 11-10-76.wav

becomes this:

White Line 11-10-76.wav.mp3

So you’d have to go through each file individually and remove the “.wav” ending as well as the spaces in the filenames!

Here is a better way. Though not perfect, it works. Each of these commands will execute on all files in the directory, so you only have to run each command once.

1. remove the spaces from the filenames:
find -type f -exec rename 'y/\ /\_/' {} \;

2. and get rid of the .wav from filenames*:
for file in *.wav ; do mv $file `echo $file | sed 's/\(.*\).wav/\1/'` ; done

3. Now run lame on the batch
find . -type f -exec lame -b 224 {} \;

Enjoy your .mp3 files!

* Step 2 is a little weird. After this step you are going to end up with files that have no file endings, but lame seems to recognize these as “.wav” files.

Advertisements

Written by nattie

May 29, 2010 at 2:01 pm

Posted in Uncategorized