Ubuntu20.04 编译 gstreamer 支持gpu硬编解 opencv-python同支持gst

gstreamer 自1.17.1开始,便抛弃了老版本的gpu硬编解方案,采取了新方案,新方案对环境要求放松,意味着更好编译,更稳定:在这里插入图片描述
老版方案装一些预环境还比较麻烦,所以建议抛弃老版本,用新版本。
另外 ubuntu20.04的默认支持gst1.16.3 所有一些诸如桌面之类依赖会有gst相关的库,在编译时容易链接错误,预计用ubutnu22.04及其以上,配合新版本1.21.3以上,应该会好很多。由于目前需要使用ubutnu20.04,故以下以此记录。

编译安装步骤

卸载其他版本

若最后cv2编译装在conda环境下,由于默认安装了gst:

conda remove gstreamer gst-plugins-base

系统若安装过gst,反向操作,则卸载原有gst

sudo apt remove libgstreamer1.0-dev libgstreamer-plugins-base1.0-dev libgstreamer-plugins-bad1.0-dev gstreamer1.0-plugins-base gstreamer1.0-plugins-good gstreamer1.0-plugins-bad gstreamer1.0-plugins-ugly gstreamer1.0-libav gstreamer1.0-doc gstreamer1.0-tools gstreamer1.0-x gstreamer1.0-alsa gstreamer1.0-gl gstreamer1.0-gtk3 gstreamer1.0-qt5 gstreamer1.0-pulseaudio 

编译环境依赖安装

sudo apt-get install build-essential dpkg-dev flex bison autotools-dev automake liborc-dev autopoint libtool gtk-doc-tools python3-pip libmount-dev python3-pip meson bison flex ninja-build  libglib2.0-dev nasm
sudo apt-get install valgrind libgirepository1.0-dev libcap-dev libgtk-3-dev libunwind-dev clzip gobject-introspection libdw-dev
sudo apt-get install libxv-dev libasound2-dev libtheora-dev libogg-dev libvorbis-dev
sudo apt-get install libbz2-dev libv4l-dev libvpx-dev libjack-jackd2-dev libsoup2.4-dev libpulse-dev
sudo apt-get install faad libfaad-dev libfaac-dev libx264-dev libmad0-dev

sudo apt install build-essential cmake git python3-dev python3-numpy \
libavcodec-dev libavformat-dev libswscale-dev libgtk-3-dev libgtk2.0-dev libcanberra-gtk-module \
libpng-dev libjpeg-dev libopenexr-dev libtiff-dev libwebp-dev \
libopencv-dev x264 libx264-dev libssl-dev ffmpeg

编译安装gst

安装1.18版本,对于Ubuntu20.04是合适的选择,对于meson的和ninja可以用系统默认版本
默认编译安装位置prefix应该是/usr/local,此处改为/usr,可解决很多编译链接问题。

git clone -b 1.18 https://github.com/GStreamer/gst-build.git
meson setup --prefix /usr build -Dgst-plugins-bad:nvcodec=enabled   
sudo ninja -C build install

gst-inspect-1.0  --version #查看是否安装成功
gst-inspect-1.0 -a | grep nvh264

#测试代码 若无报错可跑基本没啥问题
gst-launch-1.0 rtspsrc location=rtsp://xxx:[email protected]:554/h264/ch1/main/av_stream ! rtph264depay ! h264parse ! nvh264dec ! videoconvert ! videoscale ! video/x-raw,width=640,height=480 ! nvh264enc ! h264parse ! filesink location=vid2.mp4

#类似报错 即下载出错,原因懂得都懂,解决办法各有千秋呵呵,自己下载后解压到subprojects下并修改为对应名称即可……

subprocess.CalledProcessError: Command '['/bin/git', '-C', '/home/argo/compiled_project/gst-build-1.18/subprojects', 'clone', 'https://gitlab.gnome.org/gnome/libsoup.git', 'libsoup']' returned non-zero exit status 128.

opencv-python支持gst

opencv-python 支持此时的gst,也就同样可以用硬编解
即重新编译安装opencv-python即可
参考

一些记录

参考官网安装,以及dpkg查看gstreamer安装,
dpkg -l | grep libgstreamer
conda list | grep gst
ubuntu 桌面依赖于gst的,所有有相关的动态库等的安装 sudo apt show ubuntu-desktop | grep gstreamer
版本可见是1.16,所以如果不正确配置,会链接错误

参考网址:

https://mesonbuild.com/Tutorial.html
https://gstreamer.freedesktop.org/documentation/installing/index.html?gi-language=c
https://gitlab.freedesktop.org/gstreamer/gst-build
https://github.com/GStreamer/gst-build

你可能感兴趣的:(opencv,gstreamer,部署,python,opencv,开发语言)