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
