GStreamer是什么?
GStreamer是一个全平台的多媒体框架,当前最新版本是1.6
基于GObject,C语言开发的,另外GStreamer的插件机制很牛,不依赖头文件,不需要重新编译GStreamer
当前主要版本有:
- 0.10 (2005.5)
- 性能差
- 使用广泛
- caps跟buffer/memory绑定很紧
- 1.0 (2007)
- 嵌入式平台
- GPU
- 动态pipeline
- 更高的性能
- GstMemory
- 可以管理GPU,DMA buf, host Memory ,DRM memory等
概念介绍
pipeline
pipeline是GStreamer的核心, pipeline描述了媒体流的处理方法。gstreamer根据pipeline来处理任务.
source:数据来源,可能是file、http、rtp等.
demux: 负责把容器里的音视频数据剥离出来,然后分别送给audio\video decoder.
decoder:解码,然后把解完后的数据(yuv、pcm)送给audio\video output输出.
output:负责将decoder过来的数据呈现出来.
如果把数据想象成流水的话,每个模块的功能虽然不同,但是他们大致抽象的功能都是接收上个模块过来的数据,然后加工把加工后的数据送到下一个模块。
把上述这些模块通过某种方式连接起来,就形成了一个流水线(pipeline),这个流水线就是一个media播放器。
GStreamer 就是把每个模块都看做是一个Element,然后构建了连接和操作这些Element的方法,用户可以通过自己的需求把不同的Elements 排列组合,形成一个又一个的不同的pipeline。
element
各个处理模块都可以称为element,或者说是plugins,有如下这些类别:
- Protocols: 负责各种协议处理,file,http,rtsp等
- Sources: 负责数据源的处理,例如摄像头输入,
- formats: 封装、解封装
- codecs: 编解码器
- Sinks: 数据流的目的地,比如说显示,或者写入文件
另外根据质量及协议,还有下面的分类:
- gst-plugins-base: gstreamer应用所需的必要插件。
- gst-plugins-good: 高质量的采用LGPL授权的插件。
- gst-plugins-ugly: 高质量,但使用了GPL等其他授权方式的库的插件,比如使用GPL的x264,x265。
- gst-plugins-bad: 质量有待提高的插件,成熟后可以移到good插件列表中。
- gst-libav: 对libav封装,使其能在gstreamer框架中使用。
pad
每一个element都有对应的输入/输出口
bus
GStreamer里的消息机制,其实可以理解为控制各组件的一个全局的通道
pipeline的字符串描述方法
时间
Stream time: 视频流的时间
Running time: pipeline处理的时间
cock time: 整体的时间
position tracking and seeking
可以调整整个pipeline的时间
Position tracking and seeking
pipeline控制
- 数据输入给pipeline
- 从pipeline读数据出来
- 调整pipeline的速度,长度,起始点
- 监控pipeline的数据处理
动态pipeline
可以利用动态pipeline来对流做切分
GStreamer基础教程03——动态pipeline_gstreamer pipeline-CSDN博客
pipeline喂数据
GStreamer基础教程08——pipeline的快捷访问_gst_util_uint64_scale_int-CSDN博客
如何安装
在官网有一个帮助文档: Installing GStreamer
下面主要讲一下如何在alios(centos)机器上安装.
- 为了规避专利问题,gstreamer默认不安装x264和x265解码,
sudo rpm -ivh http://download1.rpmfusion.org/free/el/updates/7/x86_64/r/rpmfusion-free-release-7-4.noarch.rpm
sudo rpm -ivh http://download1.rpmfusion.org/nonfree/el/rpmfusion-nonfree-release-7.noarch.rpm
sudo rpm -ivh http://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
sudo yum install http://mirror.centos.org/centos/7/os/x86_64/Packages/libva-1.8.3-1.el7.x86_64.rpm
sudo yum -y install gstreamer-ffmpeg gstreamer-plugins-bad gstreamer-plugins-ugly gstreamer1-libav
pipeline生成构件图
【Gstreamer】如何生成pipeline构件图-CSDN博客
实用工具介绍
gst-launch
gst-lauch 启动gstreamer的pieline,pipeline由字符串描述
video/x-raw-yuv,width=200,height=200为一个过滤器,只允许设置的数据通过
/usr/bin/gst-launch-0.10 -e \
videomixer name=mix sink_0::xpos=0 sink_0::ypos=0 sink_0::zorder=1 sink_1::xpos=200 sink_1::ypos=200 sink_1::alpha=1 sink_1::zorder=2 ! \
ffmpegcolorspace ! \
x264enc bitrate=512 ! \
mpegtsmux ! filesink location="./test2.ts" \
filesrc location="1579162445215.mp4" ! \
qtdemux name=demux demux.video_00 ! \
queue ! \
ffdec_h264 ! \
video/x-raw-yuv ! \
mix.sink_0 \
filesrc location="./Cactus.1920x1080.I420_20000kbps.h264.mp4" ! \
qtdemux name=demux1 demux1.video_00 ! \
ffdec_h264 ! \
videoscale ! video/x-raw-yuv,width=200,height=200 ! \
mix.sink_1\
gst-inspect
插件列表查询
执行gst-inspect可以列出所有支持的插件
gst-inspect
dvdlpcmdec: dvdlpcmdec: DVD LPCM Audio decoder
realmedia: rmdemux: RealMedia Demuxer
realmedia: rademux: RealAudio Demuxer
realmedia: rdtdepay: RDT packet parser
realmedia: rdtmanager: RTP Decoder
realmedia: rtspreal: RealMedia RTSP Extension
realmedia: pnmsrc: PNM packet receiver
dvdsub: dvdsubdec: DVD subtitle decoder
dvdsub: dvdsubparse: DVD subtitle parser
cdio: cdiocddasrc: CD audio source (CDDA)
faad: faad: AAC audio decoder
mpeg2dec: mpeg2dec: mpeg1 and mpeg2 video decoder
asf: asfdemux: ASF Demuxer
asf: rtspwms: WMS RTSP Extension
asf: rtpasfdepay: RTP ASF packet depayloader
amrwbdec: amrwbdec: AMR-WB audio decoder
amrnb: amrnbdec: AMR-NB audio decoder
amrnb: amrnbenc: AMR-NB audio encoder
a52dec: a52dec: ATSC A/52 audio decoder
ffvideoscale: ffvideoscale: FFMPEG Scale element
mimic: mimenc: Mimic Encoder
mimic: mimdec: Mimic Decoder
mpegaudioparse: xingmux: MP3 Xing muxer
mpegaudioparse: mp3parse: MPEG1 Audio Parser
rtmp: rtmpsrc: RTMP Source
...
geometrictransform: kaleidoscope: kaleidoscope
geometrictransform: diffuse: diffuse
geometrictransform: circle: circle
dataurisrc: dataurisrc: data: URI source element
gstrtpmanager: gstrtpssrcdemux: RTP SSRC Demux
gstrtpmanager: gstrtpsession: RTP Session
gstrtpmanager: gstrtpptdemux: RTP Demux
gstrtpmanager: gstrtpjitterbuffer: RTP packet jitter-buffer
gstrtpmanager: gstrtpbin: RTP Bin
h264parse: legacyh264parse: H264Parse
opus: rtpopuspay: RTP Opus payloader
opus: rtpopusdepay: RTP Opus packet depayloader
opus: opusparse: Opus audio parser
opus: opusdec: Opus audio decoder
opus: opusenc: Opus audio encoder
fragmented: hlsdemux: HLS Demuxer
rfbsrc: rfbsrc: Rfb source
rtsp: rtpdec: RTP Decoder
rtsp: rtspsrc: RTSP packet receiver
videomeasure: measurecollector: Video measure collector
videomeasure: ssim: SSim
aiff: aiffmux: AIFF audio muxer
aiff: aiffparse: AIFF audio demuxer
tta: ttadec: TTA audio decoder
tta: ttaparse: TTA file parser
replaygain: rgvolume: ReplayGain volume
replaygain: rglimiter: ReplayGain limiter
replaygain: rganalysis: ReplayGain analysis
audioconvert: audioconvert: Audio converter
gdkpixbuf: gdkpixbufscale: GdkPixbuf image scaler
gdkpixbuf: gdkpixbufsink: GdkPixbuf sink
gdkpixbuf: gdkpixbufdec: GdkPixbuf image decoder
audioresample: audioresample: Audio resampler
camerabin: camerabin: Camera Bin
staticelements: bin: Generic bin
staticelements: pipeline: Pipeline object
Total count: 215 plugins (1 blacklist entry not shown), 1085 features
插件用法查询
可以了解到插件的输入/输出,以及对应插件的能力,即能够处理的输入,
例如下面这个videomixer,处理的是多路视频流的合入,可以支持N个输入
gst-inspect videomixer
Factory Details:
Long name: Video mixer
Class: Filter/Editor/Video
Description: Mix multiple video streams
Author(s): Wim Taymans <wim@fluendo.com>
Rank: primary (256)
Plugin Details:
Name: videomixer
Description: Video mixer
Filename: /usr/lib64/gstreamer-0.10/libgstvideomixer.so
Version: 0.10.31
License: LGPL
Source module: gst-plugins-good
Source release date: 2012-02-20
Binary package: Fedora gstreamer-plugins-good package
Origin URL: http://download.fedora.redhat.com/fedora
GObject
+----GstObject
+----GstElement
+----GstVideoMixer
Implemented Interfaces:
GstChildProxy
Pad Templates:
SINK template: 'sink_%d'
Availability: On request
Has request_new_pad() function: gst_videomixer_request_new_pad
Capabilities:
video/x-raw-yuv
format: AYUV
width: [ 1, 2147483647 ]
height: [ 1, 2147483647 ]
framerate: [ 0/1, 2147483647/1 ]
video/x-raw-rgb
gst-discoverer-0.10
可以用这个命令来看视频流文件的相关属性
$ gst-discoverer-0.10 ./test2.ts -a [1/1835]
Done discovering file:///home/qingfu.cqf/./test2.ts
Topology:
container: MPEG-2 Transport Stream
video: H.264
Properties:
Duration: 0:01:27.860696872
Seekable: yes
qingfu.cqf@iZ8vb1nz5l71xtpntk1vuiZ ~
$ gst-discoverer-0.10 ./test2.ts -v
Analyzing file:///home/qingfu.cqf/./test2.ts
Done discovering file:///home/qingfu.cqf/./test2.ts
Topology:
container: video/mpegts, systemstream=(boolean)true, packetsize=(int)188
video: video/x-h264, stream-format=(string)byte-stream, alignment=(string)nal
Codec:
video/x-h264, stream-format=(string)byte-stream, alignment=(string)nal
Additional info:
None
Width: 640
Height: 360
Depth: 0
Frame rate: 0/1
Pixel aspect ratio: 1/1
Interlaced: false
Bitrate: 0
Max bitrate: 0
Tags:
None
Properties:
Duration: 0:01:27.860696872
Seekable: yes
两个video合流示例
下面是一个示例,文件两个文件中读取视频文件,然后合并输出到同一个文件中.
pipeline是下面这个样子的
/usr/bin/gst-launch-0.10 -e \
videomixer name=mix sink_0::xpos=0 sink_0::ypos=0 sink_0::zorder=1 sink_1::xpos=200 sink_1::ypos=200 sink_1::alpha=1 sink_1::zorder=2 ! \
ffmpegcolorspace ! \
x264enc bitrate=512 ! \
mpegtsmux ! filesink location="./test2.ts" \
filesrc location="1579162445215.mp4" ! \
qtdemux name=demux demux.video_00 ! \
queue ! \
ffdec_h264 ! \
video/x-raw-yuv ! \
mix.sink_0 \
filesrc location="./Cactus.1920x1080.I420_20000kbps.h264.mp4" ! \
qtdemux name=demux1 demux1.video_00 ! \
ffdec_h264 ! \
videoscale ! video/x-raw-yuv,width=200,height=200 ! \
mix.sink_1\
效果如下:
同一个视频流做两次转码
pipeline:
/usr/bin/gst-launch-0.10 -e \
filesrc location="1579162445215.mp4" ! \
qtdemux name=demux demux.video_00 ! \
queue ! \
ffdec_h264 ! \
tee name=decxxxx ! \
x264enc bitrate=512 ! \
mpegtsmux ! \
filesink location="./test.ts" \
decxxxx. ! queue ! x264enc bitrate=1024 ! \
mpegtsmux ! filesink location="./test1.ts" \
插件说明
基础插件
queue
queue会创建一个新的线程
编译
GStreamer 包含在所有 Linux 发行版中。我们建议使用最新版本的快速移动发行版,例如 Fedora、Ubuntu(非 LTS)、Debian sid 或 OpenSuse 来获取最新的 GStreamer 版本。
安装好gstreamer,可以基于gstreamer来开发自己的应用,编译方面需要加 pkg-config --cflags --libs gstreamer-1.0
即可
g++ -o test ./main.cpp -I /usr/include/gstreamer-1.0/ -I /usr/include/glib-2.0/ `pkg-config --cflags --libs gstreamer-1.0`
参考材料
- gst-doc
下面这里可以看到example的讲解
Basic tutorial 1: Hello world! - 入门的一个视频
https://v.youku.com/v_show/id_XNDEyNjEyMzAw.html - 一些示例
http://wiki.oz9aec.net/index.php/Gstreamer_cheat_sheet#Video_Wall:_Live_from_Pluto - 安装x265codec
404 Not Found
gstreamer编译
编译过程参考这里,需要特别注意的我列到下面
Building from source using Cerbero
demon&tutorials
gstreamer插件工作原理与流程分析_gsteamet原理-CSDN博客
相见恨晚之gstreamer核心源码走读typefind原理浅析(二)_error debug information: gsttypefindelement.c(1231-CSDN博客