Listening to and recording audio and video streams with MPlayer

3605

Author: Dipen Chaudhary

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:

mms://fjord.nationalgeographic.com/channel/highspeed/2005/03/20050314SecondsChernobyl.asf

rtsp://rmv8.bbc.net.uk/radio4/religion/somethingunderstood.ra?BBC-UID=5417c0f422fe0bf9844e1d948050d9e3251e8b5800e09194b43fb6af22d49cdb_n&SSO2-UID=

http://totalrock.com/streams/TRLive64.asx

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.

Category:

  • Graphics & Multimedia