环境准备
ubuntu发行版22.04,该发行版内置Gstreamer1.20.1,gstreamer源码最新版本为1.20.3,差距不大
下载gstreamer源码
下载gstreamer源码
安装git
sudo apt install -y git
fuqiang@fuqiang-VivoBook:~/Workspace/gstreamer$ git --version
git version 2.34.1
下载gstreamer
git clone https://gitlab.freedesktop.org/gstreamer/gstreamer.git
git checkout --track -b 1.20 origin/1.20 --->1.20是目前最新版本的稳定分支,最新的小版本号为1.20.3
准备编译环境
安装meson
gstreamer1.60以后(不包含1.60),使用meson+ninja来构建
sudo apt install -y meson
fuqiang@fuqiang-VivoBook:~/Workspace/gstreamer$ meson --version
0.61.2
安装glib
gstreamer是基于glib-gobject来实现的
sudo apt install -y libglib2.0-dev
安装libsoup
sudo apt install -y libsoup2.4-dev
安装libunwind
1.下载包,http://download.savannah.nongnu.org/releases/libunwind/
2. ./configure
3.make
4.sudo make install
安装libdw
sudo apt install -y libdw-dev
安装g-ir-scanner
系统中搜索g-ir-scanner,然后将其copy到/usr/lib/下,给予执行权限
安装gobject-introspection-1.0
sudo apt-get install -y libgirepository1.0-dev
安装gtk+-3.0
sudo apt-get install -y libgtk-3-dev
安装hotdoc
sudo apt-get install -y libjson-glib-devsudo apt install -y cmake python3-pip
sudo pip3 install hotdoc
安装xgettext
系统中搜索xgettext,复制到/usr/bin/下,并给予执行权限
安装alsa
sudo apt-get install -y libasound2-dev
安装cdda_paranoia
sudo apt install -y cdparanoia
还不行将cdparanoia先注释掉
安装libvisual-0.4
sudo apt install libvisual-0.4-dev
安装xv
打开终端输入 sudo snap install xv --edge,如果不能正常安装则按照提示输入 sudo snap install xv --edge --devmode即可安装成功
安装SDL2
sudo apt-get install -y libsdl2-2.0 libsdl2-dev libsdl2-mixer-dev libsdl2-image-dev libsdl2-ttf-dev libsdl2-gfx-dev
安装qt5
sudo apt-get install -y clang qtbase5-dev qtchooser qt5-qmake qtbase5-dev-tools qtcreator
sudo apt-get install -y qt5*
安装bz2
sudo apt install -y libbz2-dev
安装nasm/yasm
sudo apt install -y nasm yasm
安装gettext
sudo apt-get install -y gettext
编译安装
创建out目录
cd gstreamer
mkdir out
编译
meson out
cd out
ninja
sudo ninja install
带参数编译示例
meson --reconfigure -Dauto_features=enabled -Dgst-plugins-base:opus=disabled -Dgst-plugins-base:ogg=disabled out
异常处理
异常1
subprojects/gstreamer/gst/parse/meson.build:7:0: ERROR: Program 'flex win_flex' not found or not executable
解决方案:
sudo apt install -y flex
异常2
subprojects/gstreamer/gst/parse/meson.build:34:0: ERROR: Program 'bison win_bison' not found or not executable
解决方案:
sudo apt install -y bison
异常3
fuqiang@fuqiang-VivoBook:~/Workspace/gstreamer/gstreamer/out$ninja
ninja: error: 'subprojects/gst-plugins-bad/gst-libs/gst/transcoder/transcoder-enumtypes.h', needed by 'subprojects/gst-devtools/validate/tools/gst-validate-transcoding-1.0.p/gst-validate-transcoding.c.o', missing and no known rule to make it
解决方案:
meson --reconfigure
异常4
fuqiang@ubuntu:~/workspace/gstreamer$ meson out
The Meson build system
Source dir: /home/fuqiang/workspace/gstreamer
Build dir: /home/fuqiang/workspace/gstreamer/out
Build type: native build
meson.build:81:15: ERROR: lexer
['gstreamer', {'build-hotdoc': true}],
解决方案:更新meson版本,ubuntu18.04会出现这个问题,原因是其meson版本过低,使用pip3来安装meson
sudo pip3 install meson
如果版本还是低的话,可能/usr/bin有原始的meson,/usr/local/bin中是新安装的meson,将/usr/local/bin下面的copy到/usr/bin下面即可文章来源:https://www.toymoban.com/news/detail-449598.html
异常5
msgfmt: command not found
解决方案:文章来源地址https://www.toymoban.com/news/detail-449598.html
sudo apt-get -y install gettext
测试命令
基本虚拟测试
gst-launch-1.0 videotestsrc ! autovideosink
gst-launch-1.0 -v videotestsrc pattern=ball name=left ! autovideosink
gst-launch-1.0 audiotestsrc ! autoaudiosink
黑洞fakesink
gst-launch-1.0 videotestsrc ! fakesink
音频播放
gst-launch-1.0 filesrc location='/home/fuqiang/音乐/audio.mp3' ! decodebin ! audioconvert ! audioresample ! autoaudiosink
视频播放
gst-launch-1.0 filesrc location='/home/fuqiang/视频/1080P.mov' ! decodebin ! autovideosink
分离MP4的音视频并分别播放
gst-launch-1.0 filesrc location='/home/fuqiang/视频/1080P.mov' ! 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='/home/fuqiang/视频/1080P.mov' ! qtdemux name=demux demux.video_0 ! queue ! decodebin ! videoconvert ! videoscale ! autovideosink
视频播放并设置videobox
gst-launch-1.0 filesrc location='/home/fuqiang/视频/1080P.mov' ! 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 v4l2src ! videoconvert ! autovideosink
gst-launch-1.0 v4l2src ! videoconvert ! x264enc ! filesink location='/home/fuqiang/视频/xx.mp4'
gst-launch-1.0 v4l2src ! video/x-raw,width=1280,height=720 ! videoconvert ! openh264enc ! h264parse ! flvmux ! filesink location=aaa.flv
采集音频到文件
gst-launch-1.0 alsasrc ! audioresample ! audioconvert ! wavenc ! filesink location=/home/fuqiang/Videos/xx.wav
mp3转码ogg
gst-launch-1.0 filesrc location='/home/fuqiang/音乐/audio.mp3' ! decodebin ! audioconvert ! vorbisenc ! oggmux ! filesink location='/home/fuqiang/音乐/audio.ogg'
timeoverlay
gst-launch-1.0 videotestsrc ! timeoverlay ! xvimagesink
到了这里,关于ubuntu22.04编译安装使用gstreamer指南的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!