For quite some time now, I always wanted to record songs from my favourite radio station. However, there was a problem: They only offer a RealMedia stream (at only 44 kbps, but the codec is remarkably good, on par with WMA or Vorbis), which is not as easily recordable as, say, HTTP streaming. However, with the help of the original binary codecs, MPlayer is able to play the stream – so it had to be possible to record it. Unfortunately, MPlayer’s
–dump options only record the compressed stream, and MEncoder refuses to transcode it into something usable (.wav, .mp3, …) because it always expects a video stream to be present. Furthermore, none of the dump or transcode options are able to play the stream while recording.
This had to change. And since I had a MPlayer-for-Win32 build environment on my box anyway, this was the right time. After some reasoning, I came up with a functional solution that doesn’t require twiddling around in MPlayer’s innards too much: an audio filter. If
–af lame is put into MPlayer’s audio filter chain, it simply encodes all audio samples that pass by into an MP3 file on disk. MPlayer’s audio output is still active, thus an MP3-encoded audio dump is created on-the-fly during playback.
Usage is quite simple:
–af lame=bitrate:filename, where
bitrate is the target bitrate in kbps (or a number between 0 and 9 if VBR encoding is desired). The
filename parameter, however, has a non-obvious special function: It is passed through
strftime(), which means that escapes like e.g.
%Y-%m-%d are processed. This allows for automatic inclusion of timestamps for the recordings, what happens to exactly match my usage requirements ;)
If you think that seeing is believing, you may enjoy the following transcript of a »real-life« MPlayer session (redundant and unnecessary lines removed):
mplayer.exe -cache-min 5 -quiet -af "lame=112:F:\TV\SSL--%Y-%m-%d--%H-%M.mp3" -priority high "rtsp://22.214.171.124/farm/*/encoder/sunshinelive/livestream2.rm"MPlayer dev-CVS-060207-19:12-3.4.2 (C) 2000-2006 MPlayer Team CPU: Advanced Micro Devices (Family: 15, Stepping: 0) CPUflags: MMX: 1 MMX2: 1 3DNow: 1 3DNow2: 1 SSE: 0 SSE2: 0 Compiled with runtime CPU detection. Setting process priority: high Playing rtsp://126.96.36.199/farm/*/encoder/sunshinelive/livestream2.rm. Connecting to server 188.8.131.52[184.108.40.206]: 554... Cache size set to 640 KBytes REAL file format detected. Stream description: Audio Stream Stream mimetype: audio/x-pn-multirate-realaudio-live Clip info: name: sunshine live - live stream ========================================================================== Opening audio decoder: [ffmpeg] FFmpeg/libavcodec audio decoders AUDIO: 44100 Hz, 2 ch, s16le, 44.1 kbit/3.12% (ratio: 5512->176400) Selected audio codec: [ffcook] afm: ffmpeg (FFmpeg COOK audio decoder) ========================================================================== [lame] encoding to file `F:\TV\SSL--2006-02-09--21-11.mp3' [lame] encoding in CBR mode at 112 kbps AO: [dsound] 44100Hz 2ch s16le (2 bytes per sample) Video: no video Starting playback...
- af_lame.tar.gz (8k) – the files I modified to add this plugin (based on CVS from 2006-02-07). I’m sorry, but I don’t have a patch at hand yet, so please backup your MPlayer source directory!