RTSPget - download an RTSP stream
A frequently recurring question is "How can I download an RTSP stream
so that I can watch it later?" This is probably because your network
bandwidth isn't high enough to make the stream watchable live, or it
may just be because you want to save it for later.
Now that the folks at xine have
implemented an RTSP input filter, you can do just that!
However, until stream-dumping is included in xine (or RTSP is
included in Mplayer)
the only way to do it seems to be via a program which
calls xine's RTSP code directly.
Notes:
- I hacked this program up one evening recently; it seems to work but
I won't actively support it, nor present it as a paragon of programming style.
I merely supply it in case it is useful. If it breaks, that's tough luck I'm
afraid.
- You need to have a configured xine source tree (at least version 1-beta4)
before you can build this. (You don't need to build the whole of xine, but
why not go ahead and do it anyway - then you can play the movie you just
downloaded!)
- Once again: this web page is the only instruction I will offer. If you
can't compile it, please hack at it yourself. (If you discover a 100% genuine
bug then you may email me, although I can't promise to reply, and I can't fix
bugs in xine's code.)
Source code
Build instructions
- First build the `libreal' and `librtsp' libraries from the xine
distribution. If you haven't already built the whole of xine then something
like the following might work.
$ cd /usr/src/xine-lib-1-beta4
$ ./configure
$ cd src/input/libreal
$ make
$ cd ../librtsp
$ make
Now copy the completed libraries to wherever you put the `rtspget' source code.
You'll find them in subdirectories called `.libs' of the
libreal and librtsp directories, and their names will end
with `.al', although you will have to rename them to `.a'
when you copy them.
- Now compile the two source files. You will need access to some of the
include files from the xine source tree. Something like the following may be
appropriate.
$ gcc -O3 -c -I/usr/src/xine-lib-1-beta4/src/input rtspget.c
$ gcc -O3 -c xineutils.c -I/usr/src/xine-lib-1-beta4/include \
-I/usr/src/xine-lib-1-beta4/src/xine-utils
- Link it all together and hope it works. . .
$ gcc -o rtspget rtspget.o xineutils.o -L. -lrtsp -lreal
Using it
For best results, supply an MRL and an output file name (in that order).
The MRL must start with `rtsp://'. You can also write (in any order):
-q | be quiet |
-v | be verbose |
-o | choose the output file name. |
Note: `-o' can either be followed by a file name or placed
last on the command line: in the latter case, the output file will
be named after the MRL's base name (starting from the last slash).
If you don't name an output file, the program will output to stdout -
although you probably don't want it to do that, for reasons explained below.
If you don't specify the quiet flag you'll get a running count of bytes
downloaded so far (this is displayed on stderr).
Beware!
The RTSP code in xine is not perfect, so you may encounter some problems.
Note that it doesn't seem to work at all on big-endian architectures.
- The `-v' and `-q' options (obviously) only control
the main program, and not the RTSP library, so you can still get messages
output even in quiet mode. Moreover, any messages coming from the RTSP
library will be written on stdout (and so they'll disrupt the stream
if you are writing the stream to stdout).
- If the RTSP stream comes to an end, it takes the library a while to
realise; however, it will terminate eventually.
- So far, the streams I've downloaded with this will play fine on xine,
but RealPlayer 8 just gives a blank screen. That's why you need to
compile xine (or Mplayer) as well as just this program. :-)
That's it
Yup. Enjoy!