How to convert FLAC to MP3 (bash script)

Here what I wrote for convert my FLAC library to MP3 from my UBUNTU workstation.

#!/bin/bash
# need gstreamer with flac and lame plugins

if [ -z "$1" ] || [ -z "$2"]
then
echo "USAGE: flac2mp3 [Input Dir] [output Dir]"
exit
fi

INPUT_DIR="$1*.flac"
OUT_DIR="$2"
[ ! -d ${OUT_DIR} ] && mkdir -p ${OUT_DIR}

for x in $INPUT_DIR
do

FLAC=$x
MP3=`basename "${FLAC%.flac}.mp3"`

[ -r "$FLAC" ] || { echo can not read file "$FLAC" >&1 ; exit 1 ; } ;

echo "Converting ${FLAC} to MP3 format"

gst-launch-0.10 filesrc location="$FLAC" ! flacdec ! audioconvert ! lame vbr=0 bitrate=320 ! id3mux name=tag ! filesink location=${OUT_DIR}/"$MP3"

done
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s