简体   繁体   English

VLC RTSP实时流到Android

[英]VLC RTSP live stream to Android

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+). 对于我的应用程序,我必须从卡链接卡流式传输到Android应用程序(我必须是实时流式传输,因此HLS或RTSP似乎是不错的解决方案,因为我的应用程序针对的是Android 3+)。 I recompiled VLC with the decklink sdk, and I am able to live stream to another pc over the network (but it works only 60sec with RTSP). 我使用了decklink sdk重新编译了VLC,并且可以通过网络将视频流实时传输到另一台PC(但是在RTSP下它只能工作60秒)。

Here is what I tried : 这是我尝试的:

  • HTTP Stream : HTTP流:

     ./vlc -vvv decklink:// --sout '#transcode{vcodec=mp4v,acodec=mpga,vb=56,ab=24,channels=1} :standard{access=http{use-key-frames},mux=ts,dst=:3001/stream.mpeg}' 

It is working in Android VLC 0.0.11, but only in WiFi, not in 3G. 它适用于Android VLC 0.0.11,但仅适用于WiFi,不适用于3G。 And I am not able to play it in my app with a VideoView. 我无法使用VideoView在我的应用程序中播放它。 Here is the code I used and the corresponding error messages : 这是我使用的代码和相应的错误消息:

String url = "http://134.246.63.169:5554/stream.mpeg";

VideoView videoView = (VideoView) this.findViewById(R.id.videoView);
videoView.setVideoURI(Uri.parse(url));        
videoView.setMediaController(new MediaController(this));
videoView.requestFocus();  
videoView.start();

Error messages : 错误讯息:

04-08 15:26:46.272: D/MediaPlayer(16349): Couldn't open file on client side, trying server side
04-08 15:26:46.272: V/ChromiumHTTPDataSource(7680): connect on behalf of uid 1080867789
04-08 15:26:46.272: I/ChromiumHTTPDataSource(7680): connect to http://134.246.63.169:8554/ @0
04-08 15:26:46.302: I/AwesomePlayer(7680): AwesomePlayer::AwesomePlayer()in
04-08 15:26:46.302: I/AwesomePlayer(7680): AwesomePlayer::AwesomePlayer()aftermClient.connect()
04-08 15:26:46.302: I/AwesomePlayer(7680): setDataSource_l('http://134.246.63.169:5554/')
04-08 15:26:46.302: W/MediaPlayer(16349): info/warning (701, 0)
04-08 15:26:46.302: V/ChromiumHTTPDataSource(7680): connect on behalf of uid 10067
04-08 15:26:46.302: I/ChromiumHTTPDataSource(7680): connect to http://134.246.63.169:5554/ @0
04-08 15:26:46.342: I/ActivityManager(272): Displayed fr.ifremer.testrtsp/.MainActivity: +183ms
04-08 15:26:46.382: I/MediaPlayer(16349): Info (701,0)
04-08 15:27:07.592: E/MediaPlayer(16349): error (1, -2147483648)
04-08 15:27:07.592: E/MediaPlayer(16349): Error (1,-2147483648)
  • RTSP : RTSP:

I used the encoding options recommended by Google on this page , eg : 我在此页面上使用了Google推荐的编码选项,例如:

  • video codec : h264 视频编解码器:h264
  • audio codec : AAC 音频编解码器:AAC
  • video bitrate : 56 视频比特率:56
  • audio bitrate : 24 音频比特率:24
  • audio channels : 1 音频通道:1个
  • size : 176x144 尺寸:176x144

     ./vlc -vvv decklink:// --sout-ffmpeg-strict=-2 --sout '#transcode{width=176,height=144,vcodec=h264,acodec=mp4a,vb=56,ab=24,channels=1} :rtp{dst=134.246.63.169,port-video=5554,port-audio=5556,sdp=rtsp://134.246.63.169:5554/stream.sdp}' 

I am able to play the stream in VLC desktop, but not in Android (even in the Android VLC version or the default Google video player:/ ). 我可以在VLC桌面上播放流,但不能在Android中播放(即使在Android VLC版本或默认的Google视频播放器:/中)。 If I don't specify a muxer, I can also play it it QuickTime (if I specify the muxer, either ts or ps, I have no video. If I try another muxer, VLC tells me that I am only allowed to use ts or ps in RTP) 如果我未指定复用器,则也可以在QuickTime中播放它(如果我指定ts或ps的复用器,则没有视频。如果尝试其他复用器,则VLC告诉我只能使用ts或RTP中的ps)

If I try with the Google video player, I get these messages in the locat : 如果我尝试使用Google视频播放器,则会在locat中收到以下消息:

04-08 15:32:45.792: D/MediaPlayer(13688): Couldn't open file on client side, trying server side
04-08 15:32:45.802: W/MediaPlayer(13688): info/warning (701, 0)
04-08 15:32:45.812: I/MediaPlayer(13688): Info (701,0)
04-08 15:32:45.812: D/MediaPlayer(13688): getMetadata
04-08 15:32:45.812: E/MediaPlayerService(7680): getMetadata failed -38
04-08 15:32:45.852: I/MyHandler(7680): connection request completed with result 0 (Success)
04-08 15:32:45.882: I/ARTSPConnection(7680): status: RTSP/1.0 200 OK
04-08 15:32:45.882: I/MyHandler(7680): DESCRIBE completed with result 0 (Success)
04-08 15:32:45.882: I/ASessionDescription(7680): v=0
04-08 15:32:45.882: I/ASessionDescription(7680): o=- 15352003113363922923 15352003113363922923 IN IP4 to63-169.ifremer.fr
04-08 15:32:45.882: I/ASessionDescription(7680): s=Unnamed
04-08 15:32:45.882: I/ASessionDescription(7680): i=N/A
04-08 15:32:45.882: I/ASessionDescription(7680): c=IN IP4 134.246.63.169
04-08 15:32:45.882: I/ASessionDescription(7680): t=0 0
04-08 15:32:45.882: I/ASessionDescription(7680): a=tool:vlc 2.0.5
04-08 15:32:45.882: I/ASessionDescription(7680): a=recvonly
04-08 15:32:45.882: I/ASessionDescription(7680): a=type:broadcast
04-08 15:32:45.882: I/ASessionDescription(7680): a=charset:UTF-8
04-08 15:32:45.882: I/ASessionDescription(7680): a=control:rtsp://134.246.63.169:5554/stream.sdp
04-08 15:32:45.882: I/ASessionDescription(7680): m=audio 5556 RTP/AVP 96
04-08 15:32:45.882: I/ASessionDescription(7680): b=AS:24
04-08 15:32:45.882: I/ASessionDescription(7680): b=RR:0
04-08 15:32:45.882: I/ASessionDescription(7680): a=rtpmap:96 mpeg4-generic/48000
04-08 15:32:45.882: I/ASessionDescription(7680): a=fmtp:96 streamtype=5; profile-level-id=15; mode=AAC-hbr; config=118856e500; SizeLength=13; IndexLength=3; IndexDeltaLength=3; Profile=1;
04-08 15:32:45.882: I/ASessionDescription(7680): a=control:rtsp://134.246.63.169:5554/stream.sdp/trackID=0
04-08 15:32:45.882: I/ASessionDescription(7680): m=video 5554 RTP/AVP 96
04-08 15:32:45.882: I/ASessionDescription(7680): b=AS:56
04-08 15:32:45.882: I/ASessionDescription(7680): b=RR:0
04-08 15:32:45.882: I/ASessionDescription(7680): a=rtpmap:96 H264/90000
04-08 15:32:45.882: I/ASessionDescription(7680): a=fmtp:96 packetization-mode=1;profile-level-id=64000b;sprop-parameter-sets=Z2QAC6zZQsTv/AC0ALBAAAADAEAAAAyjxQplgA==,aOvssiw=;
04-08 15:32:45.882: I/ASessionDescription(7680): a=control:rtsp://134.246.63.169:5554/stream.sdp/trackID=1
04-08 15:32:45.982: I/ARTSPConnection(7680): status: RTSP/1.0 200 OK
04-08 15:32:45.982: I/MyHandler(7680): SETUP(1) completed with result 0 (Success)
04-08 15:32:45.982: I/MyHandler(7680): server specified timeout of 60 secs.
04-08 15:32:45.992: W/MyHandler(7680): Missing 'source' field in Transport response. Using RTSP endpoint address.
04-08 15:32:45.992: I/APacketSource(7680): dimensions 176x144
04-08 15:32:46.012: I/ARTSPConnection(7680): status: RTSP/1.0 200 OK
04-08 15:32:46.022: I/MyHandler(7680): SETUP(2) completed with result 0 (Success)
04-08 15:32:46.022: I/MyHandler(7680): server specified timeout of 60 secs.
04-08 15:32:46.022: W/MyHandler(7680): Missing 'source' field in Transport response. Using RTSP endpoint address.
04-08 15:32:46.022: W/MyHandler(7680): Server picked an odd RTP port, it should've picked an even one, we'll let it pass for now, but this may break in the future.
04-08 15:32:46.082: I/ARTSPConnection(7680): status: RTSP/1.0 200 OK
04-08 15:32:46.082: D/dalvikvm(13688): GC_FOR_ALLOC freed 303K, 7% free 9289K/9927K, paused 35ms, total 36ms
04-08 15:32:46.092: I/MyHandler(7680): PLAY completed with result 0 (Success)
04-08 15:32:46.092: I/MyHandler(7680): This is a live stream
04-08 15:32:48.262: D/AudioHardware(7680): AudioHardware pcm playback is going to standby.
04-08 15:32:48.262: D/AudioHardware(7680): closePcmOut_l() mPcmOpenCnt: 1
04-08 15:32:56.092: W/MyHandler(7680): Never received any data, switching transports.
04-08 15:32:56.112: I/ARTSPConnection(7680): status: RTSP/1.0 200 OK
04-08 15:32:56.122: I/MyHandler(7680): TEARDOWN completed with result 0 (Success)
04-08 15:32:56.122: I/MyHandler(7680): connection request completed with result 0 (Success)
04-08 15:32:56.152: I/ARTSPConnection(7680): status: RTSP/1.0 200 OK
04-08 15:32:56.152: I/MyHandler(7680): DESCRIBE completed with result 0 (Success)
04-08 15:32:56.152: I/ASessionDescription(7680): v=0
04-08 15:32:56.152: I/ASessionDescription(7680): o=- 15352003157473632156 15352003157473632156 IN IP4 to63-169.ifremer.fr
04-08 15:32:56.152: I/ASessionDescription(7680): s=Unnamed
04-08 15:32:56.152: I/ASessionDescription(7680): i=N/A
04-08 15:32:56.152: I/ASessionDescription(7680): c=IN IP4 134.246.63.169
04-08 15:32:56.152: I/ASessionDescription(7680): t=0 0
04-08 15:32:56.152: I/ASessionDescription(7680): a=tool:vlc 2.0.5
04-08 15:32:56.152: I/ASessionDescription(7680): a=recvonly
04-08 15:32:56.152: I/ASessionDescription(7680): a=type:broadcast
04-08 15:32:56.152: I/ASessionDescription(7680): a=charset:UTF-8
04-08 15:32:56.152: I/ASessionDescription(7680): a=control:rtsp://134.246.63.169:5554/stream.sdp
04-08 15:32:56.152: I/ASessionDescription(7680): m=audio 5556 RTP/AVP 96
04-08 15:32:56.152: I/ASessionDescription(7680): b=AS:24
04-08 15:32:56.152: I/ASessionDescription(7680): b=RR:0
04-08 15:32:56.152: I/ASessionDescription(7680): a=rtpmap:96 mpeg4-generic/48000
04-08 15:32:56.152: I/ASessionDescription(7680): a=fmtp:96 streamtype=5; profile-level-id=15; mode=AAC-hbr; config=118856e500; SizeLength=13; IndexLength=3; IndexDeltaLength=3; Profile=1;
04-08 15:32:56.152: I/ASessionDescription(7680): a=control:rtsp://134.246.63.169:5554/stream.sdp/trackID=0
04-08 15:32:56.152: I/ASessionDescription(7680): m=video 5554 RTP/AVP 96
04-08 15:32:56.152: I/ASessionDescription(7680): b=AS:56
04-08 15:32:56.152: I/ASessionDescription(7680): b=RR:0
04-08 15:32:56.152: I/ASessionDescription(7680): a=rtpmap:96 H264/90000
04-08 15:32:56.152: I/ASessionDescription(7680): a=fmtp:96 packetization-mode=1;profile-level-id=64000b;sprop-parameter-sets=Z2QAC6zZQsTv/AC0ALBAAAADAEAAAAyjxQplgA==,aOvssiw=;
04-08 15:32:56.152: I/ASessionDescription(7680): a=control:rtsp://134.246.63.169:5554/stream.sdp/trackID=1
04-08 15:32:56.222: I/ARTSPConnection(7680): status: RTSP/1.0 461 Unsupported transport
04-08 15:32:56.222: I/MyHandler(7680): SETUP(1) completed with result 0 (Success)
04-08 15:32:56.222: I/APacketSource(7680): dimensions 176x144
04-08 15:32:56.242: I/ARTSPConnection(7680): status: RTSP/1.0 461 Unsupported transport
04-08 15:32:56.252: I/MyHandler(7680): SETUP(2) completed with result 0 (Success)
04-08 15:32:56.272: E/MediaPlayer(13688): error (1, -2147483648)
04-08 15:32:56.272: E/MediaPlayer(13688): Error (1,-2147483648)
04-08 15:32:56.272: D/VideoView(13688): Error: 1,-2147483648

I guess the problem is pointed with the "status: RTSP/1.0 461 Unsupported transport", but I don't see what can I change : I already open the ports I use, and I do receive the video on another computer. 我想问题出在“状态:RTSP / 1.0 461不支持的传输”,但是我看不到我可以更改什么:我已经打开了我使用的端口,并且确实在另一台计算机上接收了视频。

On the Android phone, I can play some rtsp streams I found on the web, for exemple this one : rtsp://184.72.239.149/vod/mp4:BigBuckBunny_115k.mov . 在Android手机上,我可以播放一些我在网上找到的rtsp流,例如rtsp://184.72.239.149/vod/mp4:BigBuckBunny_115k.mov。 So it should be possible. 因此应该有可能。

If anyone can help... ! 如果有人可以帮助...!

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. 最终这是一个网络问题,我通过MacBook WiFi共享连接设备,似乎阻止了RTSP流。 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). 现在,我使用的是路由器,它可以在RTSP中使用(我仍然无法在Android VideoView中接收HTTP流)。 Nevertheless, I still have a timeout issue : the RTSP stream stops after 60 sec, because the VideoView doesn't send keep alive messages. 不过,我仍然有超时问题:RTSP流在60秒后停止,因为VideoView不会发送保持活动消息。 I will try to do it myself... 我会尝试自己做的...

I've tested my rtsp server with openRTSP command. 我已经使用openRTSP命令测试了rtsp服务器。

It's the UDP ports been blocked. UDP端口被阻止。

If accessing rtsp without -t: 如果不带-t访问rtsp:

-> $ 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: 因此,通过以下方式更改为TCP:

-> $ 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. 参考openRTSP基础知识。

Now I've got to figure out how to auto switch to TCP in Android. 现在,我必须弄清楚如何在Android中自动切换到TCP。

please try the VLC: 请尝试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}" 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}}:聚集:rtp {mp4a-latm,sdp = rtsp://0.0.0.0:5554 / stream.sdp}”

and the android code: 和android代码:

@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();
        }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM