rtsp stream capturing
Asked Answered
S

6

24

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.

openRTSP

At first, google recommends me openRTSP tool.

 openRTSP -4 ${stream_link} > ${output_file}

But output video file dumped by that tool is not really correct. Video decoder (ffdec) returns many errors like "Failed to decode video packet" and "[h264] no frame!", which don't suit me.

ffmpeg

Then I've tried to dump rtsp stream with ffmpeg tool.

ffmpeg -loglevel debug -i "${stream_link}" -s 640x480 -vcodec copy -acodec copy -y ${output_file}

But streaming process was interrupted often by error:

Application provided invalid, non monotonically increasing dts to muxer in stream 0: 730672 >= 730672
av_interleaved_write_frame(): Invalid argument

I'm trying to use --fflags igndts but ffmpeg doesn't ignore these errors. It doesn't make any sense, because that error actually means that audio and video streams are sending asynchronously. The worst thing is that dumped file, resulted by that interrupted dump, is not correct too. Ffdec return some error:

ERROR [mov,mp4,m4a,3gp,3g2,mj2] moov atom not found
ERROR [ffdec] av_open_input_file: Operation not permitted

After a nice cup of googling I've found, that it's really old ffmpeg's muxer bug.

mplayer

Than I've tried to use mplayer with LIVE_555 lib.

mplayer -noframedrop -dumpfile ${output_file} -dumpstream ${stream_link}

But I've got some errors too.

Stream not seekable!
Core dumped ;)

Question

I think I'm doing something wrong. It's sounds really ridiculous, that there is no way to save rtsp stream in correct and playable video-file.

Maybe there are some another tools which can help with that task? Actually, I will be grateful for any advice for all kind of libs and languages. But that process should be automatic and have cli.

Refinements

Something about 50% experiments I've done on the localhost with vlc-streamer that emulates rtsp-broadcaster. Here is a manual which I try to follow.

I have really fresh and latest ffmpeg with x264 support, that I've installed by that useful thread.

Starchy answered 28/10, 2011 at 16:59 Comment(5)
Raw RTSP content is not well suited for save and replay: at the very least there are 2+ streams involved which you intend to save into plain file. Depacketization and saving into well known container format, such as .MP4 seems te be the bets way out. P.S. nice nickname, well done.Saprogenic
looks like the ffmpeg bug you linked to is now marked "fixed" ...Dwaynedweck
did any of the suggested solutions work? if so, could you accept it or post an answer? thx!Silicle
@Karoly Jorvath non of these are actually working solutionsElisabeth
did you get it working by any way ?Lilli
M
10

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.

Meador answered 31/10, 2011 at 12:22 Comment(0)
R
6

ffmpeg + wallclock_as_timestamps works

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!

Reduced answered 8/10, 2014 at 0:6 Comment(0)
Z
4

Dmitry, you should try ErlyVideo server. It can capture RTSP-traffic and store it in multimedia files which can be playable with mediaplayers.

Zara answered 14/11, 2011 at 5:1 Comment(1)
its dead now, migratedDarnley
B
3

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:

  1. Use Oauth 2.0 playground to interact directly with youtube api -gets the feeds
  2. Get the ID of Youtube video, using it in the gdata feed request (v=cpST8yz4w1w)
  3. Parse the output for the rtsp url you want - format 1 is low bandwidth , format 6= HIGH
  4. CLI - use openrtsp to request
  5. download(s) openrtsp outputs separate file for each track
  6. ofile1="video-H263-2000-1"
  7. ofile2="audio-AMR-2"

Details on the manual process for dumping the stream:

Oauth 2 playground is good tool https://code.google.com/oauthplayground/

  1. Choose "Youtube" from bottom of list , click "Authorize" button
  2. Click on "Allow Access"
  3. Click "Exchange Authorization code for tokens"
  4. You will get text box for "Request URI"
  5. 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:

  1. Created output file: "video-H263-2000-1"
  2. Created output file: "audio-AMR-2"

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
Businesswoman answered 30/3, 2012 at 15:52 Comment(2)
Can you use openRTSP to stream a live camera to a file? You imply that's not possible, as there's no end to the stream!Limewater
willl be in the filesystem and in the file , the file wont close until the stream terminates, its OSS use will have filesink,cpp module for each codec, so you gan see what it doesBusinesswoman
W
1

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)

Watercool answered 4/11, 2011 at 17:3 Comment(0)
O
0

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).

Overwinter answered 6/11, 2011 at 15:18 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.