简体   繁体   English

使用HTML5-Video-Tag播放RTP视频流

[英]Playing RTP Video Stream with HTML5-Video-Tag

I am sending RTP video data from an Android phone to my computer. 我正在从Android手机向计算机发送RTP视频数据。 The RTP streaming works, proven with ffplay . RTP流有效,已通过ffplay证明。

Now I'm trying to receive and display the stream inside Chrome (63.0.3239.84, Win10, 64Bit). 现在,我尝试在Chrome(63.0.3239.84,Win10、64位)中接收和显示流。 I receive the RTP packets with node.js and pass them to all connected users with help of socket.io . 我通过node.js接收RTP数据包,并在socket.io帮助下将它们传递给所有连接的用户。

To display the video in an HTML5 <video> -tag, I tried a similar approach as the example in the docs of the MediaSource API. 为了在HTML5 <video> -tag中显示视频,我尝试了与MediaSource API 文档中的示例类似的方法。 This is, what i've tried to append the video data on the fly: 这就是我试图动态添加视频数据的原因:

 var socket = io(); var ms = new MediaSource(); var mimeCodec = 'video/mp4; codecs="avc1.42C01E"'; var queue = []; var video = document.querySelector('video'); // receiving the rtp-packets from android, forwarded by nodes socket.io socket.on('video-fragment', function(fragment) { queue.push(fragment.slice(11)); // cutting of rtp header to get plain NAL units }); video.src = URL.createObjectURL(ms); var timeout = 500; var appendChunk = function() { if(queue.length > 0) { timeout = 500; var append = function() { var sb = ms.addSourceBuffer(mimeCodec); sb.appendBuffer(queue.shift()); sb.addEventListener('updateend', function() { if(video.paused) { console.log("try to start video"); video.play(); } appendChunk(); }); ms.removeSourceBuffer(sb); }; if(ms.readyState == "open") { append(); } else { ms.addEventListener('sourceopen', function() { appendChunk(); }); } } else { setTimeout(appendChunk, timeout); // try again after some timeout... timeout *= 2; } } appendChunk(); // start recursive call 
 <video></video> 

However, I don't get any errors from my video-object. 但是,我的视频对象没有任何错误。 If I close the MediaSource at some point with ms.endOfStream() and try to start the video after that, I get a MediaError with code 4: DEMUXER_ERROR_COULD_NOT_OPEN . 如果我在某些时候用ms.endOfStream()关闭MediaSource,然后尝试开始播放视频,则会收到代码为4: DEMUXER_ERROR_COULD_NOT_OPEN

Any suggestions? 有什么建议么? Am I somehow on the right way? 我以某种方式正确吗? Or is this kind of video streaming not possible in Chrome and the only way of "live streaming" would be with using a playlist and video-file-chunks? 还是在Chrome中无法进行这种视频流传输,而“实时流传输”的唯一方法就是使用播放列表和视频文件块?

The browser only supports video in an mp4 (or webm) container. 浏览器仅支持mp4(或webm)容器中的视频。 It does not support the rtp protocol. 它不支持rtp协议。 It must be repackaged to a format the browser supports. 必须将其重新打包为浏览器支持的格式。

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

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