GStreamer 命令演示,音频视频播放及混流的演示 -- TerryHe - 博客园

GStreamer 是一个用于处理音视频的开源开发包,其中提供了很方便的命令行模式,可以使用命令快速测试音视频处理的效果,然后再用代码进行实现。

GStreamer 基础知识的介绍可以参考这个文档:https://www.ibm.com/developerworks/cn/linux/l-gstreamer/

GStreamer 的安装也很简单,在这里下载安装包 https://gstreamer.freedesktop.org/download/ 然后将安装目录下的 bin 文件夹设置到 PATH 环境变量中就可以了,如 D:\gstreamer\1.0\x86_64\bin

下面是一些音视频命令的处理范例,可以直接复制到命令行中运行。在 bash 命令行中可以直接运行,如果使用 windows cmd,需要把 \ 和 回车 去除后运行

注意感叹号后面必须要有一个空格,否则执行会报错

播放当前目录下的音频或视频

gst-launch-1.0 filesrc location=abc.mp3 ! decodebin ! audioconvert ! audioresample ! autoaudiosink
gst-launch-1.0 filesrc location=111.mp4 ! decodebin ! autovideosink

产生一个测试视频画面

gst-launch-1.0 -v videotestsrc pattern=ball name=left ! autovideosink

混流两个测试画面

gst-launch-1.0 -v videotestsrc ! video/x-raw,format=AYUV,framerate=\(fraction\)5/1,width=320,height=240 ! \
videomixer name=mix background=1 sink_0::alpha=1 sink_1::alpha=1 ! \
videoconvert ! glimagesink \
videotestsrc pattern=1 ! \
video/x-raw,format=AYUV,framerate=\(fraction\)10/1,width=100,height=100 ! \
videobox border-alpha=0 top=-70 bottom=-70 right=-220 ! mix.

分离一个 MP4 的视频和音频并分别播放

gst-launch-1.0 filesrc location=a.mp4 ! qtdemux name=demux  demux.audio_0 ! queue ! decodebin ! audioconvert ! audioresample ! autoaudiosink \
demux.video_0 ! queue ! decodebin ! videoconvert ! videoscale ! autovideosink

只分离视频并播放

gst-launch-1.0 filesrc location=a.mp4 ! qtdemux name=demux demux.video_0 ! queue ! decodebin ! videoconvert ! videoscale ! autovideosink

只分离视频并设置 video 大小 和 videobox

gst-launch-1.0 filesrc location=a.mp4 ! qtdemux name=demux demux.video_0 ! decodebin ! videoscale ! \
video/x-raw,width=100,height=100 ! \
videobox border-alpha=0 top=-70 bottom=-70 right=-220 ! \
videoconvert ! autovideosink

混流两个视频文件,一左一右

gst-launch-1.0 filesrc location=a.mp4 ! qtdemux name=demux demux.video_0 ! queue ! decodebin ! videoscale ! videoconvert ! \
video/x-raw,format=AYUV,width=200,height=200 ! \
videobox border-alpha=0 top=-70 bottom=-70 right=-220 ! \
videomixer name=mix background=1 sink_0::alpha=1 sink_1::alpha=1 ! \
autovideosink \
filesrc location=b.mp4 ! qtdemux name=demux2 demux2.video_0 ! queue ! decodebin ! videoscale ! videoconvert ! \
video/x-raw,format=AYUV,width=200,height=200 ! \
videobox border-alpha=0 top=-70 bottom=-70 left=-220 ! mix.

混流两个视频并播放声音

gst-launch-1.0 filesrc location=a.mp4 ! qtdemux name=demux demux.video_0 ! queue ! decodebin ! videoscale ! videoconvert ! \
video/x-raw,format=AYUV,width=200,height=200 ! \
videobox border-alpha=0 top=-70 bottom=-70 right=-220 ! \
videomixer name=mix background=1 sink_0::alpha=1 sink_1::alpha=1 ! \
autovideosink \
filesrc location=b.mp4 ! qtdemux name=demux2 demux2.video_0 ! queue ! decodebin ! videoscale ! videoconvert ! \
video/x-raw,format=AYUV,width=200,height=200 ! \
videobox border-alpha=0 top=-70 bottom=-70 left=-220 ! mix. \
demux.audio_0 ! queue ! decodebin ! audioconvert ! audioresample ! autoaudiosink \
demux2.audio_0 ! queue ! decodebin ! audioconvert ! audioresample ! autoaudiosink
posted @ 2017-10-23 12:02  hejiangyuan  阅读(9030)  评论(5编辑  收藏  举报