In this article, we will provide a guide how to open up low layer stream to web clients, because web is one of the best solutions for interoperability.
Consuming video on any device (in a web browser) that is published as RTP stream with latency far below one second.
First research ended with observation that it is not possible to consume RTP stream directly by pure HTML video player or by any commercial or free web browser video players. The video has to be streamed using higher level communication protocols like HLS or MPEG-DASH. Low level video streams like RTP (or muxed with MPEG-TS) cannot be used directly. Communication protocol describes the playlist structure for the stream and the stream data split into playlist segments. Playlist with segments has to be published on web server and video consumer is periodically requesting data defined in playlist. Such additional processing adds overhead costs and increase glass to glass delay.
Http Live Streaming protocol divides stream into segments described in m3u8 playlist and it is transmitted over HTTP. Video data are encoded with H.264 codec, audio with MP3 and MPEG-TS container is used for transport.
Dynamic Adaptive Streaming over HTTP divides stream into segments and use XML formatted MPD manifest. Typically, the video data are encoded with H.264 codec, audio with AAC and MP4 container is used. But the standard is not bound to dedicated codecs, protocol or transport.
Neither with HLS nor MPEG-DASH we did not manage to achieve glass to glass stream delay below 1 second. In fact, there is no guarantee for delay lower than 1 second, but we tried the technology limits. It is important to mention we used recommended settings for the low latency streaming.
WebRTC - Web Real-Time Communication – provides peer-to-peer real time communication between web browsers. It does not require any additional plugin and it is based on JavaScript APIs. Can be such technology used for streaming? Yes, it can be. Let’s see how.
It’s the general-purpose server implementing mainly WebRTC media communication with browser, exchanging JSON message through REST API with it and with support of direct RTP media consumption. Any specific implementation is provided by server plugins. One of the available plugins is the streaming plugin which we used in our solution. Our requirement was to make it available on Windows machine. Because there is no free WebRTC server available for Windows and Janus WebRTC server does not run on Windows, we used WSL – Windows Subsystem for Linux – to host it.
https://janus.conf.meetecho.com/docs/
Streaming plugin is among others capable to capture a live RTP stream and broadcast it to WebRTC peers. For testing & development purpose, live RTP stream can be easily streamed by FFmpeg. Streams handled by Janus streaming plugin can be configured in “janus.plugin.streaming.jcfg”. Handled streams can be also configured using provided REST Streaming API.
https://janus.conf.meetecho.com/docs/streaming.html
As a client arbitrary web browser supporting JavaScript can be used. For communication with Janus WebRTC server is used provided REST Streaming API of the streaming plugin.
Following steps describes how we achieved our goal.
The hosting machine runs on Windows 10.
{% c-block language="markdown" %}
sudo apt-get update
sudo apt install net-tools
sudo apt install python
sudo apt install snapd
sudo apt-get install -yqq daemonize dbus-user-session fontconfig
sudo daemonize /usr/bin/unshare --fork --pid --mount-proc
/lib/systemd/systemd --system-unit=basic.target
exec sudo nsenter -t $(pidof systemd) -a su - $LOGNAME
sudo snap install janus-gateway
{% c-block-end %}
{% c-block language="markdown" %}
h264-sample: {
type = "rtp"
id = 10
description = "FFmpeg stream"
audio = false
video = true
videoport = 6004
videopt = 96
videortpmap = "H264/90000"
videofmtp = "profile-level-id=42e01f;packetization-mode=1"
secret = "adminpwd"}
{% c-block-end %}
{% c-block language="markdown" %}
ffmpeg -stream_loop -1 -re -i "sourceVideo.mp4" -an -vcodec copy -f rtp
rtp://<linux_ip_address>:6004?pkt_size=1316
{% c-block-end %}
{% c-block language="markdown" %}
cd /snap/janus-gateway/current/opt/janus/share/janus/demos
python -m SimpleHTTPServer 8000
{% c-block-end %}
With described solution we are able to consume video on any device (via web browser) that is published as RTP stream almost real time (the glass to glass delay is deeply below one second). Resulting delay and capability to present high bitrate streams depends on network throughput. The solution is able to process and show 4k streams. Janus WebRTC server does not need to be hosted under WSL. It can run on dedicated Linux machine. There are no special requirements for video clients, no third-party plugin nor non-standard library is required. Video can be consumed by nearly any web browser in most of devices (desktop, mobile). Even native desktop application can be used, so it’s very flexible solution.