RK3288 Debian下OpenCV通过Gstreamer解码RTSP视频流

本文介绍如何在RK3288主板Debian9.13系统上利用Gstreamer进行CPU硬解,实现网络摄像头视频流的高效解码。文章提供了详细的依赖包安装步骤、OpenCV编译配置方法及测试代码,展示了Gstreamer在4K画面解码上的优异性能。

前言

在RK3288主板Debian 9.13系统上想调用CPU硬解进行网络摄像头视频流进行解码,本来尝试用FFmpeg+Mpp方式进行,但ffmpeg集成mpp的解码器,解码后的格式为AV_PIX_FMT_DRM_PRIME,也就是 DRM 帧数据,要进行图像识别还得通过CPU转码为RGB或BGR格式。按照这个过程下来,光解码CPU的占用率就很高。。。后来在Rockchip的wiki_Mpp上看到,对Mpp有如下的一段说明:

We offer the Gstreamer Rockchip, it is a standard Gstreamer plugin for the hardware decoder and encoder at Rockchip platform. I would suggest all the user in the Linux don’t develop the MPP directly unless you know what you are doing. Choose Gstreamer rocckchip in you convenience.

简而言之就是建议Linux下的用户不要直接使用MPP进行开发,推荐用标准的Gstreamer插件。了解到,原来OpenCV可以集成Gstreamer进行使用。运行Gstreamer的例子发现,RK3288解码4K画面是很流畅。

  • Debian GNU/Linux 9.13 (stretch) armv7l
  • OpenCV 3.4.11
  • Gstreamer 1.10.4

Gstreamer解码RTSP命令

#!/bin/sh
gst-launch-1.0 rtspsrc location=rtsp://192.168.31.163:8554/ ! \
        ! rtph264depay ! h264parse ! mppvideodec ! rkximagesink sync=false

安装需要的依赖包

apt-get update
apt-get install -y libgstreamer-plugins-base1.0-dev \
		libpng16-16 \
        build-essential \
        cmake \
        git \
        pkg-config \
        libjpeg-dev \
		libgtk2.0-dev \
        libv4l-dev \
        libatlas-base-dev \
        gfortran \
        libhdf5-dev \
        libtiff5-dev \
		libtbb-dev \
		libeigen3-dev

编译OpenCV

cd3.4.11.zip文件目录下,执行如下命令:

unzip 3.4.11.zip # 解压zip压缩包
cd opencv-3.4.11 # 切换到源码包目录
mkdir build && cd build # 创建build目录并切换进去
cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local -D INSTALL_C_EXAMPLES=OFF -D WITH_GSTREAMER=ON -D WITH_GTK_2_X=ON -D WITH_GTHREAD=ON -D WITH_TBB=ON -D WITH_OPENGL=ON  .. # 配置opencv 此处注意有两个点

如果配置成功的话,应该会有如下输出:

--   OpenCV modules:
--     To be built:                 calib3d core dnn features2d flann hig
[ WARN:0@6.920] global cap_gstreamer.cpp:2824 cv::handleMessage OpenCV | GStreamer warning: your GStreamer installation is missing a required plugin: Audio Video Interleave (AVI) demuxer [ WARN:0@6.920] global cap_gstreamer.cpp:2840 cv::handleMessage OpenCV | GStreamer warning: Embedded video playback halted; module uridecodebin0 reported: Your GStreamer installation is missing a plug-in. [ WARN:0@6.921] global cap_gstreamer.cpp:1698 cv::GStreamerCapture::open OpenCV | GStreamer warning: unable to start pipeline [ WARN:0@6.921] global cap_gstreamer.cpp:1173 cv::GStreamerCapture::isPipelinePlaying OpenCV | GStreamer warning: GStreamer: pipeline have not been created [ WARN:0@7.073] global cap_msmf.cpp:935 CvCapture_MSMF::initStream Failed to set mediaType (stream 0, (800x600 @ 49.885) MFVideoFormat_RGB32(codec not found) 视频处理完成,每帧已保存到 ./input 文件夹中。 E:\DHP\code\ruanzhu4.py:109: FutureWarning: You are using `torch.load` with `weights_only=False` (the current default value), which uses the default pickle module implicitly. It is possible to construct malicious pickle data which will execute arbitrary code during unpickling (See https://github.com/pytorch/pytorch/blob/main/SECURITY.md#untrusted-models for more details). In a future release, the default value for `weights_only` will be flipped to `True`. This limits the functions that could be executed during unpickling. Arbitrary objects will no longer be allowed to be loaded via this mode unless they are explicitly allowlisted by the user via `torch.serialization.add_safe_globals`. We recommend you start setting `weights_only=True` for any use case where you don't have full control of the loaded file. Please open an issue on GitHub for any issues related to this experimental feature. model.load_state_dict(torch.load(args.model)) 0it [00:00, ?it/s] [ WARN:0@7.681] global cap_gstreamer.cpp:2824 cv::handleMessage OpenCV | GStreamer warning: your GStreamer installation is missing a required plugin: Audio Video Interleave
04-02
评论 20
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值