March 25, 2010

Lossless 2 mp3

#!/bin/bash

#echo name of script is $0
#echo first argument is $1
#echo second argument is $2
#echo seventeenth argument is $17
#echo number of arguments is $#

if [ $# != 3 ]
then
  echo "Error: Wrong number of arguments"
  echo "Usage: `basename $0` music_file cue_file format"
  exit 1
fi

musicfile=$1
cuefile=$2
format=$3

here=`pwd`

ln -s "$musicfile" "${here}/input.${format}"
ln -s "$cuefile" "${here}/output.cue"


ffmpeg -i ./input.${format} ./output.wav

cuebreakpoints output.cue | shnsplit -t "%n" ./output.wav

rm -f ./output.wav

for i in ./*.wav ; do
lame -h -m s -b 192 "$i"
done

rm -f ./*.wav
rm -f input.${format}
rm -f output.cue