简体   繁体   English

如何在不涉及中间服务器的情况下直接从 HTML 中输出 RTMP 视频

[英]How to directly stream out RTMP video from HTML without involving a middle server

I thought it is straightforward to establish an RTMP output stream from the browser directly to an RTMP server.我认为从浏览器直接到 RTMP 服务器建立 RTMP output stream 很简单。 It was looking possible to me when I saw some streaming video API providers offer ready-made iFrame urls that capture the PC camera and establish a stream with their servers when embedded in Html. It was looking possible to me when I saw some streaming video API providers offer ready-made iFrame urls that capture the PC camera and establish a stream with their servers when embedded in Html.

However - I was wrong.然而——我错了。

It's pretty easy to get your hands on the chunks.很容易掌握这些块。 But how to push them to RTMP server?但是如何将它们推送到 RTMP 服务器呢?

 navigator.getUserMedia({
       video: true,
       audio: true
 },

 function (stream) {

     var options = { mimeType: "video/webm; codecs=vp9" };
     mediaRecorder = new MediaRecorder(stream, options);

     mediaRecorder.ondataavailable = handleDataAvailable;
     mediaRecorder.start();

     function handleDataAvailable(event) {

       if (event.data.size > 0) {

         console.log(recordedChunks);

    } 
})

It's not possible.这是不可能的。

Browsers do not support RTMP, nor do they allow for raw sockets required for adding support.浏览器不支持 RTMP,也不允许添加支持所需的原始 sockets。

And RTMP does not support VP9, for what it's worth.并且 RTMP 不支持 VP9,因为它的价值。

@szatmary correctly pointed out that browsers can't generate RTMP streams, and most likely will never be able to. @szatmary 正确地指出浏览器无法生成 RTMP 流,而且很可能永远也无法生成。

If you concatenate the buffers you get in your ondataavailable event handler, you get a media file in webm format.如果您连接在ondataavailable事件处理程序中获得的缓冲区,您将获得 webm 格式的媒体文件。 You can push the buffers one by one to a server using a web socket or socket.io.您可以使用 web 套接字或 socket.io 将缓冲区一个一个推送到服务器。 The server can assemble them into a file, which you can then play with many different media players, including the ones built into most browsers.服务器可以将它们组合成一个文件,然后您可以使用许多不同的媒体播放器播放该文件,包括大多数浏览器中内置的播放器。

But webm data must be transmitted with TCP or another lossless net protocol.但是webm数据必须用TCP或者其他无损网络协议传输。 It is not resilient to the lost data packets inherent in datagram protocols like RTMP or RTSP.它对 RTMP 或 RTSP 等数据报协议中固有的丢失数据包没有弹性。

You may want to use WebRTC with a so-called Selective Forwarding Unit server.您可能希望将 WebRTC 与所谓的选择性转发单元服务器一起使用。 Browsers can definitely originate WebRTC.浏览器绝对可以源自WebRTC。 And WebRTC is resilient to packet loss.并且 WebRTC 对丢包具有弹性。

Some commercial vendors offer these services for a per-minute price.一些商业供应商以每分钟的价格提供这些服务。 You can find various reviews on the intertoobz like this one.你可以在 intertoobz 上找到各种评论,比如这个。 https://www.callstats.io/blog/2017/10/17/sdk-comparison https://www.callstats.io/blog/2017/10/17/sdk-comparison

You might try one or two of these to see whether they meet your application needs.您可以尝试其中的一两个,看看它们是否满足您的应用程序需求。 If they do, then you can make an informed "make vs. buy" decision.如果他们这样做,那么您可以做出明智的“制造与购买”决定。

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

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