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 War_of_the_Worlds.ra
MPlayer 1.0rc2-4.2.3 (C) 2000-2007 MPlayer Team
CPU: Intel(R) Core(TM)2 Duo CPU E6750 @ 2.66GHz (Family: 6, Model: 15, Stepping: 11)
CPUflags: MMX: 1 MMX2: 1 3DNow: 0 3DNow2: 0 SSE: 1 SSE2: 1
Compiled with runtime CPU detection.
mplayer: could not connect to socket
mplayer: No such file or directory
Failed to open LIRC support. You will not be able to use your remote control.
REALAUDIO file format detected.
Title: The "War of the Worlds" Radio Broadcast
Author: Orson Welles/The Mercury Theatre
Copyright: Howard Koch
Forced audio codec: mad
Opening audio decoder: [liba52] AC3 decoding with liba52
Using SSE optimized IMDCT transform
Using MMX optimized resampler
AUDIO: 11025 Hz, 2 ch, s16le, 16.0 kbit/4.54% (ratio: 2000->44100)
Selected audio codec: [a52] afm: liba52 (AC3-liba52)
[AO PCM] File: War_of_the_Worlds.wav (WAVE)
PCM: Samplerate: 11025Hz Channels: Stereo Format s16le
[AO PCM] Info: Faster dumping is achieved with -vc null -vo null -ao pcm:fast
[AO PCM] Info: To write WAVE files use -ao pcm:waveheader (default).
AO: [pcm] 11025Hz 2ch s16le (2 bytes per sample)
Video: no video
a52: error at resampling44.5 (57:24.5) 0.1%
A: 1.1 (01.1) of 3444.5 (57:24.5) 0.1%
Exiting... (End of file)
sysadmin@artoo:~$ ls -la War_of_the_Worlds.*
-rw-r--r-- 1 jdimpson jdimpson 6889020 2008-12-27 00:53 War_of_the_Worlds.ra
-rw-r--r-- 1 sysadmin sysadmin 152248364 2008-12-27 00:55 War_of_the_Worlds.wav
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
# convert realaudio to standard wav
if [ -z "$i" ]; then
echo "Usage: $ME
j=`basename "$i" .ra`.wav;
mplayer -vc null -vo null -ao pcm:file="$j":fast "$i"
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.