Posts Tagged ‘audio’

Converting FLAC to MP3

Friday, April 18th, 2008

I’ve been looking for a decent way to convert FLAC files to MP3 under Linux for a while now. I’d been using SoundConverter, but I notice that there’s something not right with it. I’ll set my preference to VBR, highest quality (target rate is ~256), but I end up with files at around 150-192, which is not right.

So, I’ve done a bunch of searching around and have cobbled together this script, taking a little bit from here and a lot from there:

##START SCRIPT##
#!/bin/sh

for a in *.flac
do
OUTF=`echo "$a" | sed s/"\.flac$"/"\.mp3"/g`

ARTIST=`metaflac "$a" --show-tag=ARTIST | sed s/.*=//g`
TITLE=`metaflac "$a" --show-tag=TITLE | sed s/.*=//g`
ALBUM=`metaflac "$a" --show-tag=ALBUM | sed s/.*=//g`
GENRE=`metaflac "$a" --show-tag=GENRE | sed s/.*=//g`
TRACKNUMBER=`metaflac "$a" --show-tag=TRACKNUMBER | sed s/.*=//g`
DATE=`metaflac "$a" --show-tag=DATE | sed s/.*=//g`

flac -c -d "$a" | lame -V 0 - "$OUTF"
id3v2 -t "$TITLE" -T "$TRACKNUMBER" -a "$ARTIST" -A "$ALBUM" -g "$GENRE" -y "$DATE" "$OUTF"
done

mkdir "$ARTIST" && mkdir "$ARTIST"/"$ALBUM"
mv *.mp3 "$ARTIST"/"$ALBUM"/.
## END SCRIPT##

It works beautifully.