gstreamer入门

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.
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

luckywang1103

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值