Convert flac to mp3 on the ubuntu command line

Hi again, The flac format is great. Though huge and not always supported by some MP3 players. Here is a quick way of converting flac to mp3. First lets download the required software:

sudo apt-get install flac lame

It works also on MAC, but you need to use brew install instead.

Then cd into the folder of origin and do this:

for f in *.flac; do flac -cd "$f" | lame -b 320 - "${f%.*}".mp3; done

So what does it mean? Well, the for is for recursively go through the current folder and get the flac files one by one

-c (flac) Write to stdout
-d (flac) Decode file 
-b (lame) The bitrate to use when saving as mp3
(lame) In this case it means read data from stdin

 

Though if you convert files regularly a script or alias might be to consider. With this alias you just cd into the folder and type flac2mp3.

alias flac2mp3='for f in *.flac; do flac -cd "$f" | lame -b 320 - "${f%.*}".mp3; done'

 

Cheers
/jima

Leave a Reply

Your email address will not be published. Required fields are marked *