VLC RTSP live stream to Android

后端 未结 4 659
清歌不尽
清歌不尽 2021-02-14 15:25

For my app I have to stream from a decklink card to an Android app (I must be a live stream, so either HLS or RTSP seems to be good solutions, since my app targets Android 3+).

相关标签:
4条回答
  • 2021-02-14 15:44

    I've tested my rtsp server with openRTSP command.

    It's the UDP ports been blocked.

    If accessing rtsp without -t:

    -> $ openRTSP <rtsp_url>
    

    I got log telling me:

    // omit lots of lines..
    Created receiver for "video/H264" subsession (client ports 63346-63347)
    Sending request: SETUP rtsp://61.218.52.250:554/live/ch00_0/trackID=0 RTSP/1.0
    CSeq: 4
    User-Agent: openRTSP (LIVE555 Streaming Media v2013.12.16)
    Transport: RTP/AVP;unicast;client_port=63346-63347
    
    Received 47 new bytes of response data.
    Received a complete SETUP response:
    RTSP/1.0 461 Unsupported Transport
    CSeq: 4
    
    Failed to setup "video/H264" subsession: 461 Unsupported Transport
    

    So changing to TCP with:

    -> $ openRTSP -t <rtsp_url>
    

    it start receiving data successfully.

    // omit lots of lines..
    Opened URL "rtsp://61.218.52.250:554/live/ch00_0", returning a SDP description:
    v=0
    o=- 1 1 IN IP4 127.0.0.1
    s=Ubiquiti Live
    i=UBNT Streaming Media
    c=IN IP4 0.0.0.0
    t=0 0
    m=video 0 RTP/AVP 99
    b=AS:50000
    a=framerate:25
    a=x-dimensions:1280,720
    a=x-vendor-id:ubnt,a521
    a=x-rtp-ts:4617405454576779984
    a=rtpmap:99 H264/90000
    a=fmtp:99 profile-level-id=42A01E;packetization-mode=1;sprop-parameter-sets=Z0IAKOkAoAt1xIAG3dAAzf5gDYgQlA==,aM4xUg==
    a=control:trackID=0
    
    Sending request: SETUP rtsp://61.218.52.250:554/live/ch00_0/trackID=0 RTSP/1.0
    CSeq: 4
    User-Agent: openRTSP (LIVE555 Streaming Media v2013.12.16)
    Transport: RTP/AVP/TCP;unicast;interleaved=0-1
    
    
    Received 107 new bytes of response data.
    Received a complete SETUP response:
    RTSP/1.0 200 OK
    CSeq: 4
    Transport: RTP/AVP/TCP;unicast;interleaved=0-1
    Session: E090B5503236A1BFB7CE
    
    
    Setup "video/H264" subsession (client ports 54884-54885)
    Sending request: PLAY rtsp://61.218.52.250:554/live/ch00_0/ RTSP/1.0
    CSeq: 5
    User-Agent: openRTSP (LIVE555 Streaming Media v2013.12.16)
    Session: E090B5503236A1BFB7CE
    Range: npt=0.000-
    
    
    Received 159 new bytes of response data.
    Received a complete PLAY response:
    RTSP/1.0 200 OK
    CSeq: 5
    Session: E090B5503236A1BFB7CE
    Range: npt=now-
    RTP-Info: url=rtsp://61.218.52.250:554/live/ch00_0//trackID=0;seq=41402;rtptime=0
    
    
    Started playing session
    Data is being streamed (signal with "kill -HUP 96432" or "kill -USR1 96432" to terminate)...
    Received 47 new bytes of response data.
    Received 1424 new bytes of response data.
    Received 1424 new bytes of response data.
    Received 1424 new bytes of response data.
    Received 1424 new bytes of response data.
    Received 1448 new bytes of response data.
    Received 1448 new bytes of response data.
    

    Ref to openRTSP basics.

    Now I've got to figure out how to auto switch to TCP in Android.

    0 讨论(0)
  • 2021-02-14 15:50

    please try the VLC:

    vlc some_file.mp4 -I http --sout "#transcode{soverlay,ab=128,samplerate=44100,channels=2,acodec=mp4a,vcodec=h264,width=480,height=270,vfilter="canvas{width=480,height=270,aspect=16:9}",fps=25,vb=800,venc=x264{level=12,no-cabac,subme=20,threads=4,bframes=0,min-keyint=1,keyint=50}}:gather:rtp{mp4a-latm,sdp=rtsp://0.0.0.0:5554/stream.sdp}"

    and the android code:

    @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_main);
    
            final VideoView vidView = (VideoView)findViewById(R.id.myVideo);
    
            MediaController vidControl = new MediaController(this);
            vidControl.setAnchorView(vidView);
            vidView.setMediaController(vidControl);
    
            vidView.setVideoPath("rtsp://137.110.92.231:5554/stream.sdp");
    
            vidView.start();
            }
    
    0 讨论(0)
  • 2021-02-14 15:59

    Finally it was a network problem, I was connecting my devices through a MacBook WiFi sharing, and it seems that it blocked the RTSP stream. Now I am using a router and it works in RTSP (I'm still not able to receive a HTTP stream in the Android VideoView). Nevertheless, I still have a timeout issue : the RTSP stream stops after 60 sec, because the VideoView doesn't send keep alive messages. I will try to do it myself...

    0 讨论(0)
  • 2021-02-14 16:03

    Use MediaPlayer it supports both HTTP and RTSP network protocols. http://developer.android.com/guide/topics/media/mediaplayer.html#mediaplayer http://developer.android.com/guide/appendix/media-formats.html#recommendations

    0 讨论(0)
提交回复
热议问题