Pages

Sunday, January 30, 2005

Real to MP3

One frequent task I perform is a conversion from Real Audio to MP3. Most of my music content happens to be in real format, but I would prefer to listen to it on my discman, which plays MP3 disks. Hitherto, this required a trial version of StreamBox Ripper, an excellent conversion software, that also supports batch processing.

Now that windows is gone, I had to look for Linux alternatives. I didn't had many hopes, since real-audio is a proprietary format, but I was in for a surprise. Real Networks is paying real attention to the Linux Platform (with a community supported Helix Player, and Free/Closed Real Player). And mplayer does the job of conversion just very well. Here is a shell script that I use to do batch conversions

#!/bin/sh
INPUTFMTS='.ra .rm'

convert() {
for i in `find $1 -name '*'$3`
do
outfile=`basename $i $3`
outdir=`dirname $i`
if [ ! -e $2/$outdir ]; then
mkdir -p $2/$outdir;
fi
mplayer -vo null -vc dummy -af resample=44100 -ao pcm -waveheader $i && lame -m s audiodump.wav -o $2/$outdir/$outfile.mp3
done
}

case $# in
2)break;;
*) echo "Usage: $0 ";
exit 1;;
esac

if [ ! -e $2 ]; then
mkdir $2 || exit 1;
echo "$2: pathname created";
fi

if [ ! -d $2 ]; then
echo "Source directory invalid";
exit 1;
fi

for i in $INPUTFMTS
do
echo "Converting all $i files to mp3"
convert $1 $2 $i
done
rm -f audiodump.wav
-------------------------------------------------------------------------
I guess this script would also work for wma to mp3, you just need to add wma to INPUTFMTS variable.

If I had to write a similar script on Windows , how difficult it would have been. I know this because my last job involved some windows batch scripting and vbscripting. Reminds me of this saying (probably by Larry Wall), about a good programming language

Easy things should be easy, and difficult things should be possible.

Not quite windows.

No comments: