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.
However I cannot find a python module for WebRTC. How can I send and receive a WebRTC video stream with python/twisted?
Thanks!
WebRTC is an open-source project providing peer-to-peer, real-time communication capabilities to web browsers, mobile devices, and any other device that can run code using the available APIs for Javascript, Python, . NET, Golang, and more.
If you want to create any webrtc -based client application without using a browser , the native libraries are the way to go. No silly standalone javascript engine necessary.
aiortc is a library for Web Real-Time Communication (WebRTC) and Object Real-Time Communication (ORTC) in Python. It is built on top of asyncio , Python's standard asynchronous I/O framework. The API closely follows its Javascript counterpart while using pythonic constructs: promises are replaced by coroutines.
I have started putting together the basic blocks needed to create a Python WebRTC endpoint.
One is an asyncio-based Interactive Connectivity Establishment module:
https://github.com/jlaine/aioice
Another one is a Python binding for libsrtp:
https://github.com/jlaine/pylibsrtp
We also need SRTP keying support in the OpenSSL bindings:
https://github.com/pyca/cryptography/pull/4099
On top of this, we can then build an asyncio-based WebRTC implementation:
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.
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. 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.
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.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With