Recording RealAudio to MP3

Colin | music | Saturday, January 13th, 2007

Recently I’ve gone back to listening to a lot of online streams, mostly DJ mixes. A lot of these are in RealAudio, which is fine for listening to on the computer, but no good for transferring to my iPod or my Squeezebox. The best thing to do is still convert everything to MP3. The preferred tool for MP3 encoding of course is LAME, and the best audio conversion tool is MPlayer. I installed both on my OS X box using the excellent MacPorts (formerly known as DarwinPorts), it should be equally trivial on any reasonable unixy system. So, I know this is something that’s been done to death on the net, but I couldn’t find one post that told me everything I needed to know to do the conversion. So, as much for my own documentation as anything, here’s my script (based on one I found here):

#! /bin/bash
#
# Converts a Real Audio file to MP3 and adds an ID3 tag.
#
# Usage: ra2mp3 infile outfile
#
 
if [ -z $1 ] || [ -z $2 ]
then
  echo "Usage: $0 infile.rm outfile.mp3"
  exit 0
fi
 
author=`mplayer "$1" -vo null -ss 10:00:00 | grep author | sed -e 's/.*:\\s*\\(.*\\)/\\1/'`
title=`mplayer "$1" -vo null -ss 10:00:00 | grep name | sed -e 's/.*:\\s*\\(.*\\)/\\1/'`
 
if [ -z $author ]
then
  echo "Author:"
  read author
fi
 
if [ -z $title ]
then
  echo "Title:"
  read title
fi
 
mkfifo /tmp/stream.wav
mplayer "$1" -ao pcm:file=/tmp/stream.wav -vc null -vo null &
lame /tmp/stream.wav "$2" --tt "$title" --ta "$author" --preset standard
rm /tmp/stream.wav

A quick run-through: the script first checks that it’s been given the correct parameters, then it attempts to read the author and title from the RealAudio file. If it can’t find these, the user is prompted. Then MPlayer is used to dump the RealPlayer file to a PCM WAV file (i.e. just raw audio) then LAME is used to create the MP3. Since these intermediate WAV files can be pretty big, we use a trick: mkfifo /tmp/stream.wav is used to create a named pipe. MPlayer is then told to write to the pipe, and will block until something starts reading from it. LAME is then configured to read from the pipe, and the upshot is that all the data will go directly from MPlayer to LAME with no intermediate file. Neat.

Once again…

Colin | general | Sunday, January 7th, 2007

Yesterday was not a good computer day.

First I tried to update my account that I had hosted with Bytemark, resulting in a database crash that took all afternoon until I realised that I wasn’t going to be able to recover it. Then I opened a new account with Dreamhost, and wrote a long post about my switching experience, which I lost when my computer crashed.

Anyway, here it is, once again. Hopefully I’ll update it more this time!

P.S. my switch should not be taken as any criticism of Bytemark, they offer an excellent service. It’s just that right now I want something easy, not flexible, and Dreamhost does that better.

Powered by WordPress | Theme by Roy Tanck | RSS | Comments | Valid XHTML | Valid CSS