Gstreamer学习流水账

本文详细记录了GStreamer在Linux上的使用,包括检查已安装的多媒体插件,如videosink和v4l2插件。通过示例展示了V4L2设备的打开和解码过程,以及videoconvert组件在解决视频流不匹配问题中的关键作用。此外,还演示了使用audiotestsrc和pulsesink进行音频测试。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Gstreamer是Linux上的一套多媒体框架,集采集,编码,解码,渲染,滤镜等功能一条龙的媒体解决方案,它的调度能力和扩展能力非常出色,被广泛应用在各种多媒体方案上 ,这里总结一些学习记录和心得,采用编年体,比较自由,到最后肯定会是一篇流水账。

1.查看系统安装了哪些插件

czl@czl-VirtualBox:~/WorkSpace$ gst-inspect-1.0 |grep -i videosink
inter:  intervideosink: Internal video sink
autodetect:  autovideosink: Auto video sink
decklink:  decklinkvideosink: Decklink Video Sink
debugutilsbad:  fpsdisplaysink: Measure and show framerate on videosink
debugutilsbad:  fakevideosink: Fake Video Sink
cluttergst3:  clutterautovideosink: Generic bin

czl@czl-VirtualBox:~/WorkSpace$ gst-inspect-1.0 |grep -i v4l
video4linux2:  v4l2src: Video (video4linux2) Source
video4linux2:  v4l2sink: Video (video4linux2) Sink
video4linux2:  v4l2radio: Radio (video4linux2) Tuner
video4linux2:  v4l2deviceprovider (GstDeviceProviderFactory)
czl@czl-VirtualBox:~/WorkSpace$ 

caozilong@caozilong-Vostro-3268:~/Workspace/camera$ v4l2-ctl --list-devices
Integrated Camera: Integrated C (usb-0000:00:14.0-2):
	/dev/video0
	/dev/video1

caozilong@caozilong-Vostro-3268:~/Workspace/camera$ 

V4L2 plugin注册:

gstv4l2videodec.c启动解码任务:

最终是调用gst-base包中的gst_video_decoder_xxx plugin进行解码的。

V4L2设备打开:


2.videoconvert组件的作用,当不加入videoconvert组件时,以下两个命令会出错:

gst-launch-1.0 filesrc location=./test.mp4  ! decodebin  ! ximagesink
gst-launch-1.0 filesrc location=./test.mp4  ! decodebin  ! xvimagesink
czl@czl-VirtualBox:~/WorkSpace/ffserver$ gst-launch-1.0 filesrc location=./test.mp4  ! decodebin  ! ximagesink
Setting pipeline to PAUSED ...
Pipeline is PREROLLING ...
Redistribute latency...
Redistribute latency...
ERROR: from element /GstPipeline:pipeline0/GstDecodeBin:decodebin0/GstQTDemux:qtdemux0: Internal data stream error.
Additional debug info:
qtdemux.c(6073): gst_qtdemux_loop (): /GstPipeline:pipeline0/GstDecodeBin:decodebin0/GstQTDemux:qtdemux0:
streaming stopped, reason not-negotiated (-4)
ERROR: pipeline doesn't want to preroll.
Setting pipeline to NULL ...
Freeing pipeline ...
czl@czl-VirtualBox:~/WorkSpace/ffserver$ gst-launch-1.0 filesrc location=./test.mp4  ! decodebin  ! xvimagesink
Setting pipeline to PAUSED ...
Pipeline is PREROLLING ...
Redistribute latency...
Redistribute latency...
ERROR: from element /GstPipeline:pipeline0/GstDecodeBin:decodebin0/GstQTDemux:qtdemux0: Internal data stream error.
Additional debug info:
qtdemux.c(6073): gst_qtdemux_loop (): /GstPipeline:pipeline0/GstDecodeBin:decodebin0/GstQTDemux:qtdemux0:
streaming stopped, reason not-negotiated (-4)
ERROR: pipeline doesn't want to preroll.
Setting pipeline to NULL ...
Freeing pipeline ...
czl@czl-VirtualBox:~/WorkSpace/ffserver$ 

但是,加入videoconvert后,命令正确执行:

gst-launch-1.0 filesrc location=./test.mp4  ! decodebin ! videoconvert ! ximagesink
gst-launch-1.0 filesrc location=./test.mp4  ! decodebin ! videoconvert ! xvimagesink

3.gst audio sink test

gst-launch-1.0 audiotestsrc ! pulsesink
czl@czl-RedmiBook-14:~$ gst-inspect-1.0 pulseaudio
Plugin Details:
  Name                     pulseaudio
  Description              PulseAudio plugin library
  Filename                 /usr/lib/x86_64-linux-gnu/gstreamer-1.0/libgstpulseaudio.so
  Version                  1.14.5
  License                  LGPL
  Source module            gst-plugins-good
  Source release date      2019-05-29
  Binary package           GStreamer Good Plugins (Ubuntu)
  Origin URL               https://launchpad.net/distros/ubuntu/+source/gst-plugins-good1.0

  pulsedeviceprovider: PulseAudio Device Provider
  pulsesrc: PulseAudio Audio Source
  pulsesink: PulseAudio Audio Sink

  3 features:
  +-- 2 elements
  +-- 1 device providers

czl@czl-RedmiBook-14:~$

结束! 

### GStreamer入门教程及相关资源 GStreamer 是一个用于创建多媒体应用程序的强大框架,提供了丰富的工具和库来处理音频、视频和其他数据流。以下是关于如何学习和使用 GStreamer 的一些关键点: #### 1. 基础概念 GStreamer 提供了一组核心组件,包括元素(Elements)、管道(Pipelines)以及总线(Bus)。这些组件共同协作以实现复杂的媒体处理任务[^1]。 - **Element**: 这是最小的功能单元,可以是一个源(Source),过滤器(Filter)或者是汇(Sink)。 - **Pipeline**: 它定义了一个完整的媒体流程路径,由多个串联起来的 Elements 组成。 - **Bus**: 总线机制允许应用层监听来自 Pipeline 中发生的事件或消息,比如错误报告或者播放完成的通知[^2]。 #### 2. 初学者指南 对于刚开始接触 GStreamer 的开发者来说,可以从以下几个方面入手: ##### a. 学习命令行操作 通过简单的 shell 命令快速了解各个模块的工作方式是一项非常有用的技能。例如,`gst-launch-1.0` 工具可以帮助用户无需编写任何代码就能测试不同的 pipeline 配置。 ```bash $ gst-launch-1.0 playbin uri=file:///path/to/your/video.mp4 ``` 此命令会启动一个基于指定 URI 文件的简单播放器实例。 ##### b. 探索可用插件及其属性 利用 `gst-inspect-1.0` 可查看系统上安装的所有 plugins 并获取它们的具体参数说明。 ```bash $ gst-inspect-1.0 videotestsrc ``` 上述例子展示了名为 'videotestsrc' 插件的相关详情。 ##### c. 实践编程接口(APIs) 尽管可以通过 CLI 方便地试验各种设置组合,但最终大多数项目还是需要借助 API 来定制化解决方案。官方文档覆盖了 C/C++ 版本的主要函数调用模式;而对于其他语言绑定的支持情况,则需查阅对应平台上的额外资料[^3]。 下面给出一段 Python 范例演示怎样建立并控制 basic audio playback: ```python import gi gi.require_version('Gst', '1.0') from gi.repository import Gst, GObject def main(): # 初始化 gstreamer 库环境变量 Gst.init(None) # 创建必要的 element 对象 player = Gst.ElementFactory.make("playbin", "player") if not player: print ("Not all elements could be created.") exit(-1) # 设置 media location 属性 player.set_property("uri","file:///path/to/audio.wav") # 开始播放过程 ret = player.set_state(Gst.State.PLAYING) if ret == Gst.StateChangeReturn.FAILURE: print("Unable to set the pipeline to the playing state.") exit(-1) bus = player.get_bus() while True: msg = bus.timed_pop_filtered( Gst.CLOCK_TIME_NONE, Gst.MessageType.ERROR | Gst.MessageType.EOS ) if msg: break player.set_state(Gst.State.NULL) if __name__ == '__main__': main() ``` 这段脚本实现了从本地加载声音文件直至结束整个生命周期的过程管理。 #### 3. 更多参考资料推荐 除了前面提到的内容外,还有许多在线课程、书籍可供进一步深入研究: - 官方网站提供详尽的手册和技术博客更新。 - Stack Overflow 社区活跃讨论解决实际遇到的各种难题。 - GitHub 上开源项目的案例分享也是不可忽视的学习途径之一。
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

papaofdoudou

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

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

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

打赏作者

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

抵扣说明:

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

余额充值