rtsp stream capturing

后端 未结 6 2059
野的像风
野的像风 2020-12-24 03:39

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.

6条回答
  •  北海茫月
    2020-12-24 03:54

    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
    

提交回复
热议问题