HLS, RTMP, DASH/CMAF, and SRT Streaming Using GStreamer — Ant Media Server

Ant Media Server
5 min readNov 29, 2022

In this blog, we will see how to send the stream from GStreamer to ant media using RMTP and SRT and we will also see how we can play the stream from Ant Media Server in Gstreamer using DASH and HLS. These protocols are widely used in streaming technologies. We will see what is GStreamer, How it works, How to install Gstreamer, and what is GStreamer-pipeline we will be constructing simple GStreamer pipelines to send and receive streams to AMS.

Streaming Protocols supported by Ant Media

Which protocols are supported for ingesting?

Ant Media Server supports RTMP, RTSP, WebRTC, and SRT for ingesting any video sources.

Which protocols are supported for egressing?

Ant Media Server supports WebRTC, and HLS protocols to deliver the streaming sessions. In addition, RTMP output is also provided for streaming purposes to any endpoint including Social Media.

You can learn more about these protocols here.

What is GStreamer

Gstreamer is a pipeline-based multimedia framework that links together a wide variety of media processing systems to complete complex workflows. Gstreamer can be used to build a wide range of applications. It an be used for anything related to streaming and multimedia-related applications.

Gstreamer is not a media player, codec converter or file format converter, or file streaming service but it can be used to build all of it.

Gstreamer Features

Gstreamer works on all major operating systems such as Linux, Android, Windows, Max OS X, and iOS, as well as most BSDs, commercial Unixes, Solaris, and Symbian. It has been ported to a wide range of operating systems, processors, and compilers. It runs on all major hardware architectures including x86, ARM, MIPS, SPARC, and PowerPC, on 32-bit as well as 64-bit, and little endian or big endian.

Pipelines can be visualized by dumping them to a .dot file and creating a PNG image from that

Resource-friendly plugins don’t waste memory

Multi-threaded pipelines are trivial and transparent to construct

For more information, you can visithere.

How Gstreamer Works

The framework is based on plugins that will provide the various codec and other functionality. The plugins can be linked and arranged in a pipeline.

GStreamer provides wide range of plugins that are responsible for various task

  • protocols handling
  • sources: for audio and video (involves protocol plugins)
  • formats: parsers, formaters, muxers, demuxers, metadata, subtitles
  • codecs: coders and decoders
  • filters: converters, mixers, effects.
  • sinks: for audio and video (involves protocol plugins)

Gstreamer provides bindings for various programming languages such as C , Python , Rust etc. https://gstreamer.freedesktop.org/bindings which can be used to construct GStreamer pipelines. GStreamer also provides a command line tool (gst-launch-1.0) for creating simple pipelines for testing purpose without writing any code. We will use this tool for creating our pipeline.

Think of the GStreamer pipeline as a normal water pipeline. water comes from the rivers through pipelines to the water treatment plants and then goes through phases such as cleaning, disinfection, filtration, and then to our homes. In the same way, the data flow through the pipeline, and every element in the pipeline will perform various tasks on the data flowing thought the pipeline.

GStreamer provides various kinds of elements such as udpsrc for listening to UDP data, filesrc for reading files from disk, filesink for writing a file to disk.udp sink for sending udp data. The elements can have different properties, for example, filesrc element has a property of location udpsrc element have the property of port, and likewise. you can list all the properties of elements using ( gst-launch-1.0 elment_name ) . these elements can be linked together to construct a pipeline. The data starts to flow from the left side of the pipeline to the right side as soon as the pipeline starts playing.

simple GStreamer pipelines :

we will construct simple GStreamer pipelines to understand the concept of pipelines in GStreamer. ! is used for connecting two elements.

gst-launch-1.0 videotestsrc pattern=1 ! autovideosink

videotestsrc generates the test video and passes the video buffer to autovideosink element which will then display the generated test video.

gst-launch-1.0 audiotestsrc ! volume volume=0.1 ! autoaudiosink

audiotestsrc generates the test video and passes the video buffer to autoaudiosink element which will then display the generated test video.

How to install Gstreamer :

Ubuntu :

Run the following command:

apt-get install libgstreamer1.0-dev libgstreamer-plugins-base1.0-dev libgstreamer-plugins-bad1.0-dev gstreamer1.0-plugins-base gstreamer1.0-plugins-good gstreamer1.0-plugins-bad gstreamer1.0-plugins-ugly gstreamer1.0-libav gstreamer1.0-doc gstreamer1.0-tools gstreamer1.0-x gstreamer1.0-alsa gstreamer1.0-gl gstreamer1.0-gtk3 gstreamer1.0-qt5 gstreamer1.0-pulseaudio Windows :

download the windows installer from https://gstreamer.freedesktop.org/download/#windows

Mac :

download the Mac installer from https://gstreamer.freedesktop.org/download/#macos

pipelines for connecting Ant media with Gstreamer

Note :

For ingesting make sure you enter the correct stream id and application name in the command line. You can see the ingested stream on the Ant Media web interface. Foregressing makes sure the stream is available to be consumed. And correct application name and stream id is entered. You can see whether the stream is available or not on the web interface.

RTMP streaming protocol, a TCP-based technology, was developed by Macromedia for streaming audio, video, and data over the Internet, between a Flash player and a server.

Sending RTMP stream from GStreamerto Ant Media:

Sending Test Video stream sending stream with mp4 file

gst-launch-1.0 filesrc location=test.mp4 ! qtdemux ! decodebin ! x264enc tune=zerolatency ! flvmux ! rtmpsink location=”rtmp://AntMedia_IP/{APP_Name}?streamid={APP_NAME}/{StreamId} live=1″

SRT is an open-source technology designed for reliable and low-latency streaming over unpredictable public networks. It works on top of UDP.

Sending SRT stream from GStreamer to Ant Media:

Sending Test Video stream sending stream with mp4 file

gst-launch-1.0 filesrc location=test.mp4 ! qtdemux ! decodebin ! x264enc tune=zerolatency ! mpegtsmux ! srtsink uri=srt://AntMedia_IP:4200?streamid={APP_NAME}/{StreamId}

HLS is an adaptive HTTP-based protocol used for transporting video and audio data/content from media servers to the end user’s device.

Receiving HLS stream in GStreamer from Ant Media:

DASH is a streaming method. DASH stands for “Dynamic Adaptive Streaming over HTTP” DASH breaks videos down into smaller chunks and encodes those chunks at different quality levels. This makes it possible to stream videos of different quality.

Receiving DASH stream in GStreamer from Ant Media :

Start using Ant Media Server for free now

Ant Media Server is a real-time streaming engine that provides highly scalable, ultra-low latency (WebRTC), and low latency (CMAF & HLS) video streaming solutions, with a dashboard to manage all streaming needs.

It is used by users from different segments such as education, live auctions, radio and TV broadcasts, service providers, government agencies, and gaming companies to enhance their business by using Ant Media Server and benefiting from its capabilities.

Originally published at https://antmedia.io on November 29, 2022.

--

--

Ant Media Server

Ant Media Server, open source software, supports publishing live streams with WebRTC and RTMP. It supports HLS(HTTP Live Streaming) and MP4 as well.