简体   繁体   English

使用Python的WebRTC

[英]WebRTC with python

I would like to make a streaming server with python/twisted, which receives a WebRTC video stream and then applys some OpenCV algorithms to it. 我想用python / twisted做一个流服务器,它接收WebRTC视频流,然后对其应用一些OpenCV算法。

However I cannot find a python module for WebRTC. 但是我找不到WebRTC的python模块。 How can I send and receive a WebRTC video stream with python/twisted? 如何使用python / twisted发送和接收WebRTC视频流?

Thanks! 谢谢!

What you can do is take screen shots continuously and push them to a websocket and allow your twisted server to take a gander at each one as it comes in. 您可以做的是连续拍摄屏幕快照并将其推入网络套接字,并让扭曲的服务器对每一个进来的服务器都轻描淡写。

I have modified some common recorders and my version takes Jpeg images and pushes them over a websocket. 我已经修改了一些常用的记录器,而我的版本则记录了Jpeg图像并将其推送到网络套接字上。 Feel free to use and modify how you want so that it fits your needs. 随意使用和修改您想要的方式,使其适合您的需求。 Source code here . 源代码在这里 The example I use is pushing down to a libwebsocket server built in C but the same javascript could be used to send to any websocket server. 我使用的示例下推到用C内置的libwebsocket服务器,但是相同的javascript可用于发送到任何websocket服务器。

I've had a similar issue and ended up creating a server that launches a headless chrome instance from which I can access the WebRTC streams, record chunks with a MediaRecorder and finally forward those chunks on via a WebSocket. 我遇到了类似的问题,最终创建了一个服务器,该服务器启动一个无头的chrome实例,从该实例我可以访问WebRTC流,使用MediaRecorder记录块,最后通过WebSocket继续转发这些块。

I'd love a python based solution so I wouldn't need the intermediary server launching headless chrome instances but haven't been able to find one. 我很喜欢基于python的解决方案,因此我不需要中介服务器启动无头chrome实例,但无法找到它。

I've been using Node.js and Puppeteer but one could launch the browser instances from your python server and then send the decoded data back via plain old sockets or whatever else tickles your fancy. 我一直在使用Node.js和Puppeteer,但是可以从您的python服务器启动浏览器实例,然后通过普通的旧套接字将解码后的数据发送回去,或者通过其他方式使您喜欢。

I have started putting together the basic blocks needed to create a Python WebRTC endpoint. 我已经开始整理创建Python WebRTC端点所需的基本块。

One is an asyncio-based Interactive Connectivity Establishment module: 一个是基于异步的交互式连接建立模块:

https://github.com/jlaine/aioice https://github.com/jlaine/aioice

Another one is a Python binding for libsrtp: 另一个是libsrtp的Python绑定:

https://github.com/jlaine/pylibsrtp https://github.com/jlaine/pylibsrtp

We also need SRTP keying support in the OpenSSL bindings: 在OpenSSL绑定中,我们还需要SRTP密钥支持:

https://github.com/pyca/cryptography/pull/4099 https://github.com/pyca/cryptography/pull/4099

On top of this, we can then build an asyncio-based WebRTC implementation: 最重要的是,我们可以构建一个基于异步的WebRTC实现:

https://github.com/jlaine/aiortc https://github.com/jlaine/aiortc

I have been able to get both Chrome and Firefox to establish an audio and video stream to a Python-based server. 我已经能够使用Chrome和Firefox来建立基于Python的服务器的音频和视频流。

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

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