Convert a flac file into an mp3 file

Reading Time: < 1 minuteOn 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

Reading Time: < 1 minute

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

By Marc Olivier Meunier

Marc has spent the past few years putting oil on the fire of a hyper growth ad tech company. At Smartly.io he was in charge of scaling the support and its culture. At Eficode he is now leading an engineering team and running operations. He leads by example and puts a lot of emphasis on diversity and inclusion, constantly working to create a safe environment. A warm leader with a passion for memorable experiences and innovation.
Find Marc on Linkedin

Leave a Reply

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