香橙派--安装RKMPP、x264、libdrm、FFmpeg(支持rkmpp)以及opencv(支持带rkmpp的ffmpeg)(适用于RK3588平台)

news/2024/11/27 9:06:16/

1. 安装RKMPP

git clone https://github.com/rockchip-linux/mpp
cd mpp/build/linux/aarch64
./make-Makefiles.bash
make -j8
sudo make install

RKMPP:用于编解码测试,支持RK3588平台。

2. 安装x264

git clone https://code.videolan.org/videolan/x264.git
cd x264
./configure --prefix=/usr/local/x264 --disable-opencl --enable-static --enable-shared
make -j8
sudo make install

配置环境变量:

echo 'export PKG_CONFIG_PATH="/usr/local/x264/lib/pkgconfig:$PKG_CONFIG_PATH"' >> ~/.bashrc
echo 'export LD_LIBRARY_PATH="/usr/local/x264/lib:$LD_LIBRARY_PATH"' >> ~/.bashrc
source ~/.bashrc

创建x264配置文件:

sudo nano /etc/ld.so.conf.d/x264.conf
# 添加以下内容
/usr/local/x264/lib

3. 安装libdrm

wget https://dri.freedesktop.org/libdrm/libdrm-2.4.89.tar.bz2
tar -jxvf libdrm-2.4.89.tar.bz2
cd libdrm-2.4.89
sed -i 's/drm_private uint32_t nouveau_debug;/drm_private extern uint32_t nouveau_debug;/' nouveau/private.h
./configure --prefix=/usr/local/libdrm --host=aarch64-linux-gnu
make -j8
sudo make install

4. 安装FFmpeg

git clone https://git.ffmpeg.org/ffmpeg.git
cd ffmpeg
./configure --prefix=/usr/local/ffmpeg --enable-version3 --enable-libdrm --enable-rkmpp --enable-libx264 --enable-nonfree --enable-gpl --enable-shared
make -j8
sudo make install

4.1 配置环境变量

为了让系统正确识别FFmpeg,设置路径和库路径:

echo 'export PATH="/usr/local/my/ffmpeg/bin:$PATH"' >> ~/.bashrc
echo 'export LD_LIBRARY_PATH="/usr/local/my/ffmpeg/lib:$LD_LIBRARY_PATH"' >> ~/.bashrc
source ~/.bashrc

4.2 配置系统库

更新系统库配置,确保新安装的库文件能被识别:

sudo vim /etc/ld.so.conf
# 添加以下内容
include /etc/ld.so.conf.d/*.conf
/usr/local/lib
/usr/local/x264/lib
/usr/local/libdrm/lib

完成以上步骤后,你就能在RK3588平台上使用RKMPP加速的FFmpeg进行高效的视频编解码。
确保每个步骤都按照顺序完成,特别是环境变量和配置文件的修改,它们非常重要。

opencv_157">5.安装opencv

opencv安装包下载地址:

https://github.com/opencv/opencv/

扩展库下载地址:

https://github.com/opencv/opencv_contrib

一键编译脚本build-opencv.sh,将这个脚本放在下载的opencv同级目录:

#!/bin/bashsudo apt-get updatesudo apt-get install -y \build-essential \pkg-config \libgtk2.0-dev \libavcodec-dev \libavformat-dev \libswscale-dev \libv4l-dev \libxvidcore-dev \libx264-dev \libjpeg-dev \libtiff5-dev \libvtk7-dev# 设置工作目录
BASE_DIR=$(pwd)
OPENCV_DIR="${BASE_DIR}/opencv-4.10.0"
INSTALL_DIR="${OPENCV_DIR}/install"
BUILD_DIR="${OPENCV_DIR}/build"
CONTRIB_DIR="${BASE_DIR}/opencv_contrib-4.10.0"# 创建安装和构建目录
mkdir -p "${INSTALL_DIR}"
mkdir -p "${BUILD_DIR}"# 进入构建目录
cd "${BUILD_DIR}"# 运行 CMake
cmake \
-D CMAKE_BUILD_TYPE=RELEASE \
-D CMAKE_INSTALL_PREFIX="${INSTALL_DIR}" \
-D OPENCV_EXTRA_MODULES_PATH="${CONTRIB_DIR}/modules" \
-D WITH_LIBV4L=ON \
-D WITH_EIGEN=ON \
-D WITH_TBB=ON \
-D WITH_OPENMP=ON \
-D WITH_OPENCL=ON \
-D WITH_OPENGL=ON \
-D ENABLE_CXX11=ON \
-D WITH_FFMPEG=ON \
-D FFMPEG_INCLUDE_DIR="/usr/local/ffmpeg/include" \
-D FFMPEG_LIBRARIES="/usr/local/ffmpeg/lib/libavcodec.so;/usr/local/ffmpeg/lib/libavformat.so;/usr/local/ffmpeg/lib/libavutil.so" \
-D OPENCV_ENABLE_NONFREE=ON \
-D OPENCV_GENERATE_PKGCONFIG=YES \
-D ENABLE_PRECOMPILED_HEADERS=OFF \
"${OPENCV_DIR}"  # 确保CMake指向正确的源代码目录# 编译
make -j$(nproc)  # 调整为根据实际CPU核心数选择合适的线程数
make install

opencv_232">5.1 删除手动安装包中的opencv版本

sudo apt-get remove --purge libopencv* python3-opencv
sudo rm -rf /usr/local/lib/libopencv_*
sudo rm -rf /usr/local/lib/pkgconfig/opencv4.pc
sudo rm -rf /usr/local/include/opencv*
sudo rm -rf /usr/local/bin/opencv_*

5.2安装依赖以及编译

5.2.1 更新系统依赖库

sudo apt-get update
sudo apt-get install -y \build-essential \pkg-config \libgtk2.0-dev \libavcodec-dev \libavformat-dev \libswscale-dev \libv4l-dev \libxvidcore-dev \libx264-dev \libjpeg-dev \libtiff5-dev \libvtk7-dev

5.2.2 创建编译build目录以及运行 CMake

cd  opencv-4.10.0 && mkdir build && mkdir install && cd build
cmake \
-D CMAKE_BUILD_TYPE=RELEASE \
-D CMAKE_INSTALL_PREFIX="${INSTALL_DIR}" \
-D OPENCV_EXTRA_MODULES_PATH="${CONTRIB_DIR}/modules" \
-D WITH_LIBV4L=ON \
-D WITH_EIGEN=ON \
-D WITH_TBB=ON \
-D WITH_OPENMP=ON \
-D WITH_OPENCL=ON \
-D WITH_OPENGL=ON \
-D ENABLE_CXX11=ON \
-D WITH_FFMPEG=ON \
-D FFMPEG_INCLUDE_DIR="/usr/local/ffmpeg/include" \
-D FFMPEG_LIBRARIES="/usr/local/ffmpeg/lib/libavcodec.so;/usr/local/ffmpeg/lib/libavformat.so;/usr/local/ffmpeg/lib/libavutil.so" \
-D OPENCV_ENABLE_NONFREE=ON \
-D OPENCV_GENERATE_PKGCONFIG=YES \
-D ENABLE_PRECOMPILED_HEADERS=OFF \

5.2.3 开始编译以及生成库

make -j4 && make install

5.2.4 opencv库的安装

命令执行结束,在install生成库文件,我的文件夹结构为:

/home/orangepi/
├── opencv-4.10.0
│   ├── build
│   └── install
│       ├── bin
│       ├── include
│       ├── lib
│       └── share
└── opencv_contrib-4.10.0└── modules

下面开始将库文件拷贝到系统目录,在install目录下打开终端,分别执行以下命令:

(1)修改opencv-4.10.0/install/lib/pkgconfig/opencv4.pc

vim lib/pkgconfig/opencv4.pc

原始的:

# Package Information for pkg-configprefix=/home/orangepi/opencv-4.10.0/install
exec_prefix=${prefix}
libdir=${exec_prefix}/lib
includedir=${prefix}/include/opencv4Name: OpenCV
Description: Open Source Computer Vision Library
Version: 4.10.0
Libs: -L${exec_prefix}/lib -lopencv_gapi -lopencv_stitching -lopencv_alphamat -lopencv_aruco -lopencv_bgsegm -lopencv_bioinspired -lopencv_ccalib -lopencv_cudabgsegm -lopencv_cudafeatures2d -lopencv_cudaobjdetect -lopencv_cudastereo -lopencv_dnn_objdetect -lopencv_dnn_superres -lopencv_dpm -lopencv_face -lopencv_freetype -lopencv_fuzzy -lopencv_hdf -lopencv_hfs -lopencv_img_hash -lopencv_intensity_transform -lopencv_line_descriptor -lopencv_mcc -lopencv_quality -lopencv_rapid -lopencv_reg -lopencv_rgbd -lopencv_saliency -lopencv_signal -lopencv_stereo -lopencv_structured_light -lopencv_phase_unwrapping -lopencv_superres -lopencv_cudacodec -lopencv_surface_matching -lopencv_tracking -lopencv_highgui -lopencv_datasets -lopencv_text -lopencv_plot -lopencv_videostab -lopencv_cudaoptflow -lopencv_optflow -lopencv_cudalegacy -lopencv_videoio -lopencv_cudawarping -lopencv_viz -lopencv_wechat_qrcode -lopencv_xfeatures2d -lopencv_shape -lopencv_ml -lopencv_ximgproc -lopencv_video -lopencv_xobjdetect -lopencv_objdetect -lopencv_calib3d -lopencv_imgcodecs -lopencv_features2d -lopencv_dnn -lopencv_flann -lopencv_xphoto -lopencv_photo -lopencv_cudaimgproc -lopencv_cudafilters -lopencv_imgproc -lopencv_cudaarithm -lopencv_core -lopencv_cudev
Libs.private: -lm -lpthread -lcudart_static -ldl -lrt -lnppc -lnppial -lnppicc -lnppidei -lnppif -lnppig -lnppim -lnppist -lnppisu -lnppitc -lnpps -lcublas -lcudnn -lcufft -L-L/usr/local/cuda-11.4 -llib64 -L-L/usr/lib -laarch64-linux-gnu
Cflags: -I${includedir}

新的:

# Package Information for pkg-configprefix=prefix=/usr/local
exec_prefix=${prefix}
libdir=${exec_prefix}/lib
includedir=${prefix}/include/opencv4Name: OpenCV
Description: Open Source Computer Vision Library
Version: 4.10.0
Libs: -L${exec_prefix}/lib -lopencv_gapi -lopencv_stitching -lopencv_alphamat -lopencv_aruco -lopencv_bgsegm -lopencv_bioinspired -lopencv_ccalib -lopencv_cudabgsegm -lopencv_cudafeatures2d -lopencv_cudaobjdetect -lopencv_cudastereo -lopencv_dnn_objdetect -lopencv_dnn_superres -lopencv_dpm -lopencv_face -lopencv_freetype -lopencv_fuzzy -lopencv_hdf -lopencv_hfs -lopencv_img_hash -lopencv_intensity_transform -lopencv_line_descriptor -lopencv_mcc -lopencv_quality -lopencv_rapid -lopencv_reg -lopencv_rgbd -lopencv_saliency -lopencv_signal -lopencv_stereo -lopencv_structured_light -lopencv_phase_unwrapping -lopencv_superres -lopencv_cudacodec -lopencv_surface_matching -lopencv_tracking -lopencv_highgui -lopencv_datasets -lopencv_text -lopencv_plot -lopencv_videostab -lopencv_cudaoptflow -lopencv_optflow -lopencv_cudalegacy -lopencv_videoio -lopencv_cudawarping -lopencv_viz -lopencv_wechat_qrcode -lopencv_xfeatures2d -lopencv_shape -lopencv_ml -lopencv_ximgproc -lopencv_video -lopencv_xobjdetect -lopencv_objdetect -lopencv_calib3d -lopencv_imgcodecs -lopencv_features2d -lopencv_dnn -lopencv_flann -lopencv_xphoto -lopencv_photo -lopencv_cudaimgproc -lopencv_cudafilters -lopencv_imgproc -lopencv_cudaarithm -lopencv_core -lopencv_cudev
Libs.private: -lm -lpthread -lcudart_static -ldl -lrt -lnppc -lnppial -lnppicc -lnppidei -lnppif -lnppig -lnppim -lnppist -lnppisu -lnppitc -lnpps -lcublas -lcudnn -lcufft -L-L/usr/local/cuda-11.4 -llib64 -L-L/usr/lib -laarch64-linux-gnu
Cflags: -I${includedir}

(2)将 bin 文件夹复制到 /usr/local

sudo cp -r bin/* /usr/local/bin/

(3)将 include 文件夹复制到 /usr/local/include

sudo cp -r include/* /usr/local/include/

(4)将 lib 文件夹复制到 /usr/local/lib

sudo mv lib/python3.8/site-packages    lib/python3.8/dist-packages 
sudo cp -r lib/* /usr/local/lib/

(5)将 share 文件夹复制到 /usr/local/share

sudo cp -r share/* /usr/local/share/

5.3. 将OpenCV的库添加到系统路径

5.3.1 方法一:配置ld.so.conf文件

sudo vim /etc/ld.so.conf

在文件中加上一行

include /usr/local/lib

这个路径是cmake编译时填的动态库安装路径加上/lib

配置ld.so.conf文件

5.3.2 方法二:手动生成opencv.conf文件

sudo vim /etc/ld.so.conf.d/opencv.conf

是一个新建的空文件,直接添加路径,同理这个路径是cmake编译时填的动态库安装路径加上/lib

/usr/local/lib

5.3.3 应用配置更新

以上两种方法配置好后,执行如下命令使得配置的路径生效

sudo ldconfig

配置系统bash
因为在cmake时,选择了自动生成OpenCV的pkgconfig文件,在/usr/local/lib/pkgconfig路径可以看到文件opencv4.pc

确保文件存在,执行如下命令

sudo vim /etc/bash.bashrc

在文末添加

PKG_CONFIG_PATH=$PKG_CONFIG_PATH:/usr/local/lib/pkgconfig
export PKG_CONFIG_PATH

如下:

bash.bashrc

保存退出,然后执行如下命令使配置生效

source /etc/bash.bashrc
echo 'export CPLUS_INCLUDE_PATH=/usr/local/include/opencv:/usr/local/include/opencv4:$CPLUS_INCLUDE_PATH' >> ~/.bashrc
echo 'export LIBRARY_PATH=/usr/local/lib:$LIBRARY_PATH' >> ~/.bashrc
source ~/.bashrc

至此,Linux\Ubuntu18.04环境下OpenCV的安装以及配置已经全部完成,可以使用以下命令查看是否安装和配置成功

pkg-config --modversion opencv4
pkg-config --cflags opencv4
pkg-config --libs opencv4

最后添加软链接,确保C++编译没问题:

sudo mv /usr/local/include/opencv4  /usr/local/include/opencv
sudo ln -s /usr/local/include/opencv/opencv2   /usr/local/include/opencv2
sudo ln -s /usr/local/include/opencv/opencv2   /usr/local/include/opencv4

http://www.ppmy.cn/news/1550303.html

相关文章

计算机网络socket编程(4)_TCP socket API 详解

个人主页:C忠实粉丝 欢迎 点赞👍 收藏✨ 留言✉ 加关注💓本文由 C忠实粉丝 原创 计算机网络socket编程(4)_TCP socket API 详解 收录于专栏【计算机网络】 本专栏旨在分享学习计算机网络的一点学习笔记,欢迎大家在评论区交流讨论&…

Android OpenGL ES详解——绘制圆角矩形

1、绘制矩形 代码如下: renderer类: package com.example.roundrectimport android.content.Context import android.opengl.GLES30 import android.opengl.GLSurfaceView.Renderer import com.opengllib.data.VertexArray import com.opengllib.prog…

QUICK调试camera-xml解析

本文主要介绍如何在QUICK QC6490使能相机模组。QC6490的相机基于CameraX的框架,只需通过配置XML文件,设置相机模组的相关参数,就可以点亮相机。本文主要介绍Camera Sensor Module XML和Camera Sensor XML配置的解析,这中间需要cam…

uni-app自定义底部tab并且根据字段显示和隐藏

首先将所有tab使用到的页面创建好并且在pages里面配置好,要在pages.json中的"tabBar里面配置"custom": true将自带的tab底部导航关闭 "pages": [{"path": "pages/mine/mine","style": {"navigationBa…

macOS上进行Ant Design Pro实战教程(一)

由于一个AI项目的前端使用了umi,本教程根据阿里官网上的 《Ant Design 实战教程(beta 版)》来实操一下,我使用macOS操作系统,VS Code 开发环境。 一、开发环境 1、安装nodejs, npm, yarn 官网上建议使用cnpm&#xf…

MySQL查询缓存详解

一、查询缓存的基本概念 MySQL 的查询缓存是一种用于存储查询结果的内存区域。当一个查询被执行时,MySQL 首先检查查询缓存中是否已经存在相同的查询结果。如果存在,直接从查询缓存中返回结果,而无需再次执行查询语句,从而大大提高…

蓝桥杯c++算法秒杀【6】之动态规划【下】(数字三角形、砝码称重(背包问题)、括号序列、异或三角:::非常典型的必刷例题!!!)

别忘了请点个赞收藏关注支持一下博主喵!!!! ! ! ! ! 关注博主,更多蓝桥杯nice题目静待更新:) 动态规划 三、括号序列 【问题描述】 给定一个括号序列,要求尽可能少地添加若干括号使得括号序列变得合…

使用mingw+CMake在Windows平台编译OpenCV

1. 安装mingw和cmake cmake的安装比较简单,百度一下完成相关操作即可,笔者安装的是3.24.3版本。 Mingw的安装也有很多相关文章,不过我使用的是安装QT时附带安装的mingw,其路径为D:\software\Qt\Tools\mingw1120_64。其中的bin文件…