Flac to Mp3 Simplified for Linux.
Well after alot of searching on the internet and not really finding a solution that was suitable to my needs, or having issues with getting Flac tags over to Mp3, i decided to write my own script that would pull the information. Also if you are like me you might want higher quality over smaller file sizes so i have added the option to change the bitrate you encode at.
The script listed below takes arguments in the following fashion. either you can specify a single file name to convert or you can specify a wildcard as example 2 shows.
Example 1: Flac2Mp3 01-The Black Parade.flac
Example 2: Flac2Mp3 *.flac
To use this script just copy and paste the section below and to a filename Flac2Mp3 and the chmod+x Flac2Mp3
If you have any questions please feel free to register and post a comment and i will do my best to answer.
***Update***
make sure that the (lame) package is installed if you using fedora / centos
#!/bin/bash
#########################################################
# Flac to Mp3 Conversion Software #
# Script Created by Nick Sklavenitis
# http://www.sklav.com #
# Date: September 18 2007 #
#########################################################
# modify the lame options to your preference example change -b 320 to -b 128 or -b 192 or -b 256
lame_opts=" --vbr-new -V 2 -b 320 "
# Creates the loop that allows more than 1 file to be specified, Can use single file name or example *.flac
for x in "${@}"
do
FLAC=${x}
MP3=`basename "${FLAC%.flac}.mp3"`
[ -r "$FLAC" ] || { echo can not read file \"$FLAC\" >&1 ; exit 1 ; } ;
#This section pulls the Tag info from flac and stores it as a variable.
TITLE="`metaflac --show-tag=TITLE "$FLAC" | awk -F = '{ printf($2) }'`"
ALBUM="`metaflac --show-tag=ALBUM "$FLAC" | awk -F = '{ printf($2) }'`"
ARTIST="`metaflac --show-tag=ARTIST "$FLAC" | awk -F = '{ printf($2) }'`"
TRACKNUMBER="`metaflac --show-tag=TRACKNUMBER "$FLAC" | awk -F = '{ printf($2) }'`"
GENRE="`metaflac --show-tag=GENRE "$FLAC" | awk -F = '{ printf($2) }'`"
COMMENT="`metaflac --show-tag=COMMENT "$FLAC" | awk -F = '{ printf($2) }'`"
DATE="`metaflac --show-tag=DATE "$FLAC" | awk -F = '{ printf($2) }'`"
#This section handles the conversion of the Flac file to MP3
flac -dc "$FLAC" | lame${lame_opts} \
--tt "$TITLE" \
--tn "$TRACKNUMBER" \
--tg "$GENRE" \
--ty "$DATE" \
--ta "$ARTIST" \
--tl "$ALBUM" \
--add-id3v2 \
- "$MP3"
done
Comments
14 comments postedThank you for that one, desperately needed it for the 12h ride to Berlin tomorrow! ;)
Your post is really awesome man. Thanks for sharing it. You really rock.
Regards,
Aden Jeff
Great right out of the box script.....perfectly redid an entire flac directory without issue.
Great Job~
Neil
i was wishing 4 this kind of thing from a long time :)
it is a great solution not only for me but all of the certifieds like me.
works great
that saved me some time :)
just wanna say thanks :)
I've just uploaded to GitHUB a script which pretty does the same of yours, perhaps you would like to take a look.
http://github.com/tacvbo/yaflac2mp3/tree/master/yaflac2mp3.sh
I tried yours, but it didn't work. I ran id3v2 and it said that there were no id3 tags in the flac files. However easytag shows them.
Nick's script DID work - so it would be interesting to know why his script finds the tags but yours doesn't.
I noticed you did some things differently. Will look more into it and see what i can change on my script. Also does your script work properly when a flac encoded file has the variables in upper/lower case or mixed case? I am always looking to streamline my script.
Yes, it does. The script take care about those variables names in upper/lower/mixed case parsing the complete output of metaflac accordingly, then Artist= or ARTIST= or ArTiSt= (you've got the idea) became artist=, so it always work. :)
And yes, looks quite similar but it got some differences:
* Uses more bash's parameter expansions.
* Works recursively.
* Calls metaflac just once.
* Use arrays to store data.
* Adds -t* option to flac command just if its necessary.
Thanks for posting, regards.
very good articles thank you...
Thanks, for the good articles...I am very intirested
Very complicated article, i don't understand.
This is a step by step how-to article detailing exactly what to do, so i cannot explain any clearer.