Linux Penguin

Solution: Converting flac to mp3

Sometimes you need to convert a load of flac files to mp3’s, for example when wanting to listen them on your mp3 player. This solution contains a single line of bash that’ll convert all flac files in the current directory to mp3’s, keeping the flac files.

Attention: this post now has an advanced counterpart providing a nice script. See Solution: Converting flac to mp3 advanced (supports drag ‘n drop).

Note that you will need flac and lame for this to work. Run the following line in the directory where the flac files are:

[rechosen@localhost ~]$ for file in *.flac; do flac -cd “$file” | lame -h – “${file%.flac}.mp3”; done

This will output the mp3 files in the same directory as the flac files. If any of the mp3 files that’s being created already exists, it will be overwritten. When the conversion has finished, you can copy the mp3 files to an other location like this:

[rechosen@localhost ~]$ cp *.mp3 /media/sda1

Note that this will copy all mp3 files in the current directory, not just the ones converted from the flac files! Of course, you could replace “/media/sda1” with any other directory. You could also replace “cp” by “mv” to move the mp3 files instead of copying them.

You can also make lame create the mp3 files somewhere else. Take the following line:

[rechosen@localhost ~]$ for file in *.flac; do flac -cd “$file” | lame -h – YOURLOCATION/”${file%.flac}.mp3″; done

And replace YOURLOCATION with the location you want the mp3 files to be created in. For example:

[rechosen@localhost ~]$ for file in *.flac; do $(flac -cd “$file” | lame -h – /tmp/”${file%.flac}.mp3″); done

The above line would output the mp3’s in the /tmp directory.

One thought on “Solution: Converting flac to mp3

  1. I use find to do a similar conversion. This converts all flac files in the current directory to ogg vorbis at quality 7:
    $ find . -name “*flac” -exec oggenc -q 7 {} ;

Leave a Reply

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