Blog of Leonid Mamchenkov

You just stepped in a pile of posts.

Converting FLAC to MP3 on Linux

Posted in All on February 11th, 2005 · 4 Comments

FLAC is Free Lossless Audio Codec. A 35 megabyte WAV file converted to FLAC will occupy about 25 megabytes. This is a good decrease in size, considering the fact that no quality is lost. But some files aren’t all about quality and thus will be much better in mp3 or even ogg. Converting these is really simple. The key to the convertion is to decode flac files back to wav and than to convert them to whatever else is that you want.

Here is an example script to convert a bunch of flac files in the directory to mp3s.

for FILE in *.flac
do
 echo Converting $FILE
 # Decode FLAC back to WAV
 /usr/bin/flac -d "$FILE"
 # Save the filename without extension
 BASE=`basename "$FILE" .flac`
 # Convert resulting WAV to MP3 with variable bitrate preserving good quality
 /usr/bin/lame -h -V 2 "$BASE".wav "$BASE".mp3
done

/usr/bin/flac utility is a part of Fedora Linux distribution. /usr/bin/lame is a part of LAME project. RPMs for Fedora Linux are available from a number of repositories, such as FreshRPMs.

Tags:

4 responses so far ↓

  • 1 JP // Feb 21, 2005 at 11:51 pm

    just what I was looking for, works great. thanks!

  • 2 Leonid Mamchenkov // Feb 22, 2005 at 1:50 am

    [1] welcome. :)

  • 3 Matt Clare // Mar 6, 2005 at 1:40 am

    [1] Great script, as I use ctorrent to task my home Gentoo server with downloading live recordings. But for iTunes streaming and for my iPod, flac just won’t due. I should learn a little more about Bash scripting.

  • 4 Octavio Ruiz // Jun 13, 2008 at 4:32 pm

    Perhaps you will be interested in this script,

    http://github.com/tacvbo/...tr.....lac2mp3.sh

    Pretty does the same as yours, works recursively, preserves extra information and store it as ID3v2 into the mp3 file.

Leave a Comment

Note: This post is over 3 years old. You may want to check later in this blog to see if there is new information relevant to your comment.