视频和音频流 - 仅限客户端的服务器 [英] Video and audio stream - server to clients only

查看:150
本文介绍了视频和音频流 - 仅限客户端的服务器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法使用服务器上安装的摄像头将网站上的视频和音频流传输到客户端 - 例如,像youtube一样?

Is there a way to stream a video and audio on a website just to the clients, using a camera installed on the server - for instance, like youtube does ?

我开始阅读 webrtc ,但如果我使用webrtc我应该创建一个眩晕/转弯服务器和其他事情,对于单向流我认为没有必要(这只是我对事物的理解......)因为我不需要客户的任何东西,字面意思,他们的视频或音频......

I've started reading webrtc, but if I use webrtc I should create a stun/turn server and other things, which for one way stream I think is not necessary (this is just my understanding of the things..) because I don't need anything from the clients, literally, neither their video, or audio..

所以有一种方法可以使用 html5 实现这一点,只需向一个方向流式传输:

So is there a way to achieve this using html5, streaming just in one direction:

服务器(相机) - >客户

那里有什么东西,或者我应该坚持 webrtc

Is there something about this out there, or should I stick with webrtc ?

推荐答案

我将为这个场景解释一个可能的解决方案,可能还有其他解决方案,但我希望我能给你大致了解如何做到这一点,以及探索更多关于WebRTC惊人可能性的起点。如果有什么不明白,请告诉我。

I'm going to explain a possible solution for this scenario, there might be others, but I hope mine gives you a rough idea of how you could do it and a start point to explore more about the amazing possibilities of WebRTC. Please let me know if something is not understood.

所以, WebRTC是一个免费的开放式项目,通过简单的API为浏览器和移动应用程序提供实时通信(RTC)功能。很好,就是:WebRTC有一个非常好的浏览器支持(不是在每个浏览器中,Safari一个月前开始使用Safari 11支持它)。但在这种情况下,我们希望在服务器端使用WebRTC。在一天结束时,我们仍然可以考虑点对点实时通信,其中一个同行是服务器。

So, WebRTC is a free, open project that provides browsers and mobile applications with Real-Time Communications (RTC) capabilities via simple APIs. Sweet, that is: WebRTC has a quite good browser support (not in every browser though, Safari just started supporting it a month ago with Safari 11). But in this case we want to use WebRTC in the server side. At the end of the day we can still think about peer-to-peer real time communication, where one of our peers is the server.

我不知道是否你熟悉Node.js,但我建议你用它编写你的服务器应用程序(< 3 Javascript!):

I don't know if you are familiar with Node.js, but I recommend you to write your Server app with it (<3 Javascript!):

但我建议你去看看 electron-werbrtc ,因为
其他人可能会使用弃用的方法或不完整。
electron-webrtc在后台运行一个无头电子客户端,使用Chromium的内置WebRTC实现
。所以有了它你应该
能够访问你服务器中的Camera并创建一个流为
服务给另一个对等体(浏览器)。

But I recommend you to to take a look at electron-werbrtc, since the others might be using deprecated methods or be incomplete. electron-webrtc runs a headless Electron client in the background to use Chromium's built-in WebRTC implementation. So with it you should be able to access the Camera in your server and create a stream to be served to the other peer (the browser).

以上所有都是与WebRTC相关的任务,在这种情况下:流视频对等(服务器)到对等(浏览器)。

All above would be the WebRTC related tasks, in this case: streaming video peer(server)-to-peer(browser).

现在,让我们来谈谈信号处理,眩晕和转弯。

Now, let's talk about signaling process, stun and turn.


  • 信令:现在想象一个具有2个浏览器的点对点场景,他们希望建立直接连接并在彼此之间传输视频和音频。但他们彼此不认识,如果我不知道你的家庭住址,我就不能给你发信。所以他们需要一种能够帮助他们相互了解的服务,这样他们才能拥有对方的IP。这应该通过所谓的信令服务器来完成。如果您知道其他对等IP,则不需要信令服务器。

  • Signaling: imagine now a scenario peer-to-peer with 2 browsers, they want to establish a direct connection and stream video and audio between each other. But they don't know each other, like if I don't know your home address, I can't send you a letter. So they need a service that helps them know each other, so they can have the other's IP. This should be done by what is called "a signaling server". If somehow you know the other peer IP, you wouldn't need a signaling server.

STUN / TURN :上述方案在局域网中完美运行,每个对等体都有自己的IP地址,并且它们之间没有防火墙和路由器。但除此之外,您可以在NAT或防火墙后面拥有对等体,然后您的信令服务器将无法让两个对等体发现自己。如果你有NAT背后的同伴,你需要一个STUN服务器,如果你有防火墙后面的同伴,你需要一个TURN服务器。这有点简化,但我只想让您了解何时需要STUN / TURN服务器。

STUN/TURN: the scheme above works perfectly in a local area network where each peer has its own IP address and there are no firewalls and routers between them. But otherwise, you can have peers behind a NAT or firewalls, and then your signaling server won't be able to make both peers to discover themselves. If you have peers behind a NAT, you'll need a STUN server, and if you have peers behind firewalls you'll need a TURN server. This is a bit simplified, but I just want you to have the general picture of when you might need STUN/TURN servers.

为了更好地理解信令,STUN和TURN,有一个非常图形的文章,完美地解释了它们。

To better understand Signaling, STUN and TURN, there is a very graphic article that explains them perfectly.

现在, for您的方案


  • 我认为您不需要STUN / TURN服务器而且您也不需要'需要实现信令过程,因为应该从服务器接收流的浏览器会知道服务器地址,对吧?因此,他们可以与它建立WebRTC连接。

  • 编辑:您可能需要在服务器和客户端之间实现某种握手(浏览器),这将是信令过程。这不是WebRTC的一部分,这就是你需要自己实现它的原因。正如我所说,这是2个对等方可以互相发现的方式,但它们也会将信息作为本地媒体条件进行交换,如编解码器,可以处理的解决方案等。对于您的情况,您的信令服务器可以托管在同一台服务器上您使用strea:您可以构建一个小型node.js应用程序,它在那里运行并轻松管理所有信令过程,这不是什么大问题。我建议你阅读这个文章,特别是我如何建立信令服务?。通常,该站点的所有WebRTC文章都非常有用。

  • I think you prob don't need STUN/TURN servers and also you prob don't need to implement the signaling process, because the browsers that are supposed to receive the stream from the server will know that server address, right? So they can establish a WebRTC connection with it.
  • it is likely that you will need to implement some sort of handshake between the server and the clients (browsers), so this will be the signaling process. This is not part of WebRTC and this is why you need to implement it yourself. As I said, it is the way 2 peers can discover each other, but they also exchange information as their local media conditions, like codecs, resolutions they can handle, etc. For your case, your signaling server could be hosted in the same server you use to strea: you can build a small node.js app that runs there and that manages all the signaling process easily, it is not a big deal. I recommend you to read this article, and specially the section "How can I build a signaling service?". In general all WebRTC articles from that site are very helpful.

这对你有意义吗?我认为你可以开始挖掘更多,看看这是否足够,或者你需要实现更多的东西。希望它有所帮助!

Does this make sense to you? I think with it you can start digging a little bit more and see if with this is enough or you need to implement more stuff. Hope it helps!

这篇关于视频和音频流 - 仅限客户端的服务器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆