This is a read-only archive. Find the latest Linux articles, documentation, and answers at the new!

Feature: Graphics & Multimedia

Listening to and recording audio and video streams with MPlayer

By Dipen Chaudhary on October 29, 2007 (3:00:00 PM)

Share    Print    Comments   

Most streaming audio and video on the Internet is disseminated in proprietary formats such as RM, RAM, WMV, and ASF. Fortunately, the open source application MPlayer can play and even record streams in almost any format.

MPlayer supports RTSP, MMS, HTTP (progressive) and other streaming URLs, as well as direct playback from the URLs. Such URLs may look something like these:

Unfortunately, these URLs are not always provided in the open to be copied. It can take a bit of detective work to extract them from a meta file, such as .ram file for rtsp:// URLs. For instance, if you want to listen to BBC Radio 4, you choose the program you want and try to locate the link of .ram file from the site, which in case of BBC Radio can be found out by opening its player and copying the link on "Listen using stand-alone Real Player." You can then use wget to download the associated .ram file, which points to one or more RTSP URLs such as the one above. Using that URL, you should be able to listen to the program in MPlayer, after that program sets the initial cache and loads appropriate codecs. MPlayer does not allow forward positioning with streams, and the extent of backward positioning depends on the size of the cache. If the RTSP stream is password-protected, you can specify a username and password as command-line options to MPlayer.

Saving and sharing stream content

MPlayer can also record streams using the -dumpstream option, which dumps the stream to a file specified by the -dumpfile option. This process takes as much time as the playback time of the stream, if the network bandwidth is more than the bit rate of the stream. If you have a slow connection, stream dump will be very irregular, and its success will depend on the cache size set by MPlayer.

Encoders and decoders for proprietary formats are usually reverse-engineered, and hence do not have a consistent implementation among players. For instance, the .rm file obtained after using dumpstream may not play properly in VLC or other players supporting .rm files. If you want to make a downloaded stream more portable, you can convert the file to a standard format such as MP3 or MPEG that is better supported by all players. You'll need the appropriate encoders to do the conversion, such as LAME for MP3 and MEncoder for MPEG. For instace, to convert a .rm file to MP3, you can use commands like:
mplayer -ao pcm:waveheader:file="su.wav" "somethingunderstood.rm" -vo null -vc dummy
lame -h -ms "su.wav" "su.mp3"

When they complete, the streamed audio should be in MP3 format, and can thus be used easily with other players and shared with friends. You can convert other stream formats, such as ASF and WMV, the same way.

Dipen Chaudhary is an organiser of the Linux user group at VIT, Vellore, India.

Share    Print    Comments   


on Listening to and recording audio and video streams with MPlayer

Note: Comments are owned by the poster. We are not responsible for their content.


Posted by: Anonymous [ip:] on October 29, 2007 06:04 PM
C-Span has for many years now offered streams for c-span1, 2 and 3 which is awfully nice of them I think, you can access them with:

mplayer -playlist rtsp://
mplayer -playlist rtsp://
mplayer -playlist rtsp://

Note, this is the rm stream, which is of much higher quality, in particular concerning audio. They also have a wmv stream, but it's much lower quality (Well in my opinion anyway) (:


Re: C-Span

Posted by: Anonymous [ip:] on October 29, 2007 06:05 PM
Meh well that got a bit fucked up, the space between "rm mplayer" is actually supposed to be a newline, but oh well


Listening to and recording audio and video streams with MPlayer

Posted by: Anonymous [ip:] on October 29, 2007 11:54 PM
I tried to connect mplayer to my slimserver and it acted like I was a fool for even trying. I wish this article was more practical. A "How to' rather that a "You can". "You can" do a lot of things with Linux, we all know that, its the "How to" that is needed.


Re: Listening to and recording audio and video streams with MPlayer

Posted by: Anonymous [ip:] on October 30, 2007 09:33 AM
Search for the 'AlienBBC' plugin. That wraps this method of using MPlayer, and SlimServer will do the transcoding to MP3 for you. An added enhancement is that you can also browse the 'listen again' listings on either the web client or your player and choose content from there.


No, No, NO!

Posted by: Anonymous [ip:] on October 30, 2007 06:55 AM
The problem is proprietary data formats. And here we have an article on a Linux website telling us to convert .wav files to .mp3!

MP3 is a closed, proprietary format. Moreover, it's technically inferior to Ogg. Never convert a .wav file to .mp3; convert it to .ogg. Many popular brands of music player (e.g. Samsung) play .ogg files. Don't buy one that locks you in to proprietary mp3.


Re: No, No, NO!

Posted by: Anonymous [ip:] on October 30, 2007 07:45 AM
Sorry, buy Samsung is not a "popular brand of music players"; Apple, Creative, and even Microsoft are, but not Samsung.


Re: No, No, NO!

Posted by: Anonymous [ip:] on October 30, 2007 05:48 PM
MP3, being an open standard, is not a proprietary format, it's just patent-encumbered. Which, by the way, is of concern to you only if you're unfortunate enough to live in a place where software is patentable. The decoders and encoders your average *nixer uses, are free software.


Oh, by the way...

Posted by: Anonymous [ip:] on October 30, 2007 07:46 AM
... your capcha system sucks; I had to try four times before it accepted my post.


A more efficient recording method.

Posted by: Anonymous [ip:] on October 30, 2007 10:48 AM
The method described for encoding to mp3 would work, but requires three passes and potentially a lot of disk space. The following will convert a stream to mp3 using two parallel passes.

First create a fifo:

mkfifo radip.pipe

This creates a special file that can be used as the output file for one program and the input file of another.

Next, assuming that you have a ram file execute these two commands in seperate terminal windows.

mplayer -vo null -vc dummy -ao pcm:waveheader:file=radio.pipe `cat ramfile.ram`

lame -h -ms radio.pipe show.mp3

mplayer will send its output to radio.pipe, and lame will receive it as it arrives and output the mp3, thus your mp3 will be encoded faster without needing to use up as much disk space as you would creating the rm and wav files.


This story has been archived. Comments can no longer be posted.

Tableless layout Validate XHTML 1.0 Strict Validate CSS Powered by Xaraya