Try Live Demo

HLS, RTMP, DASH/CMAF, and SRT Streaming Using GStreamer 

In this blog we will see how to send stream from gstreamer to ant media using RMTP and SRT and we will also see how we can play 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 , what is a 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 RTMPRTSPWebRTC, and SRT for ingesting any video sources.

Which protocols are supported for egressing?

Ant Media Server supports WebRTCDASH(CMAF), 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, 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 visit here.

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.

what is gstreamer

Gstreamer provide wide range of plugins which 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 pipelines

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 gstreamer pipeline as a normal water pipeline.  water comes from the rivers through pipeline to water treatment plant and then goes through phases such as cleaning , disinfection , filtration , and then to our homes. In the same way the data flow though the pipeline and every element in the pipeline will perform various task on the data flowing thought the pipeline.

Gstreamer  provides various kind of element such as udpsrc for listen to udp data , filesrc for reading file 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 have a property of location udpsrc element have 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 left side of the pipeline  to right side as soon as 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 generate the test video and pass 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 generate the test video and pass 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.

For egressing make 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 (ingesting only)

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 GStreamer to Ant Media:

Sending Test Video stream

gst-launch-1.0 -v videotestsrc ! x264enc tune=zerolatency ! flvmux ! rtmpsink location=”rtmp://AntMedia_IP/{APP_NAME}?streamid={APP_NAME}/{StreamId} live=1″

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 (ingesting only)      

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

gst-launch-1.0 videotestsrc ! x264enc tune=zerolatency ! mpegtsmux ! srtsink uri=”srt://AntMedia_IP:4200?streamid={APP_NAME}/{streamid}”

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 (egressing only)

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:

gst-launch-1.0  souphttpsrc location=”http://AntMedia_IP:5080/{APP_NAME}/streams/{Streamid}.m3u8?token=undefined&subscriberId=undefined&subscriberCode=undefined” ! hlsdemux ! decodebin ! videoconvert ! videoscale ! autovideosink

DASH (egressing only)

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 :

gst-launch-1.0 souphttpsrc location=”http://AntMedia_IP:5080/{Appname}/streams/{streamid}/{streamid}.mpd?token=undefined&subscriberId=undefined&subscriberCode=undefined'” ! dashdemux ! decodebin ! videoconvert ! videoscale ! autovideosink

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.

Fundamental features

Categories: Tutorial

chatsimple