Convert a flac file into an mp3 file

Convert a flac file into an mp3 file

On Ubuntu, install flac.

#apt-get install flac lame

Put the following script in /usr/bin/ and give it a name (convert_flac.sh or flac2mp3.sh)

#!/bin/bash  
FLAC=$1
MP3="${FLAC%.flac}.mp3"
[ -r "$FLAC" ] || { echo can not read file \"$FLAC\" >&1 ; exit 1 ; } ;
metaflac --export-tags-to=- "$FLAC" | sed 's/=\(.*\)/="\1"/' >tmp.tmp
cat tmp.tmp
. ./tmp.tmp
rm tmp.tmp
flac -dc "$FLAC" | lame --tt "$TITLE" \
--tn "$TrackNumber" \
--tg "$GENRE" \
--ty "$Date" \
--tc "$COMMENT" \
--ta "$ARTIST" \
--tl "$ALBUM" \
--add-id3v2 \
- "$MP3"

change the execution bit

$ chmod 755 /usr/bin/convert_flac.sh

You can run it in a loop

for i in *.flac
do
convert_flac.sh $i
done

Leave a Reply

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