Convert WAV to MP3 in command line with LAME on Linux

Friday, 8th April 2011

I needed to convert a bunch of files from WAV to MP3 format on my Linux desktop.

I’ve placed all my wav files to the directory /home/hipo/wav

And then I issued the small one liner script to convert the .wav files to .mp3 using the niftly lame linux mp3 convertor.

Here is how I did it:

linux-desktop:~$ cd wav
linux-desktop:/home/hipo/wav$ for i in *.wav; do
new_name=$(echo $i |sed -e 's#wav#mp3#g');
lame -V0 -h -b 160 --vbr-new "$i" "$new_name";
done

After executing the little script you might go and have a coffee, if you have thousands of files, each file convertion takes about 10-15 seconds of time (speed depends on your CPU).

Here is some output from a lame convertion to mp3 taking place:

Encoding as 8 kHz single-ch MPEG-2.5 Layer III VBR(q=0)
Frame | CPU time/estim | REAL time/estim | play/CPU | ETA
27237/27237 (100%)| 0:12/ 0:12| 0:12/ 0:12| 155.89x| 0:00
64 [27237] ***************************************************************
----------------------------------------------
kbps mono % long switch short %
64.0 100.0 84.1 8.9 7.0
If you want to save my convertion quickly for a later, download my Convert WAV to mp3 from a directory with lame shell script here

Actually there are plenty of other ways to convert wav to mp3 on Linux through mplayer, ffmpeg even with mpg123.

There are also some GUI programs that could do the convertion like winff , however for some weird reason after installing WinFF on my debian it was not able to complete convertion to mp3?!
But it doesn’t matter, the good news is I did what I wanted to via the simple lame program and the above script, hope it helps somebody out there.

Share this on:

Download PDFDownload PDF

Tags: , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , ,

8 Responses to “Convert WAV to MP3 in command line with LAME on Linux”

  1. admin says:
    Epiphany 2.30.6 Epiphany 2.30.6 Debian GNU/Linux x64 Debian GNU/Linux x64
    Mozilla/5.0 (X11; U; Linux x86_64; en-us) AppleWebKit/531.2+ (KHTML, like Gecko) Version/5.0 Safari/531.2+ Debian/squeeze (2.30.6-1) Epiphany/2.30.6

    Just in case if you’re interested here is what the lame options means:

    -V n 0 <= n <= 9 Enable VBR (Variable BitRate) and specifies the value of VBR quality (default = 4). 0 = highest quality. -h
    Use some quality improvements. Encoding will be slower, but the result will be of higher quality. The behaviour is the same as the -q 2 switch. This switch is always enabled when using VBR.

    -b n
    For MPEG1 (sampling frequencies of 32, 44.1 and 48 kHz) n = 32, 40, 48, 56, 64, 80, 96, 112, 128, 160, 192, 224, 256, 320
    For MPEG2 (sampling frequencies of 16, 22.05 and 24 kHz) n = 8, 16, 24, 32, 40, 48, 56, 64, 80, 96, 112, 128, 144, 160
    Default is 128 for MPEG1 and 64 for MPEG2.

    –vbr-new
    Invokes the newest VBR algorithm. During the development of version 3.90, considerable tuning was done on this algorithm, and it is now considered to be on par with the original –vbr-old. It has the added advantage of being very fast (over twice as fast as –vbr-old).

    View CommentView Comment
  2. Kirm says:
    Firefox 8.0 Firefox 8.0 GNU/Linux x64 GNU/Linux x64
    Mozilla/5.0 (X11; Linux x86_64; rv:8.0) Gecko/20100101 Firefox/8.0

    Nice script and great idea. Gui app not required!

    Thanks.

    View CommentView Comment
  3. cool_kau says:
    Google Chrome 15.0.874.121 Google Chrome 15.0.874.121 GNU/Linux GNU/Linux
    Mozilla/5.0 (X11; Linux i686) AppleWebKit/535.2 (KHTML, like Gecko) Chrome/15.0.874.121 Safari/535.2

    Thanks .. that was of great help ..

    View CommentView Comment
  4. PhilGP says:
    Google Chrome 20.0.1132.57 Google Chrome 20.0.1132.57 Windows XP Windows XP
    Mozilla/5.0 (Windows NT 5.1) AppleWebKit/536.11 (KHTML, like Gecko) Chrome/20.0.1132.57 Safari/536.11

    Depending on lame’s defaults this could also work,

    find . -exec lame {} \;

    View CommentView Comment
  5. tolengo78 says:
    Google Chrome 23.0.1271.64 Google Chrome 23.0.1271.64 GNU/Linux x64 GNU/Linux x64
    Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.11 (KHTML, like Gecko) Chrome/23.0.1271.64 Safari/537.11

    Thanks! Beautiful script!

    View CommentView Comment
  6. Françoise Labelle says:
    Firefox 18.0 Firefox 18.0 Ubuntu x64 Ubuntu x64
    Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:18.0) Gecko/20100101 Firefox/18.0

    Great !!!

    View CommentView Comment
  7. GrouchyGaijin says:
    Firefox 33.0 Firefox 33.0 Ubuntu x64 Ubuntu x64
    Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:33.0) Gecko/20100101 Firefox/33.0

    Thanks!

    I needed to pull 57 tracks off a CD and send selected tracks to a student.  The script was a time saver.

    View CommentView Comment

Leave a Reply

CommentLuv badge