I am trying to build a service that streams your screen from a browser to clients (something like twitch).
What I have accomplished is I have built a working nginx server with rtmp, I tested it using OBS. That works pretty well.
And my question is how to stream a screen from a browser (not from OBS or other broadcasters) using WebRTC to nginx server with RTMP?
For RTSP<->WebRTC / RTMP<->WebRTC conversions, you need to run some kind of WebRTC gateway / media server software that works with all these formats/protocols and can transmux between all of them. Try Wowza / Unreal Media Server / Flashphoner. https://en.wikipedia.org/wiki/Comparison_of_streaming_media_systems
So in your case you want to publish the screen from browser to media server via WebRTC (H264 codec is a must) and then pull RTMP stream from the media server to nginx server with nginx-rtmp module.
Note that the opposite is possible too: You could push a stream to media server via RTMP, (for example, OBS screen capture) and then send this stream from media server to web browser(s) via WebRTC.
The main issue in these conversions is codec compatibility: H264 must be used for video, but if you need audio then you will have to do Opus to AAC transcoding.
SRS(Simple Realtime Server) is also able to covert WebRTC to RTMP, vice versa.
WebRTC to RTMP
is used for H5 publisher for live streaming. Because RTMP is disable now(at 2021.12), so the only way to publish stream by H5 is WebRTC. We also need to covert WebRTC to RTMP, which enable us to reuse the stream by other platform.
And SRS also support RTMP to WebRTC
, which is low latency live streaming. Generally, RTMP is about 3~5s latency, while RTMP to WebRTC
is about 0.8~1s
latency. Note that RTMP is not supported by H5, but HTTP-FLV
works well.
Apart of this, SRS also support HTTP-FLV, which enable H5 to play the RTMP, by flv.js. The latency is also lower than HLS or LLHLS.
Note: Other live streaming features are also important, because of off-topic, so please check the wiki of SRS, like DVR-MP4, DASH, Cluster, HTTP-API, etc.
It's also OK to use nginx to pull RTMP stream from SRS, or let SRS to forward RTMP to nginx, after covert WebRTC to RTMP stream by SRS.
Please don't use WebRTC to do live streaming, unless you know what you're doing, please read Why and Why NOT use WebRTC for live streaming.
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