Prerequisites:
Before beginning, you will probably want to have some basic understanding of the command line, namely, how to copy files, use sudo, and set paths. You will also need to have LAME installed, and it should be in your path. This tutorial will not go into basic shell usage.
This hint builds off of this older hint, by correcting some mistakes, and attempting to automate the process a bit. You will need to obtain the newest mplayer and mencoder binaries from the mplayerosx page; the latest version is preferred. Secondly, if you do not have it already, you will need to download the free version of Real Player. Alternatively, if you do not want to download Real Player, the necessary codecs for this project can be obtained from the Helix DNA Producer program. If you choose to go this route, obtain the latest stable OS X releases.
Putting Everything Together:
After obtaining the necessary items, you will want to move the mencoder and mplayer binaries to a location in your path; /usr/local/bin is probably the best candidate. However, you may need to manually add it to your path, and also create the directory. To do this, use pico (or your favorite text editor) to create a file called .profile and place it in your home directory. It should contain the following line:
export PATH=$PATH:/usr/local/bin
After doing this, you will want to also ensure that LAME is in your path. If typing lame while in your home directory does not start LAME, then it is not in your path.
The next step is create a symbolic link to Real Player's codecs, so that mplayer can utilize them. While the previous hint suggests these are stored in /usr/local/lib/mplayer, this has changed in recent versions of mplayer. Assuming you have chosen to use the codecs included with Real Player, and have installed Real Player in your applications folder, create a link to them with the command below. Take note that you may need to create a folder labeled ffmpegX in /Library/Application Support before linking the codecs:
ln -s /Applications/RealPlayer.app/Contents/Frameworks/HXClientKit.framework/HelixPlugins/Codecs \
/Library/Application\ Support/ffmpegX/reallib
If you decided to use the codecs from Helix DNA Producer, create a folder under /Library/Application Support/ffmpegX labeled reallib, and copy the contents of the 'codecs' folder to that directory.
Automating the Process:
At this point, one could use mplayer to convert a Real Audio file to WAV, and then use LAME to encode it. However, this requires calling both apps with a series of flags and parameters that are too annoying to memorize. Instead, create a file named ra2mp3 using a text editor of your choice, and paste the following code inside it:
#! /bin/bash
#
# Converts a Real Audio file to a mono MP3 and adds an ID3 tag.
#
# Usage: ra2mp3 infile [outfile]
#
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/'`
mplayer "$1" -ao pcm -aofile "$1".wav -vc dummy -vo null
lame -m m "$1".wav "$2" --tt "$title" --ta "$author"
rm "$1".wav
To use this script, you will need to copy it to somewhere in your path; again, /usr/local/bin is a good choice. It can then be evoked from any directory. Also, you will need to set the script to be executable; to do this, type:
chmod +x ra2mp3
The script is evoked with the following syntax:
ra2mp3 input.rm output.mp3
It will first run the input file through mplayer to determine its author and title. Then, using mplayer again, it will convert the file to a WAV, and take the author and title info to create an MP3 with matching ID3 tags. The WAV file used during the conversion process will be deleted automatically. Also, you may notice that LAME is being called with the flag -m m. Since I deal mostly with audio lectures, I convert the audio to mono; if you do not wish to do this, simply remove the flag from the script. Additionally, by typing lame at the command line, you can find a number of parameters that may be of personal use, and could subsequently be added to this script. Unfortunately, I know nothing of GUI programming, so if someone would like to make this process even easier, feel free :).
Conclusion:
I recommend making a backup of the mplayer and mencoder binaries, as well as the Real Player codecs. There is no telling when a change in either project may make this hint unusable (as it has in the past). You now have a file that can be used in any MP3 player, iTunes, or burnt to CD.

