20110902

Using Lame to convert a set of WAV files to MP3

While cleaning up my temp directory today, I stumbled across some old .wav files from a CD I had ripped a couple of months earlier. I don't know why I didn't originally rip them to MP3 since I was using EAC, but I needed to free up space. I already owned the CD, and didn't want to have the uncompressed audio files taking up space on my laptop.

Machine: Windows XP SP3
Issue: Need to convert several WAV files to MP3
Gripes: Don't want to do it one-at-a-time, or use a GUI; must be "scriptable."
Tool of choice: Lame, for /f

Command:

for /f "usebackq delims=" %g in (`dir /b d:\drop\aud\*.wav`) do @%programfiles%\lame\lame.exe -b 192 -h "d:\drop\aud\%g" "d:\dl\aud\%g.mp3"

Notes:
  • Use this raw when copying directly to prompt. If putting in a .bat or .cmd file, remember to change all instances of %g to %%g.
  • Also, the quotes immediately inside the parentheses are backquotes, usually on the same key as your tilde (~) character in the upper left-hand corner of your keyboard.

Other Gripes:
  • This is obviously very rudimentary, as it doesn't strip the .wav off the end first; it just creates a .wav.mp3 file which you would then have to rename.
  • If you want to script that out, you could do so as follows:
    set originalFile=%%g:.wav=%
    That searches the %g iterative variable for the .wav and strips it off, assigning the result to originalFile.

My blog doesn't currently get much traffic, but if there's any interest later, I'll add a full script to do this.

No comments: