Tags: arts

ra2wav: Convert RealAudio files to WAV files

This is getting silly. But this is the end of the mplayer/mencoder theme.

I've used mencoder, part of the mplayer suite, to do lots of different types of file format conversions. Here's another one, only this time it uses mplayer to do the conversion, Normally, mplayer plays A/V data, while mencoder transcodes A/V data between different formats.

However, mplayer has a "-ao" flag ("audio out"), which is normally used to control which hardware interface to send sound to (and/or how to send the audio data). E.g. It can choose between the ALSA or the OSS interfaces on a Linux system, or the sun interface on a Solaris system, or the OSX interface on a Mac. It is used to specify the specific sound card if more than one is present. It can also choose to send the audio to another abstraction layer such as SDL, esd, arts, or jack (all of which typically end up sending to a real sound card, although sometimes one on another computer). It can even use specialized hardware like that found in those TV capture cards that also output audio and video signals.

For some reason, mplayer's -ao flag has the ability to send audio data to plain PCM/WAV data file. This data is more or less identical to what it would send to sound hardware (at least, sound hardware found on PC-based computers). It creates a legitimate WAV file, but note that the data generated this way is not compressed.

sysadmin@artoo:~$ ra2wav
Usage: ra2wav .ra

Collapse )

You can see that the resulting wav file is very large. A logical next step would be to use something like lame to covert it to an mp3 or ogg file.

Here's the code

Collapse )

Note that, because mplayer really is a player but we're using it to transcode data, it needs to be told not to use a video codec ("-vc null") or to actually display video ("-vo null"). Note this is also done when using mplayer to identify data about the file using the "-identify" flag. The word "fast" tells the pcm driver to process faster than real (clock) time.

In writing this post, I couldn't remember why I decided to write this using mplayer. But in trying to create the "correct" version using mencoder, I couldn't figure out how to do it. I expected this to work:

mencoder -oac pcm -o "$j" "$i"

However, it doesn't. It says "WARNING: OUTPUT FILE FORMAT IS _AVI_. See -of help.", then "REALAUDIO file format detected.", and finally "Video stream is mandatory!". Apparently mencoder assumes it's working on a video file (an AVI file, by default). I can't figure out how to make it realize it's only to process audio data. There is an output format flag ("-of") that has a "rawaudio" format, but I couldn't make that work--it still insisted that a Video stream is mandatory. The man page says "-of" is still in beta, perhaps someday there'll be a "wav" or "pcm" format. If anyone has a suggestion, I'd love to learn how to make mencoder do what I want.