Low latency RTP stream delivery

Low latency RTP stream delivery
December 1, 2020
Video has become a basic type of on-line content and a video stream in a web browser window has become a mundane and ordinary technology. But what if a very specialized application, for example for medical or industry use, needs a high-quality video with less than 1 second latency?

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.

Main goal – low latency

Consuming video on any device (in a web browser) that is published as RTP stream with latency far below one second.

Journey to the goal

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.

HLS

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.

MPEG-DASH

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.

Hitting the goal

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.

Janus WebRTC server

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

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

Web client

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.

The solution

Following steps describes how we achieved our goal.

  • Hosting the Janus WebRTC server via WSL.
  • Janus WebRTC server configuration.
  • Streaming source RTP stream by FFmpeg
  • Watching the result.

The hosting machine runs on Windows 10.

Solution architecture

Hosting machine configuration:

Install Janus WebRTC server under Linux distribution:

  • To install required dependencies and Janus WebRTC server, run the following commands in Ubuntu terminal

{% 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 %}

Linux distribution network configuration:

  • By default, Linux distribution running under WSL is not accessible from outside of hosting machine
  • To make Janus WebRTC server running under Linux virtual machine available from outside of hosting machine, it is needed to set WSL network configuration to Bridge mode. Using the Bridge mode Linux virtual machine gets IP address on same LAN as hosting machine.

Add stream definition into streaming plugin configuration file:

  • Add following definition into “janus.plugin.streaming.jcfg”

{% 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 %}

Run FFmpeg to provide source RTP stream to Janus WebRTC server:

  • Get FFmpeg tool and run following command on host machine

{% 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 %}

Accessing configured stream:

  • By default, Janus WebRTC REST API is accessible on http://<linux_ip_address>:8088 and is possible to consume the stream over it.
  • Janus sever connection can be configured in “janus.transport.http.jcfg” configuration file
  • Janus also contains built in demos for streaming. To run the demos start HTTP server by typing following commands in Ubuntu console:

{% c-block language="markdown" %}
cd /snap/janus-gateway/current/opt/janus/share/janus/demos
python -m SimpleHTTPServer 8000

{% c-block-end %}

  • See the streaming demo on: http://<linux_ip_address>:8000/streamingtest.html

Summary

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.

Share:
Petr is a developer with more than 10 years of working experience. He focuses on Front-end and Back-end development on the Windows platform. Petr is a fan of agile development and teamwork. Apart from that, he likes the wind blowing through his hair in historical cars, on roller-skates, and while skiing.

Other articles by same author

Article collaborators

SABO Newsletter icon

SABO NEWSLETTER

Thank you! Your submission has been received!
Oops! Something went wrong while submitting the form.

About SABO Mobile IT

We focus on developing specialized software for our customers in the automotive, supplier, medical and high-tech industries in Germany and other European countries. We connect systems, data and users and generate added value for our customers with products that are intuitive to use.
Learn more about sabo