Jetson NX的opencv-ffmpeg-gstream的编译

一、gstream推流的依赖

sudo apt update
sudo apt install -y build-essential checkinstall cmake pkg-config yasm git gfortran
sudo apt install -y libgstreamer1.0-dev libgstreamer-plugins-base1.0-dev
sudo apt install -y libjpeg8-dev libjasper-dev libpng12-dev libtiff5-dev libavcodec-dev libavformat-dev libswscale-dev libdc1394-22-dev libxine2-dev libv4l-dev
sudo apt install -y libgstreamer1.0-dev libgstreamer-plugins-base1.0-dev libgtk2.0-dev libtbb-dev libatlas-base-dev libfaac-dev libmp3lame-dev libtheora-dev libvorbis-dev libxvidcore-dev libopencore-amrnb-dev libopencore-amrwb-dev x264 v4l-utils
sudo apt install python-dev python-numpy libtbb2 libtbb-dev libjpeg-dev libpng-dev libtiff-dev libjasper-dev libdc1394-22-dev
sudo apt-get install gtk-doc-tools libgtk-3-dev -y 
sudo apt-get install libgstreamer-plugins-base1.0-dev libgstreamer-plugins-good1.0-dev libgstreamer-plugins-bad1.0-dev -y
sudo apt install -y libgtk2.0-dev libtbb-dev libatlas-base-dev libfaac-dev libmp3lame-dev libtheora-dev libvorbis-dev 

Ubuntu 的软件源配置文件是 /etc/apt/sources.list。将系统自带的该文件做个备份,将该文件替换为下面内容,即可使用选择的软件源镜像。

deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ focal-updates main restricted universe multiverse
deb-src http://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ focal-updates main restricted universe multiverse
deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ focal-security main restricted universe multiverse
deb-src http://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ focal-security main restricted universe multiverse
deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ focal-backports main restricted universe multiverse
deb-src http://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ focal-backports main restricted universe multiverse
deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ focal main universe restricted
deb-src http://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ focal main universe restricted
deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ xenial main multiverse restricted universe
deb [arch=amd64] https://packages.microsoft.com/repos/vscode stable main

参考Xavier NX 使用OpenCV+GStreamer实现硬解码

sudo apt-get update
sudo apt-get dist-upgrade -y --autoremove
sudo apt-get install -y \
        build-essential \
        cmake \
        git \
        gfortran \
        libatlas-base-dev \
        libavcodec-dev \
        libavformat-dev \
        libavresample-dev \
        libcanberra-gtk3-module \
        libdc1394-22-dev \
        libeigen3-dev \
        libglew-dev \
        libgstreamer-plugins-base1.0-dev \
        libgstreamer-plugins-good1.0-dev \
        libgstreamer1.0-dev \
        libgtk-3-dev \
        libjpeg-dev \
        libjpeg8-dev \
        libjpeg-turbo8-dev \
        liblapack-dev \
        liblapacke-dev \
        libopenblas-dev \
        libpng-dev \
        libpostproc-dev \
        libswscale-dev \
        libtbb-dev \
        libtbb2 \
        libtesseract-dev \
        libtiff-dev \
        libv4l-dev \
        libxine2-dev \
        libxvidcore-dev \
        libx264-dev \
        pkg-config \
        python-dev \
        python-numpy \
        python3-dev \
        python3-numpy \
        python3-matplotlib \
        qv4l2 \
        v4l-utils \
        v4l2ucp \
        zlib1g-dev

# https://github.com/LinusCDE/mad-jetson-ffmpeg
sudo apt install bzip2 fontconfig libfribidi{0,-dev} gmpc{,-dev} gnutls-bin lame libass{9,-dev} libavc1394-{0,dev} libbluray{2,-dev} libdrm{2,-dev} libfreetype6{,-dev} libmodplug{1,-dev} libraw1394-{11,dev} librsvg2{-2,-dev} libsoxr{0,-dev} libtheora{0,-dev} libva{2,-dev} libva-drm2 libva-x11-2 libvdpau{1,-dev} libvorbisenc2 libvorbis{0a,-dev} libwebp{6,-dev} libx11{-6,-dev} libxcb1{,-dev} libxext{6,-dev} libxml2{,-dev} libxv{1,-dev} libxvidcore{4,-dev} libopencore-amr{nb0,nb-dev,wb0,wb-dev} opus-tools libsdl2-dev speex v4l-utils zlib1g{,-dev} libopenjp2-7{,-dev} libssh-{4,dev} libspeex{1,-dev}
sudo apt-get install libgmp3-dev libunistring-dev libvpx-dev libopus-dev libmp3lame-dev libfdk-aac-dev

这些是参考的apt依赖

启用gstream的rtsp模块

sudo apt-get install libgstrtspserver-1.0-0 gstreamer1.0-rtsp
sudo apt-get install libgirepository1.0-dev
sudo apt-get install gobject-introspection gir1.2-gst-rtsp-server-1.0

二、opencv的源码编译

编译时出现错误
Can’t build ffmpeg test code
编译不中断,但是最后FFMPEG的选项显示为NO,gstream也显示为no

进入/opencv-4.5.4/modules/videoio/cmake/detect_ffmpeg.cmake
找到if(NOT __VALID_FFMPEG)这个代码块,取消第一个注释,这样能看到全部的错误信息,但是编译会中断。

可以看到是因为依赖库没有全部导入,在/etc/profile中,建立FFMPEG_ROOT路径,把ffmpeg的pkg和lib路径加入到PKG_CONFIG_PATH和LD_LIBRARY_PATH。另外再加上/usr/lib/aarch64-linux-gnu/pkgconfig

三、gstream的rtsp推流

以下是gstream的rtsp推流测试命令行

gst-launch-1.0 -v v4l2src device=/dev/video0 ! jpegdec !  \
nvvidconv! nvv4l2h264enc ! queue ! h264parse! video/x-h264, \
stream-format=byte-stream ! \
rtspclientsink location=rtsp://192.168.137.30:554/test

usb摄像头需要用 v4l2src device=/dev/video0 启动,csi摄像头需要找其他的元素替换。jpegdec是普通的软解码,按理说可以使用nvjpegdec启动硬件解码,不知道为什么这里会显示黑屏,有懂的兄弟麻烦告知一下。

这时应该是推流不成功的,会提示没有连接服务器。gstreamer USB摄像头RTSP推流 这篇文章写了如何编译gstreamer rtsp源码(gst-rtsp-server)我没成功,

root@ems-desktop:/home/video/sources/videoFile# gst-launch-1.0 -v v4l2src device=/dev/video0 ! jpegdec !  nvvidconv! nvv4l2h264enc ! queue ! h264parse! video/x-h264,stream-format=byte-stream ! rtspclientsink location=rtsp://192.168.137.30:554/test
Setting pipeline to PAUSED ...
Opening in BLOCKING MODE
Pipeline is live and does not need PREROLL ...
Progress: (open) Opening Stream
Progress: (connect) Connecting to rtsp://192.168.137.30:554/test
/GstPipeline:pipeline0/GstV4l2Src:v4l2src0.GstPad:src: caps = image/jpeg, width=(int)3264, height=(int)2448, framerate=(fraction)15/1, pixel-aspect-ratio=(fraction)1/1, colorimetry=(string)2:4:5:1, interlace-mode=(string)progressive
/GstPipeline:pipeline0/GstJpegDec:jpegdec0.GstPad:sink: caps = image/jpeg, width=(int)3264, height=(int)2448, framerate=(fraction)15/1, pixel-aspect-ratio=(fraction)1/1, colorimetry=(string)2:4:5:1, interlace-mode=(string)progressive
ERROR: from element /GstPipeline:pipeline0/GstRTSPClientSink:rtspclientsink0: Could not open resource for reading and writing.
Additional debug info:
gstrtspclientsink.c(3236): gst_rtsp_client_sink_connect_to_server (): /GstPipeline:pipeline0/GstRTSPClientSink:rtspclientsink0:
Failed to connect. (Generic error)
ERROR: pipeline doesn't want to preroll.
Setting pipeline to NULL ...
Freeing pipeline ...

我是找了个已经编译好的EasyDarwin的源码包 EasyDarwin百度网盘下载

解压之后,然后

chmod 777 start.sh
./start.sh

成功的截图
然后就可以重新执行gstream的rtsp推流测试命令行

gst-launch-1.0 -v v4l2src device=/dev/video0 ! jpegdec !  \
nvvidconv! nvv4l2h264enc ! queue ! h264parse! video/x-h264, \
stream-format=byte-stream ! \
rtspclientsink location=rtsp://192.168.137.30:554/test

rtsp推流成功
然后rtsp推流就成功啦

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值