Hack 82. Rip Streaming Video
Use MPlayer to rip streaming video feeds directly to a file for later viewing .
With broadband connections becoming more and more the norm, many web sites are providing not just streaming audio but even streaming video content. Like with streaming audio, sometimes you would like to save a streaming video feed to a file for later (possibly offline) viewing. [Hack #81] discusses how to use streamripper to rip audio feeds, which it does well, but to rip video feeds you need to use a tool such as Mplayer.
MPlayer is an incredibly flexible video and audio player (for more information on MPlayer check out [Hack #48] ). MPlayer supports a wide variety of audio and video formats including streaming audio and video and can also dump the raw video and audio streams directly to a file.
The first step to rip a stream is to get the URL for the streaming video. In some cases this is as easy as right-clicking a link on the web page and selecting Copy Link. Some video streams are embedded in a web page, so you might have to view the page's source code to find the direct link to the stream (many Quicktime feeds are like this). After you have found the URL, the
$ mplayer http://movies.sample.com/example.mov
Replace the URL with the
After MPlayer has successfully
$ mplayer URL -dumpstream -dumpfile filename
This command sets MPlayer in a special mode to dump the streaming content directly to the file you specify with the
Hack 83. Command-Line Streaming MP3 Player
Use basic command-line tools to create your own streaming MP3 player .
When setting up Obsequeium (http://obsbox.sf.net) or Jinzora (http://
You can build a robust command-line streaming player with one command if you have madplay and wget installed. wget and madplay are both popular programs and should be prepackaged by your Linux distribution. Use your distribution's software installation tool to install these programs. If for some reason you don't have these tools prepackaged, download the tarballs from http://www.underbit.com/products/mad/ and http://www.gnu.org/software/wget/wget.html, compile, and install them according to the included installation instructions.
With wget and madplay installed, the following command will play the stream from http://example.com/mystream :
$ wgetqO http://example.com/mystream madplay -Q --no-tty-control-
reads the MP3 stream and
There is one more gotcha to
#!/bin/sh while [ 1 ] do wget -q -O -http://example.com/mystream madplay -Q --no-tty-control- sleep 5 done
Should something happen with the stream and the player exits, it will pause for five seconds and then restart the stream again. The five-second pause
Finally, to ensure the robustness of the command-line player, I recommend killing the player once a day at a
0 4 * * * killall9 madplay
This causes cron to kill madplay each day at 4 A.M. Pick a time when you expect the least number of people to listen, because listeners will need to sit through five seconds of silence.
That completes our hassle-free robust streaming MP3 player. This player configuration has