Gstreamer中一些gst-launch常用命令

本文介绍GStreamer中gst-launch命令的应用实例,包括视频显示、摄像头采集、视频录制等场景,并演示了如何实现画中画、视频墙及添加文本等功能。

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

Gstreamer中一些gst-launch常用命令

Linux系统中使用gstreamer架构做对媒体开发时,gst-inspectgst-launch是两个非常使用的小工具,gst-inspect 在开发时用于查询库各个插件element的详细信息,后者用于在终端快速构建一条pipeline用于播放多媒体。下面列出我在以前的学习和项目开发时常用的gst-launch播放各种多媒体文件的实例:

一、gstreamer实现视频显示

gst-launch videotestsrc ! xvimagesink

二、gstreamer实现摄像头采集:

1、可以现实图像,但图像卡住不动

gst-launch v4l2src ! xvimagesink

2、摄像头视频显示正常

gst-launch v4l2src !video/x-raw-yuv,format=\(fourcc\)YUY2,width=640,height=480,framerate=15/1 !videorate ! videoscale ! ffmpegcolorspace ! xvimagesink

gst-launch v4l2src ! video/x-raw-yuv,width=640,height=480,framerate=15/1 !queue2 ! videorate ! videoscale ! ffmpegcolorspace ! xvimagesink

三、摄像头视频现实及保存为avi格式文件

gst-launch -e v4l2src !video/x-raw-yuv,format=\(fourcc\)YUY2,width=640,height=480,framerate=30/1 ! teename=srctee \

srctee. ! queue2 name=squeue ! ffmpegcolorspace ! xvimagesink \

srctee. ! queue2 name=fqueue ! videorate ! ffmpegcolorspace !ffenc_mpeg4 ! avimux ! filesink location=test.avi

四、将摄像头视频比例设置为16:9

gst-launch v4l2src ! video/x-raw-yuv,width=640,height=480,framerate=15/1 !aspectratiocrop aspect-ratio=16/9 ! ffmpegcolorspace ! xvimagesink

五、保存摄像头的视频为avi格式

gst-launch -e v4l2src ! video/x-raw-yuv, format=\(fourcc\)YUY2,framerate=30/1, width=640, height=480 ! videorate ! ffmpegcolorspace !ffenc_mpeg4 ! avimux ! filesink location=test.avi

六、多个流数据同时录制

gst-launch -e avimux name="muxer" ! filesink location=multi.avi\

v4l2src ! video/x-raw-yuv, format=\(fourcc\)YUY2, framerate=25/1,width=640, height=480 ! videorate ! ffmpegcolorspace ! ffenc_mpeg4 ! queue2 !muxer. \

pulsesrc ! audioconvert ! audioresample! lamemp3enc target=1 bitrate=64cbr=true ! queue2 ! muxer.

七、画中画

1、videomixer可以将两个或多个视频流混合到一起:

gst-launch -e videotestsrc pattern="snow" ! video/x-raw-yuv,framerate=10/1, width=200, height=150 ! videomixer name=mix ! \

ffmpegcolorspace ! xvimagesink videotestsrc !video/x-raw-yuv, framerate=10/1, width=640, height=360 ! mix.

2、GstVideoMixerPad能够改变Z轴和图像的位置

gst-launch videotestsrc pattern="snow" ! video/x-raw-yuv,framerate=10/1, width=200, height=150 ! \

videomixer name=mix sink_1::xpos=20 sink_1::ypos=20sink_1::alpha=0.5 sink_1::zorder=3 sink_2::xpos=100 sink_2::ypos=100sink_2::zorder=2 ! \

ffmpegcolorspace ! xvimagesink videotestsrc pattern=13 !video/x-raw-yuv, framerate=10/1, width=200, height=150 ! mix. \

videotestsrc ! video/x-raw-yuv, framerate=10/1, width=640,height=360 ! mix.

3、GstVideoMixerPad可以制定每个sink

gst-launch \

videomixer name=mix sink_1::xpos=20 sink_1::ypos=20sink_1::alpha=0.5 sink_1::zorder=3 sink_2::xpos=100 sink_2::ypos=100 sink_2::zorder=2! \

ffmpegcolorspace ! xvimagesink \

videotestsrc ! video/x-raw-yuv, framerate=10/1, width=640,height=360 ! mix.sink_0 \

videotestsrc pattern="snow" ! video/x-raw-yuv,framerate=10/1, width=200, height=150 ! mix.sink_1 \

videotestsrc pattern=13 ! video/x-raw-yuv, framerate=10/1,width=200, height=150 ! mix.sink_2

八、VideoBox可以用来制定视频框的大小和位置和apha混合透明度等

1、不透明

gst-launch -e videotestsrc pattern="snow" ! video/x-raw-yuv,framerate=10/1, width=200, height=150 ! videobox border-alpha=0 top=-100left=-100 ! \

videomixer name=mix ! ffmpegcolorspace ! xvimagesink videotestsrc !video/x-raw-yuv, framerate=10/1, width=640, height=360 ! mix.

2、指定透明度

gst-launch -e videotestsrc pattern="snow" ! video/x-raw-yuv,framerate=10/1, width=200, height=150 ! \

videobox border-alpha=0 alpha=0.6 top=-20 left=-25 !videomixer name=mix ! ffmpegcolorspace ! xvimagesink \

videotestsrc ! video/x-raw-yuv, framerate=10/1, width=640,height=360 ! mix.

3、添加边框

gst-launch -e videotestsrc pattern="snow" ! video/x-raw-yuv,framerate=10/1, width=200, height=150 ! \

videobox border-alpha=1.0 top=-2 bottom=-2 left=-2 right=-2 !videobox border-alpha=0 alpha=0.6 top=-20 left=-25 ! \

videomixer name=mix ! ffmpegcolorspace ! xvimagesinkvideotestsrc ! video/x-raw-yuv, framerate=10/1, width=640, height=360 ! mix.

九、VideoWall视频墙

gst-launch -e videomixer name=mix ! ffmpegcolorspace ! xvimagesink \

videotestsrc pattern=1 ! video/x-raw-yuv, framerate=5/1,width=320, height=180 ! videobox border-alpha=0 top=0 left=0 ! mix. \

videotestsrc pattern=15 ! video/x-raw-yuv, framerate=5/1,width=320, height=180 ! videobox border-alpha=0 top=0 left=-320 ! mix. \

videotestsrc pattern=13 ! video/x-raw-yuv, framerate=5/1,width=320, height=180 ! videobox border-alpha=0 top=-180 left=0 ! mix. \

videotestsrc pattern=0 ! video/x-raw-yuv, framerate=5/1,width=320, height=180 ! videobox border-alpha=0 top=-180 left=-320 ! mix. \

videotestsrc pattern=3 ! video/x-raw-yuv, framerate=5/1,width=640, height=360 ! mix.

十、TextOverlay 在视频上面添加文本,由textoverlay插件实现,可以设置文本的属性

gst-launch videotestsrc !video/x-raw-yuv,width=640,height=480,framerate=15/1 ! textoverlaytext="Hello" ! ffmpegcolorspace ! ximagesink

十一、TimeOverlay ,由timeoverlay插件实现

1、由timeoverlay插件实现

gst-launch videotestsrc ! timeoverlay ! xvimagesink

gst-launch -v videotestsrc ! video/x-raw-yuv, framerate=25/1, width=640,height=360 ! \

timeoverlay halign=left valign=bottom text="Streamtime:" shaded-background=true ! xvimagesink

2、cairotimeoverlay

gst-launch videotestsrc ! cairotimeoverlay ! ffmpegcolorspace ! xvimagesink

3、clockoverlay时钟

gst-launch videotestsrc ! cairotimeoverlay ! ffmpegcolorspace ! xvimagesink

gst-launch videotestsrc ! clockoverlay halign=right valign=bottomshaded-background=true time-format="%Y.%m.%D" ! ffmpegcolorspace !ximagesink

十二、录制视频为ogg格式,带时间和日期overlay

gst-launch -e v4l2src ! video/x-raw-yuv, format=\(fourcc\)YUY2,framerate=20/1, width=640, height=480 ! \

ffmpegcolorspace ! \

timeoverlay halign=right valign=top ! clockoverlayhalign=left valign=top time-format="%Y/%m/%d %H:%M:%S" ! \

tee name="splitter" ! queue2 ! xvimagesinksync=false splitter. ! \

queue2 ! videorate ! ffmpegcolorspace ! theoraenc bitrate=256! oggmux ! filesink location=webcam.ogg

十三、视频墙

gst-launch videomixer name=mix sink_1::xpos=20 sink_1::ypos=20sink_1::alpha=1.0 sink_1::zorder=3 sink_2::xpos=40 sink_2::ypos=40sink_2::zorder=2 ! ffmpegcolorspace ! xvimagesink \

uridecodebinuri=file:///mnt/hgfs/fedshare/source/video/loveStyle.mp4 ! ffmpegcolorspace !videoscale ! mix. \

uridecodebin uri=file:///mnt/hgfs/fedshare/source/video/davincieffect_480p30.mp4! ffmpegcolorspace ! videoscale ! mix. \

videotestsrc ! video/x-raw-yuv, framerate=10/1,width=800, height=540 ! mix.

十四、播放视频文件,带声音

gst-launch uridecodebinuri=file:///mnt/hgfs/fedshare/source/video/loveStyle.mp4 name=decoder \

decoder. ! audioconvert ! autoaudiosink \

decoder. ! ffmpegcolorspace ! xvimagesink

### 解决NVIDIA Jetson GStreamer gst-launch-1.0 RTSP转MP4录制不播放的问题 在处理NVIDIA Jetson平台上使用GStreamer通过`gst-launch-1.0`命令将RTSP流转换并保存为MP4文件遇到无法播放的情况时,有几个方面需要注意。 #### 安装必要的GStreamer组件 为了确保所有必需的插件都已安装,在Jetson平台上应执行如下命令来安装完整的GStreamer工具集及其开发库: ```bash sudo apt-get update && sudo apt-get upgrade -y sudo apt-get install gstreamer1.0-tools gstreamer1.0-alsa \ gstreamer1.0-plugins-base gstreamer1.0-plugins-good \ gstreamer1.0-plugins-bad gstreamer1.0-plugins-ugly \ gstreamer1.0-libav libgstreamer1.0-dev \ libgstreamer-plugins-base1.0-dev \ libgstreamer-plugins-good1.0-dev \ libgstreamer-plugins-bad1.0-dev[^1] ``` #### 正确配置GST_LAUNCH-1.0管道 当尝试从RTSP源捕获视频并将其实时编码成MP4格式存储到本地磁盘时,建议采用以下结构化的pipeline设置方法。这有助于创建兼容大多数媒体播放器的标准容器格式文件: ```bash gst-launch-1.0 rtspsrc location=rtsp://<your_rtsp_stream_url> ! decodebin ! x264enc tune=zerolatency bitrate=<desired_bitrate_in_kbps> ! mp4mux fragment-duration=5 ! filesink location=output.mp4 ``` 这里的关键点在于选择了合适的编解码器(`x264enc`)以及多路复用器(`mp4mux`),并且设置了合理的参数以适应不同的应用场景需求。特别是对于移动设备上的回放优化,可以通过调整比特率(bitrate)和其他选项获得更好的体验效果。 另外值得注意的是,如果目标是生成分片式的MP4文件以便于后续在线传输或即时观看,则可以在上述基础上进一步指定更短的时间间隔来进行片段划分操作,比如上面例子中的`fragment-duration=5`表示每五秒切分为一个新的片段。 #### 验证输出文件的有效性 完成录制之后,可以利用FFmpeg或其他第三方软件检查生成的MP4文件是否具有正确的元数据标签和索引表项。有时即使看起来正常的视频也可能因为缺少这些信息而导致某些特定类型的播放程序读取失败。修复这类问题的一个简单方式就是重新封装一次而不改变原始内容本身: ```bash ffmpeg -i output.mp4 -c copy fixed_output.mp4 ``` 此过程不会影响音画质量,仅是对内部结构进行了整理优化,从而提高了与其他应用程序之间的互操作性和稳定性。
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值