I\'m looking for some universal way to dump rtsp stream. I want to figure out, that some rtsp stream is working well and server is sending some watchable video.
How about using libpcap to create a tcpdump/Wireshark-like tool? By removing the headers generate by the layers below the application layer (i.e. TCP/UDP/IP/...), you will have access to the RTSP stream. The stream can then be dumped to a file on disc. I have to admit that I am not that familiar with RTP/RTSP, so maybe you have to remove those headers as well and just write the payload to file (for a media player to play it back).
ffmpeg is the easiest way to achieve your goal, but here are some important notes:
First, I advise you to get the last version (2.4.x instead of the 1.2.x shipped with Ubuntu). You can get it from https://www.ffmpeg.org/download.html
You will still get the
Application provided invalid, non monotonically increasing dts to muxer in stream 0: 730672 >= 730672
av_interleaved_write_frame(): Invalid argument error
error but you can get rid of it. This is mainly because the FPS (Frames Per Second) are consistently changing on IP cameras depending on the quality of the connection. Here are 2 solutions that worked for me:
Solution 1 = use the use_wallclock_as_timestamps option so your command looks like
ffmpeg -use_wallclock_as_timestamps 1 -i rtsp://myip:554/mpeg4 -c copy myrecord.avi
PROS = low CPU usage + good quality recordings because nothing is transcoded / CONS = slightly big files (~6Mb / minute)
Solution2 = removing the "-acodec copy -vcodec copy" options in your command. The simple command
ffmpeg -i rtsp://myip:554/mpeg4 myrecord.avi
will do the trick. PROS = small files (~1.2Mb / minute) / CONS = high CPU usage (6% on my computer), because I think it is transcoding to the default codecs + bad quality recordings
Hope it helps!
Dump stream(s) from any Youtube Video to local device using OPENRTSP
As an example, i will use the rtsp feed available for any youtube video.
Steps:
Details on the manual process for dumping the stream:
Oauth 2 playground is good tool https://code.google.com/oauthplayground/
Request the following:
https://gdata.youtube.com/feeds/api/videos/cpST8yz4w1w?fields=media%3Agroup%2Fmedia%3Acontent%5B%40yt%3Aformat%3D%221%22%5D&v=2&alt=json
plaintext fields spec=media:group/media:content[@yt:format="1"]
The response is json stream. Copy that from the oauth form and paste it to : http://json.parser.online.fr/ and you will have something like:
"entry":{
"xmlns":"http://www.w3.org/2005/Atom",
"xmlns$media":"http://search.yahoo.com/mrss/",
"xmlns$yt":"http://gdata.youtube.com/schemas/2007",
"media$group":{
"media$content":[
{
"url":"rtsp://v8.cache8.c.youtube.com/CiILENy73wIaGQlcw_gs85OUchMYDSANFEgGUgZ2aWRlb3MM/0/0/0/video.3gp",
"type":"video/3gpp",
"medium":"video",
"expression":"full",
"duration":64,
"yt$format":1
}
]
Take the RTSP url attribute from that and call openrtsp to do the file dump. You will have to WAIT because openrtsp will stream the media ( not download ). If you ask for a dump of a 10 minute .mp4, you will have to wait 10 minutes.
NOTE: The SDP behind the rtsp URI maintains separate sources for each track. So, along with the dump, you get separate files for each track in the original media file.
$ ./openRTSP rtsp://v8.cache8.c.youtube.com/CiILENy73wIaGQlcw_gs85OUchMYDSANFEgGUgZ2aWRlb3MM/0/0/0/video.3gp
Dumpfile, Outputs will be:
Stdout details includes full protocol of RTSP session :
$ ./openRTSP rtsp://v8.cache8.c.youtube.com/CiILENy73wIaGQlcw_gs85OUchMYDSANFEgGUgZ2aWRlb3MM/0/0/0/video.3gp
Opening connection to 74.125.213.247, port 554...
...remote connection opened
Sending request: OPTIONS rtsp://v8.cache8.c.youtube.com/CiILENy73wIaGQlcw_gs85OUchMYDSANFEgGUgZ2aWRlb3MM/0/0/0/video.3gp RTSP/1.0
CSeq: 2
User-Agent: ./openRTSP (LIVE555 Streaming Media v2011.07.08)
Received 140 new bytes of response data.
Received a complete OPTIONS response:
RTSP/1.0 200 OK
Public: DESCRIBE, GET_PARAMETER, OPTIONS, PAUSE, PLAY, SETUP, SET_PARAMETER, TEARDOWN
CSeq: 2
Server: Google RTSP 1.0
Sending request: DESCRIBE rtsp://v8.cache8.c.youtube.com/CiILENy73wIaGQlcw_gs85OUchMYDSANFEgGUgZ2aWRlb3MM/0/0/0/video.3gp RTSP/1.0
CSeq: 3
User-Agent: ./openRTSP (LIVE555 Streaming Media v2011.07.08)
Accept: application/sdp
Received 776 new bytes of response data.
Received a complete DESCRIBE response:
RTSP/1.0 200 OK
Content-Type: application/sdp
Cache-Control: must-revalidate
Date: Fri, 30 Mar 2012 15:27:43 GMT
Expires: Fri, 30 Mar 2012 15:27:43 GMT
Last-Modified: Fri, 30 Mar 2012 15:27:43 GMT
Content-Base: rtsp://v8.cache8.c.youtube.com/CiILENy73wIaGQlcw_gs85OUchMYDSANFEgGUgZ2aWRlb3MM/0/0/0/video.3gp/
CSeq: 3
Server: Google RTSP 1.0
Content-Length: 404
v=0
o=GoogleStreamer 943086435 202448811 IN IP4 74.125.213.247
s=Video
c=IN IP4 0.0.0.0
b=AS:51
t=0 0
a=control:*
a=range:npt=0-63.800000
m=video 0 RTP/AVP 98
b=AS:39
a=rtpmap:98 H263-2000/90000
a=control:trackID=0
a=cliprect:0,0,144,176
a=framesize:98 176-144
a=fmtp:98 profile=0;level=10
m=audio 0 RTP/AVP 99
b=AS:12
a=rtpmap:99 AMR/8000/1
a=control:trackID=1
a=fmtp:99 octet-align
Opened URL "rtsp://v8.cache8.c.youtube.com/CiILENy73wIaGQlcw_gs85OUchMYDSANFEgGUgZ2aWRlb3MM/0/0/0/video.3gp", returning a SDP description:
v=0
o=GoogleStreamer 943086435 202448811 IN IP4 74.125.213.247
s=Video
c=IN IP4 0.0.0.0
b=AS:51
t=0 0
a=control:*
a=range:npt=0-63.800000
m=video 0 RTP/AVP 98
b=AS:39
a=rtpmap:98 H263-2000/90000
a=control:trackID=0
a=cliprect:0,0,144,176
a=framesize:98 176-144
a=fmtp:98 profile=0;level=10
m=audio 0 RTP/AVP 99
b=AS:12
a=rtpmap:99 AMR/8000/1
a=control:trackID=1
a=fmtp:99 octet-align
Created receiver for "video/H263-2000" subsession (client ports 52320-52321)
Created receiver for "audio/AMR" subsession (client ports 52322-52323)
Sending request: SETUP rtsp://v8.cache8.c.youtube.com/CiILENy73wIaGQlcw_gs85OUchMYDSANFEgGUgZ2aWRlb3MM/0/0/0/video.3gp/trackID=0 RTSP/1.0
CSeq: 4
User-Agent: ./openRTSP (LIVE555 Streaming Media v2011.07.08)
Transport: RTP/AVP;unicast;client_port=52320-52321
Received 360 new bytes of response data.
Received a complete SETUP response:
RTSP/1.0 200 OK
Session: 4d04d0e9;timeout=90
Transport: RTP/AVP;unicast;mode=play;client_port=52320-52321;server_port=10580-10581;source=74.125.213.247;ssrc=7B551CAA
Cache-Control: must-revalidate
Date: Fri, 30 Mar 2012 15:27:43 GMT
Expires: Fri, 30 Mar 2012 15:27:43 GMT
Last-Modified: Fri, 30 Mar 2012 15:27:43 GMT
CSeq: 4
Server: Google RTSP 1.0
setup response srvAddr port rtpchnl 74.125.213.247 10580 255
Setup "video/H263-2000" subsession (client ports 52320-52321)
Sending request: SETUP rtsp://v8.cache8.c.youtube.com/CiILENy73wIaGQlcw_gs85OUchMYDSANFEgGUgZ2aWRlb3MM/0/0/0/video.3gp/trackID=1 RTSP/1.0
CSeq: 5
User-Agent: ./openRTSP (LIVE555 Streaming Media v2011.07.08)
Transport: RTP/AVP;unicast;client_port=52322-52323
Session: 4d04d0e9
Received 360 new bytes of response data.
Received a complete SETUP response:
RTSP/1.0 200 OK
Session: 4d04d0e9;timeout=90
Transport: RTP/AVP;unicast;mode=play;client_port=52322-52323;server_port=10580-10581;source=74.125.213.247;ssrc=10CD5DCE
Cache-Control: must-revalidate
Date: Fri, 30 Mar 2012 15:27:43 GMT
Expires: Fri, 30 Mar 2012 15:27:43 GMT
Last-Modified: Fri, 30 Mar 2012 15:27:43 GMT
CSeq: 5
Server: Google RTSP 1.0
setup response srvAddr port rtpchnl 74.125.213.247 10580 255
Setup "audio/AMR" subsession (client ports 52322-52323)
Created output file: "video-H263-2000-1"
Created output file: "audio-AMR-2"
Sending request: PLAY rtsp://v8.cache8.c.youtube.com/CiILENy73wIaGQlcw_gs85OUchMYDSANFEgGUgZ2aWRlb3MM/0/0/0/video.3gp/ RTSP/1.0
CSeq: 6
User-Agent: ./openRTSP (LIVE555 Streaming Media v2011.07.08)
Session: 4d04d0e9
Range: npt=0.000-63.800
Received 394 new bytes of response data.
Received a complete PLAY response:
RTSP/1.0 200 OK
Session: 4d04d0e9;timeout=90
Range: npt=0.000-63.800
RTP-Info: url=rtsp://v8.cache8.c.youtube.com/CiILENy73wIaGQlcw_gs85OUchMYDSANFEgGUgZ2aWRlb3MM/0/0/0/video.3gp/trackID=0;seq=48690;rtptime=668323490,url=rtsp://v
8.cache8.c.youtube.com/CiILENy73wIaGQlcw_gs85OUchMYDSANFEgGUgZ2aWRlb3MM/0/0/0/video.3gp/trackID=1;seq=61565;rtptime=99689199
CSeq: 6
Server: Google RTSP 1.0
Started playing session
Receiving streamed data (for up to 68.800000 seconds)...
Sending request: TEARDOWN rtsp://v8.cache8.c.youtube.com/CiILENy73wIaGQlcw_gs85OUchMYDSANFEgGUgZ2aWRlb3MM/0/0/0/video.3gp/ RTSP/1.0
CSeq: 7
User-Agent: ./openRTSP (LIVE555 Streaming Media v2011.07.08)
Session: 4d04d0e9
Received 72 new bytes of response data.
Received a complete TEARDOWN response:
RTSP/1.0 200 OK
CSeq: 7
Session: 4d04d0e9
Server: Google RTSP 1.0
Dmitry, you should try ErlyVideo server. It can capture RTSP-traffic and store it in multimedia files which can be playable with mediaplayers.
Did you try vlc to save rtsp stream? It worked for me.I tried with graphical interface though. But it should also work from command line.
VLC is the first that comes to mind. I usually go to this old site www.vcdhelp.com and under "How To" panel on left side, click on "All Guide", type in your search parameter in "Text Search".
For your solution, check out: http://www.videohelp.com/tools/StreamTransport (freeware)