Basics

gstreamer consists of gst-launch-1.0 and gst-inspect-1.0
gst-launch-1.0 launches a new stream pipeline with the properties you set.
gst-inspect-1.0 provides information on installed gstreamer modules
The ! connects the filters, but in gstreamer terminology they are called pads. The entire system of pads and filters is called a pipeline.


the most basic stream

This stream launches the video test source and pipes it to the screen.
​​​gst-launch-1.0 videotestsrc ! autovideosink​


Adding caps to the stream

Gstreamer has a filter called capabilities, caps for short. That changes some properties of the stream.
​​​gst-launch-1.0 videotestsrc ! video/x-raw,width=640,height=480 ! autovideosink​​​
this is actually a short hand for
​​​gst-launch-1.0 videotestsrc ! capsfilter caps=video/x-raw,width=640,height=480 ! autovideosink​


Feed from the camera


Feed from screengrabber


Encode your stream

The videostreams that previously has been piped to autovideosink is now piped to the encoder pad with for example ​​! jpegdec​​​ for mjpeg encoding. Those encoders have multiple elements that can be changed to create the stream you want. A complete list can be provided ​​by gst-inspect-1.0 encoder-name​​.


Payload the stream

Payloading is the step of packing the data, raw or compressed into a network protocol. You can either use GDP (Gstreamer data protocol) or RTP (Real time protocol).
The payloader pad is simply added after the decoder pad in this fashion:
​​​! jpegenc ! rtpjpegpay​​​
If you have a dedicated high bandwidth connection you could skip the encoding step and just payload the raw stream:
​​​! rtpvrawpay​


Send the stream

There are multiple ways to send this stream to be used by other recipients on a network. ​​gst-inspect-1.0 | grep sink​​​ will show you all possibilities. In this tutorial I will only cover the autovideosink, the udpsink and the multiudpsink.
udpsink and multiudpsink are two similar sinks. The data piped to them is sent to one (udpsink) or several (multiudpsink) udp-adresses. ​​​udpsink host=127.0.0.1 port=5000​​​ sends the stream to the localhoast ​​multiudpsink clients=127.0.0.1:5000,127.0.0.1:5004,192.168.2.15:2000​​ sends it to three different destinations.


Receive the stream

​gst-launch-1.0 udpsrc port=5000​​​ will give you a connection, but that is not going to be interpreted correctly. To do that we need to add the caps filter from the sender.
​​​gst-launch-1.0 udpsrc port=5000 caps =xxx​


Unpack the payload

​! rtpjpegdepay​​ are the pads that can handle the unpacking.


Decode the format

The decoding of the format is also mostly quite straight forward.
add the pads ​​​! jpegdec​​ to your pipeline to decode the video.


Display the video

add ​​! autovideosink​​ again and it will be displayed on your screen.


Gst-inspect

​gst-inspect-1.0 | grep sink​​​ gives you a list of available sinks and ​​gst-inspect-1.0 | grep src​​​ gives you the available sources.
​​​gst-inspect-1.0 fpsdisplaysink​​ shows information on a special kind of video sink for example.


example

//sender
gst-launch-1.0 videotestsrc ! capsfilter caps=video/x-raw,width=640,height=480 ! jpegenc ! rtpjpegpay ! udpsink host=dest_ip_addr port=5555
//receiver
gst-launch-1.0 udpsrc port=5555 ! capsfilter caps=application/x-rtp,encoding-name=JPEG,payload=26 ! rtpjpegdepay ! jpegdec ! autovideoconvert ! autovideosink

参考文章

  1. ​Gstreamer basic real time streaming tutorial​
  2. 2.