Using ffmpeg and SRT to Transport Video Signal to the Cloud

Moving the live video transcoding for online distribution to public cloud requires a way to transport the video signal to the cloud. There a couple of ways this can be achieved and in this article we will mainly look at how to use SRT (Secure Reliable Transport) and ffmpeg to accomplish this.

Transporting the video signal to a public cloud often means transportation over Internet

Before we look into how to use SRT let us look at what other options exists. The simplest option available today is to use RTMP as the transport protocol. It is a protocol developed by Adobe and has been around for a while. Many production tools such as Wirecast, Teradek and OBS have support for RTMP today and this is the protocol that YouTube, Facebook and Twitch supports.

RTMP is the simplest option available today

RTMP is a TCP-based protocol where every packet is acknowledged and guaranteed to be delivered meaning that the underlying protocol ensures that all bits in the bitstream are received by the receiving end. This handshake process for every packet adds overhead and emposes some limitations.

Another drawback with RTMP is that not all Live Transcoding software supports RTMP out-of-the-box. This limits some of the options you have on choosing the right transcoding software. You would in many cases need a “bridge” from RTMP to MPEG-TS over UDP/Multicast. This can also be accomplished using ffmpeg and we will describe how in a separate article.

A “bridge” from RTMP to Multicast may be required for some of the live transcoding softwares

And equally it is not always you on the production side (sender) have the option to use RTMP as the transportation protocol. For those cases there are a couple of commercial options available, such as Zixi, to transfer a MPEG-TS stream over the Internet.

Principle of using commercial options such as Zixi to transfer MPEG-TS over Internet

An option to the commercial and proprietary protocols is to use SRT (Secure Reliable Transport) to transfer the signal and how this can be done with ffmpeg is what we will describe here.

Secure Reliable Transport

SRT is an open source video transport protocol and technology stack backed by the SRT Alliance. Today the SRT Alliance consists of over 40 vendors including Haivision, Wowza, Teradek, and many more. The standard is open and available to anyone who wants to implement it and SRT is also open source which means that the software (technology stack) required to implement SRT is available from a public repository and there are no fees to incorporate the technology into any device or service.

Compiling SRT with ffmpeg

Havision, one of the founders of SRT, provides an open source SDK to enable SRT support in your software. This is the SDK that we will compile and include in our ffmpeg build.

$ git clone https://github.com/Haivision/srt.git
$ cd srt
$ ./configure
$ make && make install

The SDK is depending on that you have libssl and tcl installed, e.g. on Ubuntu:

$ apt-get install libssl-dev tclsh

When compiling ffmpeg enable SRT by adding the option below when running the configure script.

$ ./configure --enable-libsrt ...
Using SRT to transport an MPEG-TS video stream over the Internet

SRT Tx

To setup an SRT Transmitter that takes an MPEG-TS video stream and transmit it to an SRT Receiver over the Internet you start ffmpeg with the following command.

$ ffmpeg -fflags +genpts -listen 1 -re -i udp://239.0.0.1:1234?pkt_size=1316 -acodec copy -vcodec copy -strict -2 -y -f mpegts srt://0.0.0.0:9998?pkt_size=1316&mode=listener

This setup the SRT Transmitter as a server that the SRT Receiver can connect to. If you instead have an SRT Receiver acting as a server you run the following instead (assuming that 192.168.1.42 is the IP of the SRT Receiver).

$ ffmpeg -fflags +genpts -listen 1 -re -i udp://239.0.0.1:1234?pkt_size=1316 -acodec copy -vcodec copy -strict -2 -y -f mpegts srt://192.168.1.42:9998?pkt_size=1316

If you want to quickly try this out you can use the SRTTx Docker container in our toolbox.

$ docker run --rm -p 9998:9998/udp eyevinntechnology/toolbox-srttx --inputtype=mpegts --passthrough --listener 239.0.0.1:1234 0.0.0.0:9998

SRT Rx

To setup an SRT Receiver with ffmpeg that outputs the incoming stream over a multicast network you start ffmpeg with this command.

$ ffmpeg -re -i srt://0.0.0.0:9998?pkt_size=1316&mode=listener -vcodec copy -acodec copy -strict -2 -y -f mpegts udp://239.0.0.2:1234?pkt_size=1316

In thise case the SRT Receiver acts as a server which the SRT Transmitter will connect to. If you instead wants to act as a client and assuming the IP of the SRT Transmitter is 192.168.1.19 you run the following command.

$ ffmpeg -re -i srt://192.168.1.19:9998?pkt_size=1316 -vcodec copy -acodec copy -strict -2 -y -f mpegts udp://239.0.0.2:1234?pkt_size=1316

To quickly try this out you can use the SRTRx Docker container from our toolbox and use the loopts Docker container to generate a test stream to transmit.

Generate an MPEG-TS stream to transport over SRT and view in VLC

To emulate the encoder we instead use VLC to verify that the stream is transported. On the sender side.

$ docker run --rm -v $PWD:/mnt eyevinntechnology/toolbox-loopts --withtc testfile.mp4 "srt://192.168.1.2:9998?pkt_size=1316"

And on the receiver side.

$ docker run --rm -p 9998:9998/udp eyevinntechnology/toolbox-srtrx --listener 0.0.0.0:9998 239.0.0.3:1234

Then open VLC with the following address to join the multicast stream:

udp://@239.0.0.3:1234

Using OBS and SRT

The SRT Transmitter in the toolbox can also take an RTMP stream and transport using SRT to an SRT Receiver. Spin up the SRTTx Docker container on the computer running for example OBS or Wirecast and you can use SRT instead of RTMP to transfer the signal to the cloud.l

Use SRT with OBS instead of RTMP

Start the SRTTx Docker container and given that the SRT Receiver is available on IP 192.168.1.6 use the following arguments.

$ docker run --rm -p 1935:1935 eyevinntechnology/toolbox-srttx --passthrough --inputtype=rtmp input_stream 192.168.1.6:9998

And on the receiver side run the following

$ docker run --rm -p 9998:9998/udp eyevinntechnology/toolbox-srtrx --listener 0.0.0.0:9998 239.0.0.3:1234

And again, to try this out we can use VLC to view the MPEG-TS stream that is received.

udp://@239.0.0.3:1234

Summary

In this article I have shown how you with ffmpeg can transport an MPEG-TS stream over the Internet using SRT as the protocol. I personally believe that we in a not so distant future will see more support for SRT on both the Sender and Receiver side as the SDK is available as open source and can easily (without a fee) be incorporated in the software. I would assume that Wirecast or OBS will soon have support for SRT given the number of companies now joining the SRT Alliance.

If you have any further questions and comments on this blog drop a comment below or tweet me on Twitter (@JonasBirme).

Eyevinn Technology is the leading independent consultant firm specializing in video technology and media distribution, and proud organizer of the yearly nordic conference Streaming Tech Sweden.

We are consultants sharing the passion for the technology for a media consumer of the future.