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:
OBS/FFmpeg ---RTMP---> SRS ---WebRTC--> Browser(Chrome)
Note: This solution allows you make little change, and also allows you to deliver both HLS for some devices which does not support WebRTC such as mobile brower.
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:
docker run --rm -it -p 1935:1935 -p 1985:1985 -p 8080:8080 \
--env CANDIDATE="192.168.1.10" -p 8000:8000/udp \
ossrs/srs:5 ./objs/srs -c conf/rtmp2rtc.conf
Note: Please set the CANDIDATE
to the IP that your browser can access it, because WebRTC signaling and media use seperate transport channel.
Then, use OBS or other encoder to publish a RTMP stream:
docker run --rm -it ossrs/srs:encoder \
ffmpeg -stream_loop -1 -re -i doc/source.flv \
-c copy -f flv rtmp://192.168.1.10/live/livestream
Note: Please replace the IP to the correct one.
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.
Note: Neither WebRTC nor HTTP-TS is supported by general CDN, but there are some CDNs support it such as TencentCloud, and there will be more in future.
Note: There is some issues to do live streaming by WebRTC, please see this post
First, run SRS server by docker:
docker run --rm -it -p 1935:1935 -p 1985:1985 -p 8080:8080 \
ossrs/srs:5 ./objs/srs -c conf/srs.conf
Then, use OBS or other encoder to publish a RTMP stream:
docker run --rm -it ossrs/srs:encoder \
ffmpeg -stream_loop -1 -re -i doc/source.flv \
-c copy -f flv rtmp://192.168.1.10/live/livestream
Note: Please replace the IP to the correct one.
Please open the H5 player to play the HTTP-FLV stream:
Note: We only demostrate the HTTP-FLV, you can use HTTP-TS for better compatiblity.
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:
OBS/FFmpeg --SRT---> SRS ---HTTP-TS/HLS--> Safari/Chrome/VLC/ffpay
Note: You can find the HEVC low latency demo at here
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:
- SRT or RIST: Used to publish live streaming to live streaming server or platform.
- WebRTC: To publish live stream by H5 web page.
- HLS/HTTP-TS/WebRTC: To play the live streaming.
It works like this:
+-------------+
OBS/FFmpeg/Encoder ---RTMP/SRT--> + Live Server +----RTMP/SRT--> Tool
H5/Chrome/Safari ------WebRTC--> + or Platform +----HLS ---> Viewer
+-------------+----HTTP-TS/WebRTC-->Viewer
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