Saturday, May 14, 2005

How do you convert a bunch of wave files into mp3 using lame on linux

I had a bunch of files with names like:
The Last Stand of the Tin Can Sailors - D07T01.wav

Using a simple for loop in shell would not suffice. I found that the readdir() function in perl would not expand (breakup) the filename like the shell would so I devised a simple little perl script that would be run under the directory where you the wave files.

#!/usr/bin/perl
endir(DH,".");
@files = readdir(DH);
$lame = "the_path_to_lame";
foreach $file (@files) {
next if($file eq "." || $file eq "..");
$mp3 = $file;
$mp3 =~ s/(.*)\.wav/$1/;
system("$lame --preset cbr 128 \"$file\" \"$mp3.mp3\" ");
}

0 Comments:

Post a Comment

<< Home