I’d like to use OBS to stream via RTMP to a nginx server, and then locally send the RTMP fragments to WebRTC, so that they can be transmitted to the client via a MediaStream. I think this possible as it is essentially described here. I’m doing this because the multi-second latency of HLS is not appropriate for what I’m trying to do.
I’m having trouble extracting the RTMP fragments from nginx, the only plausible command I could find for doing this in the documentation was pull rtmp://...
. When I tried this I did not see any files appearing in my root folder, where I would normally find the HLS files if I were using hls on
. Does anyone know how to accomplish what I’m trying achieve above?
Thanks!
2
Answers
This is easily possible! You could base it off Pion’s rtp-to-webrtc example. This allows you to easily get media from ffmpeg into the browser.
The ffmpeg command you run instead would be like this one
ffmpeg -re -i rtmp://localhost:1935/$app/$name -vn -acodec libopus -f rtp rtp://localhost:6000 -vcodec copy -an -f rtp rtp:localhost:5000 -sdp_file video.sdp
I would consider transcoding to VP8 since not all browsers support H264.
—-
If you want sub-second playback in the browser I would check out Project Lightspeed that’s your best option today IMO.
There is really better and simple solutions for low latency streaming, either covert RTMP to WebRTC, or HTTP-FLV and HTTP-TS.
Convert RTMP to WebRTC
The most easy to do this, is to use a RTMP server such as SRS, which also support WebRTC player, it works like this:
You can follow the wiki to setup the demostration, I’m sure that you can finish it without 1 minute, because it’s very easy without any other dependencies.
First, run SRS server by docker:
Then, use OBS or other encoder to publish a RTMP stream:
Please open the H5 player to play the WebRTC stream:
Please note that this is not the only solution for low latency live streaming, I will describe others in bellow.
Low Latency Live Streaming
For low latency live streaming, besides WebRTC, there are another solutions, use HTTP-FLV or HTTP-TS. The protocol is very simple and the latency is about 1~3s.
First, run SRS server by docker:
Then, use OBS or other encoder to publish a RTMP stream:
Please open the H5 player to play the HTTP-FLV stream:
There are also some new features for live streaming, for example, HEVC now is available on both Safari and Chrome 107+, you can do HEVC low latency live streaming by:
I think WebRTC is not the same thing as live streaming, and live streaming never die, so even RTMP will be used in a long period.
The new protocol for live streaming is not only WebRTC, but:
It works like this:
For some use scenario, for example, if you want to transcode the live stream, or add a logo, or recreate it by OBS or other tools,
RTMP/SRT
is the best protocol.To play live stream on almost all devices and CDN, HLS is the best solution, and you can use smaller gop to get about 5s latency, see this post.
If you want to do more realtime live stream, you can use HTTP-TS or HTTP-FLV, the latency is about 1~3s, see this post
WebRTC is also avaiable to play live stream, use a SFU to covert RTMP to WebRTC, such as SRS, for example for cloud gaming, please see this post