君正T41交叉编译ffmpeg、opencv并做h264软解,利用君正SDK做h264硬件编码

目录

1 交叉编译ffmpeg----错误解决过程,不要看

1.1 下载源码

1.2 配置

1.3 编译 安装

1.3.1 报错:libavfilter/libavfilter.so: undefined reference to `fminf'

1.3.2 报错:error: unknown type name 'HEVCContext'; did you mean 'HEVCPredContext'?

2 交叉编译opencv----错误解决过程,不要看了,直接看目录3

2.1 下载源码

2.2 修改mips.toolchain.cmake

2.3 配置

2.3.1 报错:can’t find ffmpeg – ‘pkg-config’ utility is missing

2.4 编译、安装

2.4.1编译报错:fatal error: zlib.h: No such file or directory

  2.4.2 报错:undefined reference to `avcodec_find_encoder@LIBAVCODEC_57

2.4.3最终使用的cmake命令

 2.4.4 编译出来的库是x86的

2.4.5 undefined reference to `avcodec_find_encoder@LIBAVCODEC_57----为什么这个错误又出现了

2.5 换个新的xshell终端做实验

3 交叉编译opencv----整理后的正确步骤,直接看这个

 3.1 下载源码

3.2 修改../platforms/linux/mips.toolchain.cmake和../platforms/linux/mips32r5el-gnu.toolchain.cmake

3.3 配置PKG_CONFIG_LIBDIR

3.4 cmake

3.5 编译、安装

4 软件解码

4.1 libopencv_core.so: undefined reference to `__atomic_compare_exchange_8'

4.2 illegal instruction

4.3 错误: CAP_IMAGES: Stop scanning. Can't read image file

5 交叉编译ffmepg----正确步骤,直接看这个

5.1 下载源码 

5.2 配置

5.3 编译、安装

参考文献:


君正T41芯片只有编码器没有解码器,所以需要用软件解码对h264进行解码,试一下ffmpeg和opencv。

1 交叉编译ffmpeg----错误解决过程,不要看

1.1 下载源码

Index of /releases

不需要用特别新的,我这里下载4.1.3的版本就行,然后解压

tar xzvf ffmpeg-4.1.3.tar.gz 
cd ffmpeg-4.1.3/
mkdir install

1.2 配置

./configure --enable-cross-compile --cross-prefix=mips-linux-uclibc- --arch=mips --target-os=linux --cc=mips-linux-uclibc-gcc --prefix=$PWD/install --enable-shared --enable-pic --disable-static --enable-gpl --enable-nonfree --enable-pthreads --enable-ffmpeg --disable-ffplay --enable-swscale --enable-mips32r2  --disable-mipsdsp1 --disable-mipsdspr2 --disable-mips32r1 --disable-mipsfpu  --disable-mips64r2  --disable-mips32r6 

1.3 编译 安装

make -j
make install

编译报错

1.3.1 报错:libavfilter/libavfilter.so: undefined reference to `fminf'

libavfilter/libavfilter.so: undefined reference to `fminf'
libavfilter/libavfilter.so: undefined reference to `fmaxf'

从这篇博客看海思3516ev200 _FFMPEG库编译_ffmpeg undefined reference to `fmaxf-CSDN博客

然后从博客的评论区看

行吧,应该是我的交叉编译工具链的问题,重新下载3.3.9的,然后重新重复上面的过程。

然后又报错

1.3.2 报错:error: unknown type name 'HEVCContext'; did you mean 'HEVCPredContext'?

libavcodec/mips/hevcpred_msa.c:1913:32: error: unknown type name 'HEVCContext'; did you mean 'HEVCPredContext'?void ff_intra_pred_8_16x16_msa(HEVCContext *s, int x0, int y0, int c_idx)^~~~~~~~~~~HEVCPredContext
libavcodec/mips/hevcpred_msa.c:2426:32: error: unknown type name 'HEVCContext'; did you mean 'HEVCPredContext'?void ff_intra_pred_8_32x32_msa(HEVCContext *s, int x0, int y0, int c_idx)^~~~~~~~~~~HEVCPredContext

好吧,直接vscode把整个ffmpeg代码打开看看怎么个事,查找HEVCContext的定义,

发现在ffmpeg-3.3.9/libavcodec/hevcpred.h中有

然后在ffmpeg-3.3.9/libavcodec/hevcdec.h中有

那么在ffmpeg-3.3.9/libavcodec/mips/hevcpred_msa.c中添加

//#include "libavcodec/hevcpred.h"  //添加了这一行没用,还是报错
#include "libavcodec/hevcdec.h"

然后make install之后发现

先这样,后面再看库能不能用。

2 交叉编译opencv----错误解决过程,不要看了,直接看目录3

2.1 下载源码

首先也还是下载opencv源码Releases - OpenCV,然后

2.2 修改mips.toolchain.cmake

cd opencv-3.4.9/
mkdir build
mkdir install
cd platforms/linux/

mips.toolchain.cmake本来内容如下

# ----------------------------------------------------------------------------------------------
#  MIPS ToolChanin can be downloaded from https://www.mips.com/develop/tools/codescape-mips-sdk/ .
#  Toolchains with 'mti' in the name (and install directory) are for MIPS R2-R5 instruction sets.
#  Toolchains with 'img' in the name are for MIPS R6 instruction sets.
#  It is recommended to use cmake-gui application for build scripts configuration and generation:
#  1. Run cmake-gui
#  2. Specifiy toolchain file for cross-compiling, mips32r5el-gnu.toolchian.cmake or mips64r6el-gnu.toolchain.cmake
#     can be selected.
#  3. Configure and Generate makefiles.
#  4. make -j4 & make install
# ----------------------------------------------------------------------------------------------if(COMMAND toolchain_save_config)return() # prevent recursive call
endif()set(CMAKE_SYSTEM_NAME Linux)
set(CMAKE_SYSTEM_VERSION 1)
if(NOT DEFINED CMAKE_SYSTEM_PROCESSOR)set(CMAKE_SYSTEM_PROCESSOR mips)
endif()include("${CMAKE_CURRENT_LIST_DIR}/gnu.toolchain.cmake")if(CMAKE_SYSTEM_PROCESSOR STREQUAL mips AND NOT MIPS_IGNORE_FP)set(FLOAT_ABI_SUFFIX "")
endif()if(NOT "x${GCC_COMPILER_VERSION}" STREQUAL "x")set(__GCC_VER_SUFFIX "-${GCC_COMPILER_VERSION}")
endif()if(NOT DEFINED CMAKE_C_COMPILER)find_program(CMAKE_C_COMPILER NAMES ${GNU_MACHINE}${FLOAT_ABI_SUFFIX}-gcc${__GCC_VER_SUFFIX})
endif()
if(NOT DEFINED CMAKE_CXX_COMPILER)find_program(CMAKE_CXX_COMPILER NAMES ${GNU_MACHINE}${FLOAT_ABI_SUFFIX}-g++${__GCC_VER_SUFFIX})
endif()
if(NOT DEFINED CMAKE_LINKER)find_program(CMAKE_LINKER NAMES ${GNU_MACHINE}${FLOAT_ABI_SUFFIX}-ld${__GCC_VER_SUFFIX} ${GNU_MACHINE}${FLOAT_ABI_SUFFIX}-ld)
endif()
if(NOT DEFINED CMAKE_AR)find_program(CMAKE_AR NAMES ${GNU_MACHINE}${FLOAT_ABI_SUFFIX}-ar${__GCC_VER_SUFFIX} ${GNU_MACHINE}${FLOAT_ABI_SUFFIX}-ar)
endif()if(NOT DEFINED MIPS_LINUX_SYSROOT AND DEFINED GNU_MACHINE)set(MIPS_LINUX_SYSROOT /usr/bin)
endif()if(NOT DEFINED CMAKE_CXX_FLAGS)if(CMAKE_SYSTEM_PROCESSOR MATCHES "mips32r5el")set(CMAKE_C_FLAGS             "-march=mips32r5 -EL -mmsa -mhard-float -mfp64 -mnan=2008 -mabs=2008 -O3 -ffp-contract=off -mtune=p5600" CACHE INTERNAL "")set(CMAKE_SHARED_LINKER_FLAGS "" CACHE INTERNAL "")set(CMAKE_CXX_FLAGS           "-march=mips32r5 -EL -mmsa -mhard-float -mfp64 -mnan=2008 -mabs=2008 -O3 -ffp-contract=off -mtune=p5600" CACHE INTERNAL "")set(CMAKE_MODULE_LINKER_FLAGS "" CACHE INTERNAL "")set(CMAKE_EXE_LINKER_FLAGS    "-lpthread -lrt -ldl -latomic" CACHE INTERNAL "Added for mips cross build error")set(CMAKE_CXX_FLAGS           "${CMAKE_CXX_FLAGS} -fdata-sections  -Wa,--noexecstack -fsigned-char -Wno-psabi")set(CMAKE_C_FLAGS             "${CMAKE_C_FLAGS} -fdata-sections  -Wa,--noexecstack -fsigned-char -Wno-psabi")elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "mips64r6el")set(CMAKE_C_FLAGS             "-O3 -march=i6500 -EL -mmsa -mabi=64 -mhard-float -mfp64 -mnan=2008" CACHE INTERNAL "")set(CMAKE_SHARED_LINKER_FLAGS "" CACHE INTERNAL "")set(CMAKE_CXX_FLAGS           "-O3 -march=i6500 -EL -mmsa -mabi=64 -mhard-float -mfp64 -mnan=2008" CACHE INTERNAL "")set(CMAKE_MODULE_LINKER_FLAGS "" CACHE INTERNAL "")set(CMAKE_EXE_LINKER_FLAGS    "-lpthread -lrt -ldl" CACHE INTERNAL "Added for mips cross build error")set(CMAKE_CXX_FLAGS           "${CMAKE_CXX_FLAGS} -fdata-sections -Wa,--noexecstack -fsigned-char -Wno-psabi")set(CMAKE_C_FLAGS             "${CMAKE_C_FLAGS} -fdata-sections -Wa,--noexecstack -fsigned-char -Wno-psabi")endif()set(CMAKE_SHARED_LINKER_FLAGS "${MIPS_LINKER_FLAGS} ${CMAKE_SHARED_LINKER_FLAGS}")set(CMAKE_MODULE_LINKER_FLAGS "${MIPS_LINKER_FLAGS} ${CMAKE_MODULE_LINKER_FLAGS}")set(CMAKE_EXE_LINKER_FLAGS    "${MIPS_LINKER_FLAGS} ${CMAKE_EXE_LINKER_FLAGS}")
endif()set(CMAKE_FIND_ROOT_PATH ${CMAKE_FIND_ROOT_PATH} ${MIPS_LINUX_SYSROOT})set(TOOLCHAIN_CONFIG_VARS ${TOOLCHAIN_CONFIG_VARS}MIPS_LINUX_SYSROOT
)
toolchain_save_config()

修改成下面的形式

# ----------------------------------------------------------------------------------------------
# MIPS ToolChain can be downloaded from https://www.mips.com/develop/tools/codescape-mips-sdk/ .
# Toolchains with 'mti' in the name (and install directory) are for MIPS R2-R5 instruction sets.
# Toolchains with 'img' in the name are for MIPS R6 instruction sets.
# It is recommended to use cmake-gui application for build scripts configuration and generation:
# 1. Run cmake-gui
# 2. Specify toolchain file for cross-compiling, mips32r5el-gnu.toolchian.cmake or mips64r6el-gnu.toolchain.cmake
#    can be selected.
# 3. Configure and Generate makefiles.
# 4. make -j4 & make install
# ----------------------------------------------------------------------------------------------if(COMMAND toolchain_save_config)return() # prevent recursive call
endif()set(CMAKE_SYSTEM_NAME Linux)
set(CMAKE_SYSTEM_VERSION 1)
if(NOT DEFINED CMAKE_SYSTEM_PROCESSOR)set(CMAKE_SYSTEM_PROCESSOR mips)
endif()include("${CMAKE_CURRENT_LIST_DIR}/gnu.toolchain.cmake")if(CMAKE_SYSTEM_PROCESSOR STREQUAL mips AND NOT MIPS_IGNORE_FP)set(FLOAT_ABI_SUFFIX "")
endif()if(NOT "x${GCC_COMPILER_VERSION}" STREQUAL "x")set(__GCC_VER_SUFFIX "-${GCC_COMPILER_VERSION}")
endif()# Set GNU_MACHINE based on your toolchain prefix
set(GNU_MACHINE "mips-linux-uclibc-")# Define paths to the compilers using the GNU_MACHINE variable and your toolchain path
if(NOT DEFINED CMAKE_C_COMPILER)find_program(CMAKE_C_COMPILER NAMES ${GNU_MACHINE}gcc${__GCC_VER_SUFFIX}PATHS /data3/t41_toolchain/mips-gcc720-uclibc0.9.33.2-r5.1.4/bin/NO_DEFAULT_PATH)
endif()
if(NOT DEFINED CMAKE_CXX_COMPILER)find_program(CMAKE_CXX_COMPILER NAMES ${GNU_MACHINE}g++${__GCC_VER_SUFFIX}PATHS /data3/t41_toolchain/mips-gcc720-uclibc0.9.33.2-r5.1.4/bin/NO_DEFAULT_PATH)
endif()
if(NOT DEFINED CMAKE_LINKER)find_program(CMAKE_LINKER NAMES ${GNU_MACHINE}ld${__GCC_VER_SUFFIX}PATHS /data3/t41_toolchain/mips-gcc720-uclibc0.9.33.2-r5.1.4/bin/NO_DEFAULT_PATH)
endif()
if(NOT DEFINED CMAKE_AR)find_program(CMAKE_AR NAMES ${GNU_MACHINE}ar${__GCC_VER_SUFFIX}PATHS /data3/t41_toolchain/mips-gcc720-uclibc0.9.33.2-r5.1.4/bin/NO_DEFAULT_PATH)
endif()# Set the sysroot if it's not defined already
if(NOT DEFINED MIPS_LINUX_SYSROOT)set(MIPS_LINUX_SYSROOT /data3/t41_toolchain/mips-gcc720-uclibc0.9.33.2-r5.1.4/sysroot/)
endif()# Add your specific compiler flags here
if(NOT DEFINED CMAKE_CXX_FLAGS)if(CMAKE_SYSTEM_PROCESSOR MATCHES "mips32r5el")set(CMAKE_C_FLAGS             "-march=mips32r5 -EL -mmsa -mhard-float -mfp64 -mnan=2008 -mabs=2008 -O3 -ffp-contract=off -mtune=p5600" CACHE INTERNAL "")set(CMAKE_SHARED_LINKER_FLAGS "" CACHE INTERNAL "")set(CMAKE_CXX_FLAGS           "-march=mips32r5 -EL -mmsa -mhard-float -mfp64 -mnan=2008 -mabs=2008 -O3 -ffp-contract=off -mtune=p5600" CACHE INTERNAL "")set(CMAKE_MODULE_LINKER_FLAGS "" CACHE INTERNAL "")set(CMAKE_EXE_LINKER_FLAGS    "-lpthread -lrt -ldl -latomic" CACHE INTERNAL "Added for mips cross build error")set(CMAKE_CXX_FLAGS           "${CMAKE_CXX_FLAGS} -fdata-sections  -Wa,--noexecstack -fsigned-char -Wno-psabi")set(CMAKE_C_FLAGS             "${CMAKE_C_FLAGS} -fdata-sections  -Wa,--noexecstack -fsigned-char -Wno-psabi")elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "mips64r6el")set(CMAKE_C_FLAGS             "-O3 -march=i6500 -EL -mmsa -mabi=64 -mhard-float -mfp64 -mnan=2008" CACHE INTERNAL "")set(CMAKE_SHARED_LINKER_FLAGS "" CACHE INTERNAL "")set(CMAKE_CXX_FLAGS           "-O3 -march=i6500 -EL -mmsa -mabi=64 -mhard-float -mfp64 -mnan=2008" CACHE INTERNAL "")set(CMAKE_MODULE_LINKER_FLAGS "" CACHE INTERNAL "")set(CMAKE_EXE_LINKER_FLAGS    "-lpthread -lrt -ldl" CACHE INTERNAL "Added for mips cross build error")set(CMAKE_CXX_FLAGS           "${CMAKE_CXX_FLAGS} -fdata-sections -Wa,--noexecstack -fsigned-char -Wno-psabi")set(CMAKE_C_FLAGS             "${CMAKE_C_FLAGS} -fdata-sections -Wa,--noexecstack -fsigned-char -Wno-psabi")endif()set(CMAKE_SHARED_LINKER_FLAGS "${MIPS_LINKER_FLAGS} ${CMAKE_SHARED_LINKER_FLAGS}")set(CMAKE_MODULE_LINKER_FLAGS "${MIPS_LINKER_FLAGS} ${CMAKE_MODULE_LINKER_FLAGS}")set(CMAKE_EXE_LINKER_FLAGS    "${MIPS_LINKER_FLAGS} ${CMAKE_EXE_LINKER_FLAGS}")
endif()set(CMAKE_FIND_ROOT_PATH ${CMAKE_FIND_ROOT_PATH} ${MIPS_LINUX_SYSROOT})set(TOOLCHAIN_CONFIG_VARS ${TOOLCHAIN_CONFIG_VARS}MIPS_LINUX_SYSROOT
)
toolchain_save_config()

2.3 配置

cd ../../build   先退到opencv路径再创建build和install,不要在platforms/linux目录下创建cmake -DCMAKE_BUILD_TYPE=Debug -DCMAKE_TOOLCHAIN_FILE=../platforms/linux/mips.toolchain.cmake -DCMAKE_INSTALL_PREFIX=../install -DSOFTFP=ON -DENABLE_PROFILING=OFF -DWITH_OPENCL=OFF -DWITH_TBB=ON -DWITH_V4L=ON -DHAVE_CAMV4L2=ON -DBUILD_TESTS=OFF -DINSTALL_PYTHON_EXAMPLES=OFF -DBUILD_EXAMPLES=OFF -DWITH_FFMPEG=ON -DHAVE_FFMPEG=ON -DBUILD_opencv_js=OFF -DENABLE_NEON=OFF -DENABLE_VFPV3=OFF - ..

 配置后发现ffmpeg并没有找到

2.3.1 报错:can’t find ffmpeg – ‘pkg-config’ utility is missing

然后执行下面这一行

export PKG_CONFIG_PATH=/data3/sku_mount/chw/x264_ffmpeg_opencv_20241230/ffmpeg-3.3.9/install/lib/pkgconfig:$PKG_CONFIG_PATH

 然后继续config

cmake -DCMAKE_BUILD_TYPE=Debug -DCMAKE_TOOLCHAIN_FILE=../platforms/linux/mips.toolchain.cmake -DCMAKE_INSTALL_PREFIX=../install -DSOFTFP=ON -DENABLE_PROFILING=OFF -DWITH_OPENCL=OFF -DWITH_TBB=ON -DWITH_V4L=ON -DHAVE_CAMV4L2=ON -DBUILD_TESTS=OFF -DINSTALL_PYTHON_EXAMPLES=OFF -DBUILD_EXAMPLES=OFF -DWITH_FFMPEG=ON -DHAVE_FFMPEG=ON -DBUILD_opencv_js=OFF -DENABLE_NEON=OFF -DENABLE_VFPV3=OFF ..

然后看到这这篇博客:OpenCV+FFmpeg交叉编译_opencv ffmpeg-CSDN博客

 上面说原因是ffmpeg test code没有编译成功然后HAVE_FFMPEG被置为了OFF。

然后我在我的日志中搜test code果然发现了 

看opencv-3.4.9/cmake/OpenCVFindLibsVideo.cmake

 他的博客上说直接注释掉下面的内容,但其实不应该这么做。

因为注释掉之后发现为什么最后一个还是NO,

这里最后一个为什么还是NO,是因为ffmpeg中库libavresample改名为libswresample.so了,所以opencv找不到,其实修改 opencv-3.4.9/cmake/OpenCVFindLibsVideo.cmake中

就可以了, 也就是让opencv去找libswresample这个库。

所以就都找到了, 不需要像那篇博客上说的那样把内容注释掉,而是修改库的名字就可以了,

2.4 编译、安装

make -j8
make install

2.4.1编译报错:fatal error: zlib.h: No such file or directory

好吧,服了,这破东西,这是找不到zlib,处理png的图片时候需要用zlib,那么根据我之前交叉编译opencv时候cmake-gui的提示:ubuntu交叉编译opencv-CSDN博客

那次是用的cmake-gui,那么这次我在cmake中增加相应的配置, cmake命令中增加zlib的-DBUILD_ZLIB=ON -DZLIB_INCLUDE_DIR=/data3/sku_mount/chw/x264_ffmpeg_opencv_20241230/opencv-3.4.9/3rdparty/zlib,然后重新配置,重新编译。

cmake -DCMAKE_BUILD_TYPE=Debug -DCMAKE_TOOLCHAIN_FILE=../platforms/linux/mips.toolchain.cmake -DCMAKE_INSTALL_PREFIX=../install -DSOFTFP=ON -DENABLE_PROFILING=OFF -DWITH_OPENCL=OFF -DWITH_TBB=ON -DWITH_V4L=ON -DHAVE_CAMV4L2=ON -DBUILD_TESTS=OFF -DINSTALL_PYTHON_EXAMPLES=OFF -DBUILD_EXAMPLES=OFF -DWITH_FFMPEG=ON -DHAVE_FFMPEG=ON -DBUILD_opencv_js=OFF -DENABLE_NEON=OFF -DENABLE_VFPV3=OFF -DBUILD_ZLIB=ON -DZLIB_INCLUDE_DIR=/data3/sku_mount/chw/x264_ffmpeg_opencv_20241230/opencv-3.4.9/3rdparty/zlib ..

  2.4.2 报错:undefined reference to `avcodec_find_encoder@LIBAVCODEC_57

./../lib/libopencv_videoio.so.3.4.9: undefined reference to `avcodec_find_encoder@LIBAVCODEC_57'
../../lib/libopencv_videoio.so.3.4.9: undefined reference to `sws_getContext@LIBSWSCALE_4'
../../lib/libopencv_videoio.so.3.4.9: undefined reference to `av_frame_unref@LIBAVUTIL_55'
../../lib/libopencv_videoio.so.3.4.9: undefined reference to `av_write_frame@LIBAVFORMAT_57'
../../lib/libopencv_videoio.so.3.4.9: undefined reference to `av_log_set_level@LIBAVUTIL_55'
../../lib/libopencv_videoio.so.3.4.9: undefined reference to `avformat_close_input@LIBAVFORMAT_57'
../../lib/libopencv_videoio.so.3.4.9: undefined reference to `av_bitstream_filter_init@LIBAVCODEC_57'
../../lib/libopencv_videoio.so.3.4.9: undefined reference to `avformat_get_riff_video_tags@LIBAVFORMAT_57'
../../lib/libopencv_videoio.so.3.4.9: undefined reference to `avcodec_get_context_defaults3@LIBAVCODEC_57'
../../lib/libopencv_videoio.so.3.4.9: undefined reference to `avcodec_decode_video2@LIBAVCODEC_57'
../../lib/libopencv_videoio.so.3.4.9: undefined reference to `av_lockmgr_register@LIBAVCODEC_57'
../../lib/libopencv_videoio.so.3.4.9: undefined reference to `sws_freeContext@LIBSWSCALE_4'
../../lib/libopencv_videoio.so.3.4.9: undefined reference to `av_bitstream_filter_filter@LIBAVCODEC_57'
../../lib/libopencv_videoio.so.3.4.9: undefined reference to `av_malloc@LIBAVUTIL_55'
../../lib/libopencv_videoio.so.3.4.9: undefined reference to `av_read_frame@LIBAVFORMAT_57'
../../lib/libopencv_videoio.so.3.4.9: undefined reference to `avformat_alloc_context@LIBAVFORMAT_57'
../../lib/libopencv_videoio.so.3.4.9: undefined reference to `avformat_network_init@LIBAVFORMAT_57'
../../lib/libopencv_videoio.so.3.4.9: undefined reference to `av_guess_sample_aspect_ratio@LIBAVFORMAT_57'
../../lib/libopencv_videoio.so.3.4.9: undefined reference to `av_image_get_buffer_size@LIBAVUTIL_55'
../../lib/libopencv_videoio.so.3.4.9: undefined reference to `avcodec_flush_buffers@LIBAVCODEC_57'
../../lib/libopencv_videoio.so.3.4.9: undefined reference to `av_write_trailer@LIBAVFORMAT_57'
../../lib/libopencv_videoio.so.3.4.9: undefined reference to `av_dict_set@LIBAVUTI

好吧,这破东西是找不到库,直接在opencv-3.4.9/CMakeLists.txt中增加

link_directories("/data3/sku_mount/chw/x264_ffmpeg_opencv_20241230/ffmpeg-3.3.9/install/lib")

 然后还是重新直接cmake,然后make,还是报错,说明这个方法不行。

然后google搜索 交叉编译x264  ffmpeg opencv 关键字,看到了这篇博客:Linux aarch64-linux-gnu-交叉编译x264、ffmpeg、opencv并移植-CSDN博客

 它里面有这个

行,那我也试一下, 然后也不行,然后总之我又中查找,发现了这个命令可以用,

cmake -DCMAKE_BUILD_TYPE=Debug -DCMAKE_TOOLCHAIN_FILE=../platforms/linux/mips.toolchain.cmake -DCMAKE_INSTALL_PREFIX=../install -DSOFTFP=ON -DENABLE_PROFILING=OFF -DWITH_OPENCL=OFF -DWITH_TBB=ON -DWITH_V4L=ON -DHAVE_CAMV4L2=ON -DBUILD_TESTS=OFF -DINSTALL_PYTHON_EXAMPLES=OFF -DBUILD_EXAMPLES=OFF -DWITH_FFMPEG=ON -DHAVE_FFMPEG=ON -DBUILD_opencv_js=OFF -DENABLE_NEON=OFF -DENABLE_VFPV3=OFF -DBUILD_ZLIB=ON -DZLIB_INCLUDE_DIR=/data3/sku_mount/chw/x264_ffmpeg_opencv_20241230/opencv-3.4.9/3rdparty/zlib -DFFMPEG_LIBRARIES=/data3/sku_mount/chw/x264_ffmpeg_opencv_20241230/ffmpeg-3.3.9/install/lib/ -DFFMPEG_DIR=/data3/sku_mount/chw/x264_ffmpeg_opencv_20241230/ffmpeg-3.3.9/install/ -DFFMPEG_INCLUDE_DIR=/data3/sku_mount/chw/x264_ffmpeg_opencv_20241230/ffmpeg-3.3.9/install/include -DCMAKE_PREFIX_PATH=/data3/sku_mount/chw/x264_ffmpeg_opencv_20241230/ffmpeg-3.3.9/install/ ..

 但是我觉得虽然问题解决了,我还不知道哪一条起作用的,所以我做了下面的几个实验。

2.4.3最终使用的cmake命令

cmake -DCMAKE_BUILD_TYPE=Debug -DCMAKE_TOOLCHAIN_FILE=../platforms/linux/mips.toolchain.cmake -DCMAKE_INSTALL_PREFIX=../install -DSOFTFP=ON -DENABLE_PROFILING=OFF -DWITH_OPENCL=OFF -DWITH_TBB=ON -DWITH_V4L=ON -DHAVE_CAMV4L2=ON -DBUILD_TESTS=OFF -DINSTALL_PYTHON_EXAMPLES=OFF -DBUILD_EXAMPLES=OFF -DWITH_FFMPEG=ON -DHAVE_FFMPEG=ON -DBUILD_opencv_js=OFF -DENABLE_NEON=OFF -DENABLE_VFPV3=OFF -DBUILD_ZLIB=ON -DZLIB_INCLUDE_DIR=/data3/sku_mount/chw/x264_ffmpeg_opencv_20241230/opencv-3.4.9/3rdparty/zlib -DFFMPEG_LIBRARIES=/data3/sku_mount/chw/x264_ffmpeg_opencv_20241230/ffmpeg-3.3.9/install/lib/ -DFFMPEG_INCLUDE_DIR=/data3/sku_mount/chw/x264_ffmpeg_opencv_20241230/ffmpeg-3.3.9/install/include -DCMAKE_PREFIX_PATH=/data3/sku_mount/chw/x264_ffmpeg_opencv_20241230/ffmpeg-3.3.9/install/ ..

然后直接 make -j; make install就可以了。 编译出来之后,发现

file libopencv_videostab.so.3.4.9
libopencv_videostab.so.3.4.9: ELF 64-bit LSB shared object, x86-64, version 1 (GNU/Linux), dynamically linked, BuildID[sha1]=0b27b56ce5c93949283722a2b136399ebfa933dd, with debug_info, not stripped

这怎么是x86的。。。。。

 2.4.4 编译出来的库是x86的

针对编译出来的库是x86,那我觉得大概率是toolchain那个脚本不对,于是这次我只修改上层的opencv-3.4.9/platforms/linux/mips32r5el-gnu.toolchain.cmake 在里面增加交叉编译工具链的路径

set(CMAKE_SYSTEM_PROCESSOR mips32r5el)
set(GCC_COMPILER_VERSION "" CACHE STRING "GCC Compiler version")
set(GNU_MACHINE "/data3/t41_toolchain/mips-gcc720-uclibc0.9.33.2-r5.1.4/bin/mips-linux-uclibc" CACHE STRING "GNU compiler triple")include("${CMAKE_CURRENT_LIST_DIR}/mips.toolchain.cmake")

其实是类似的,可以看到opencv-3.4.9/platforms/linux/mips32r5el-gnu.toolchain.cmake里面包含了        include("${CMAKE_CURRENT_LIST_DIR}/mips.toolchain.cmake"),

然后opencv-3.4.9/platforms/linux/mips.toolchain.cmake内容也修改成mips32r2,因为我用的君正的是mips32r2的指令集。

然后make -j; make instll就可以了。然后file ../install/lib/libopencv_photo.so.3.4.9
../install/lib/libopencv_photo.so.3.4.9: ELF 32-bit LSB shared object, MIPS, MIPS32 rel2 version 1 (SYSV), dynamically linked, with debug_info, not stripped

发现可以了,是mips的了。

2.4.5 undefined reference to `avcodec_find_encoder@LIBAVCODEC_57----为什么这个错误又出现了

当我编译完成之后,我想把步骤重新来一遍,然后按照上面的步骤又试了下,然后发现这种找不到ffmpeg的错误又来了,不行,必须找到根本原因。然后我发现一个奇怪的现象

 2424  mv opencv-3.4.9 correct_backup_opencv-3.4.92425  unzip opencv-3.4.9.zip 2426  cd opencv-3.4.9/2427  ll2428  mkdir build2429  mkdir install2430  cd build2431  export PKG_CONFIG_PATH=/data3/sku_mount/chw/x264_ffmpeg_opencv_20241230/ffmpeg-3.3.9/install/lib/pkgconfig:$PKG_CONFIG_PATH2432  cmake -DCMAKE_BUILD_TYPE=Debug -DCMAKE_TOOLCHAIN_FILE=../platforms/linux/mips32r5el-gnu.toolchain.cmake -DCMAKE_INSTALL_PREFIX=../install -DSOFTFP=ON -DENABLE_PROFILING=OFF -DWITH_OPENCL=OFF -DWITH_TBB=ON -DWITH_V4L=ON -DHAVE_CAMV4L2=ON -DBUILD_TESTS=OFF -DINSTALL_PYTHON_EXAMPLES=OFF -DBUILD_EXAMPLES=OFF -DWITH_FFMPEG=ON -DHAVE_FFMPEG=ON -DBUILD_opencv_js=OFF -DENABLE_NEON=OFF -DENABLE_VFPV3=OFF -DBUILD_ZLIB=ON -DZLIB_INCLUDE_DIR=/data3/sku_mount/chw/x264_ffmpeg_opencv_20241230/opencv-3.4.9/3rdparty/zlib -DFFMPEG_LIBRARIES=/data3/sku_mount/chw/x264_ffmpeg_opencv_20241230/ffmpeg-3.3.9/install/lib/ -DFFMPEG_INCLUDE_DIR=/data3/sku_mount/chw/x264_ffmpeg_opencv_20241230/ffmpeg-3.3.9/install/include -DCMAKE_PREFIX_PATH=/data3/sku_mount/chw/x264_ffmpeg_opencv_20241230/ffmpeg-3.3.9/install/ ..2433  make -j2434  export PKG_CONFIG_PATH=/data3/sku_mount/chw/x264_ffmpeg_opencv_20241230/ffmpeg-3.3.9/install/lib/pkgconfig:$PKG_CONFIG_PATH2435  make -j2436  make clean2437  cmake -DCMAKE_BUILD_TYPE=Debug -DCMAKE_TOOLCHAIN_FILE=../platforms/linux/mips32r5el-gnu.toolchain.cmake -DCMAKE_INSTALL_PREFIX=../install -DSOFTFP=ON -DENABLE_PROFILING=OFF -DWITH_OPENCL=OFF -DWITH_TBB=ON -DWITH_V4L=ON -DHAVE_CAMV4L2=ON -DBUILD_TESTS=OFF -DINSTALL_PYTHON_EXAMPLES=OFF -DBUILD_EXAMPLES=OFF -DWITH_FFMPEG=ON -DHAVE_FFMPEG=ON -DBUILD_opencv_js=OFF -DENABLE_NEON=OFF -DENABLE_VFPV3=OFF -DBUILD_ZLIB=ON -DZLIB_INCLUDE_DIR=/data3/sku_mount/chw/x264_ffmpeg_opencv_20241230/opencv-3.4.9/3rdparty/zlib -DFFMPEG_LIBRARIES=/data3/sku_mount/chw/x264_ffmpeg_opencv_20241230/ffmpeg-3.3.9/install/lib/ -DFFMPEG_INCLUDE_DIR=/data3/sku_mount/chw/x264_ffmpeg_opencv_20241230/ffmpeg-3.3.9/install/include -DCMAKE_PREFIX_PATH=/data3/sku_mount/chw/x264_ffmpeg_opencv_20241230/ffmpeg-3.3.9/install/ ..2438  export PKG_CONFIG_PATH=/data3/sku_mount/chw/x264_ffmpeg_opencv_20241230/ffmpeg-3.3.9/install/lib/pkgconfig:$PKG_CONFIG_PATH2439  make -j2440  history]2441  history

我发现我的命令都是一样的,但是执行2433的make -j的时候报错,但是当我2439的那次make -j发现并不报错了,前后两次的命令一模一样的呀,那么为什么,一定是哪里做错了,我反复试了几次,有时候成功,有时候报错,那么问题在哪里,问题到了这里已经有些离谱了,这时候感觉是我的服务器环境有问题了。。。。。。。。。。。。需要把当前的xshell终端给关了,重新打开一个继续做实验。

2.5 换个新的xshell终端做实验

换个新的xshell终端,然后把之前的opencv删掉,重新unzip一个,然后做实验。

实验过程不写了,直接把正确步骤写到下面正确步骤的目录.

3 交叉编译opencv----整理后的正确步骤,直接看这个

 3.1 下载源码

首先也还是下载opencv源码Releases - OpenCV,

unzip opencv-3.4.9.zip
cd opencv-3.4.9/
mkdir build
mkdir install

3.2 修改../platforms/linux/mips.toolchain.cmake和../platforms/linux/mips32r5el-gnu.toolchain.cmake

修改../platforms/linux/mips32r5el-gnu.toolchain.cmake在里面添加上交叉编译工具链的路径

set(CMAKE_SYSTEM_PROCESSOR mips32r5el)
set(GCC_COMPILER_VERSION "" CACHE STRING "GCC Compiler version")
set(GNU_MACHINE "/data3/t41_toolchain/mips-gcc720-uclibc0.9.33.2-r5.1.4/bin/mips-linux-uclibc" CACHE STRING "GNU compiler triple")include("${CMAKE_CURRENT_LIST_DIR}/mips.toolchain.cmake")

因为我用的君正t41是mips32r2指令集的,所以修改../platforms/linux/mips.toolchain.cmake(这个不是mips32r5el-gnu.toolchain.cmake,mips32r5el-gnu.toolchain.cmake会包含mips.toolchain.cmake)里面把-march=mips32r5修改成-march=mips32r2。并且加上ffmpeg的链接路径,并且把-mmsa -mhard-float  -O3这些东西删掉。修改后的如下

为什么这么改

  • 增加的-Wl,-rpath-link=/data3/sku_mount/chw/x264_ffmpeg_opencv_20241230/ffmpeg-3.4.13/install/lib/才是解决 undefined reference to `avcodec_find_encoder@LIBAVCODEC_57那一堆错误的方法,也就是加上ffmpeg库的路径,找到库了就不会报错了。
  • 删掉-mmsa -mhard-float  -O3是为了解决后面程序运行时候的illegal instruction,这个illegal instruction的原因一个是硬件上有些计算芯片不支持,另一个就是O3之后有问题,所以这两个删掉。
  • 然后我的君正t41是mips32r2,所以修改成-march=mips32r2
# ----------------------------------------------------------------------------------------------
#  MIPS ToolChanin can be downloaded from https://www.mips.com/develop/tools/codescape-mips-sdk/ .
#  Toolchains with 'mti' in the name (and install directory) are for MIPS R2-R5 instruction sets.
#  Toolchains with 'img' in the name are for MIPS R6 instruction sets.
#  It is recommended to use cmake-gui application for build scripts configuration and generation:
#  1. Run cmake-gui
#  2. Specifiy toolchain file for cross-compiling, mips32r5el-gnu.toolchian.cmake or mips64r6el-gnu.toolchain.cmake
#     can be selected.
#  3. Configure and Generate makefiles.
#  4. make -j4 & make install
# ----------------------------------------------------------------------------------------------if(COMMAND toolchain_save_config)return() # prevent recursive call
endif()set(CMAKE_SYSTEM_NAME Linux)
set(CMAKE_SYSTEM_VERSION 1)
if(NOT DEFINED CMAKE_SYSTEM_PROCESSOR)set(CMAKE_SYSTEM_PROCESSOR mips)
endif()include("${CMAKE_CURRENT_LIST_DIR}/gnu.toolchain.cmake")if(CMAKE_SYSTEM_PROCESSOR STREQUAL mips AND NOT MIPS_IGNORE_FP)set(FLOAT_ABI_SUFFIX "")
endif()if(NOT "x${GCC_COMPILER_VERSION}" STREQUAL "x")set(__GCC_VER_SUFFIX "-${GCC_COMPILER_VERSION}")
endif()if(NOT DEFINED CMAKE_C_COMPILER)find_program(CMAKE_C_COMPILER NAMES ${GNU_MACHINE}${FLOAT_ABI_SUFFIX}-gcc${__GCC_VER_SUFFIX})
endif()
if(NOT DEFINED CMAKE_CXX_COMPILER)find_program(CMAKE_CXX_COMPILER NAMES ${GNU_MACHINE}${FLOAT_ABI_SUFFIX}-g++${__GCC_VER_SUFFIX})
endif()
if(NOT DEFINED CMAKE_LINKER)find_program(CMAKE_LINKER NAMES ${GNU_MACHINE}${FLOAT_ABI_SUFFIX}-ld${__GCC_VER_SUFFIX} ${GNU_MACHINE}${FLOAT_ABI_SUFFIX}-ld)
endif()
if(NOT DEFINED CMAKE_AR)find_program(CMAKE_AR NAMES ${GNU_MACHINE}${FLOAT_ABI_SUFFIX}-ar${__GCC_VER_SUFFIX} ${GNU_MACHINE}${FLOAT_ABI_SUFFIX}-ar)
endif()if(NOT DEFINED MIPS_LINUX_SYSROOT AND DEFINED GNU_MACHINE)set(MIPS_LINUX_SYSROOT /usr/bin)
endif()if(NOT DEFINED CMAKE_CXX_FLAGS)if(CMAKE_SYSTEM_PROCESSOR MATCHES "mips32r5el")set(CMAKE_C_FLAGS             "-Wl,-rpath-link=/data3/sku_mount/chw/x264_ffmpeg_opencv_20241230/ffmpeg-3.4.13/install/lib/ -march=mips32r2 -EL  -mfp64 -mnan=2008 -mabs=2008  -ffp-contract=off " CACHE INTERNAL "")set(CMAKE_SHARED_LINKER_FLAGS "" CACHE INTERNAL "")set(CMAKE_CXX_FLAGS           "-Wl,-rpath-link=/data3/sku_mount/chw/x264_ffmpeg_opencv_20241230/ffmpeg-3.4.13/install/lib/ -march=mips32r2 -EL  -mfp64 -mnan=2008 -mabs=2008  -ffp-contract=off " CACHE INTERNAL "")set(CMAKE_MODULE_LINKER_FLAGS "" CACHE INTERNAL "")set(CMAKE_EXE_LINKER_FLAGS    "-lpthread -lrt -ldl -latomic" CACHE INTERNAL "Added for mips cross build error")set(CMAKE_CXX_FLAGS           "${CMAKE_CXX_FLAGS} -fdata-sections  -Wa,--noexecstack -fsigned-char -Wno-psabi")set(CMAKE_C_FLAGS             "${CMAKE_C_FLAGS} -fdata-sections  -Wa,--noexecstack -fsigned-char -Wno-psabi")elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "mips64r6el")set(CMAKE_C_FLAGS             "-O3 -march=i6500 -EL -mmsa -mabi=64 -mhard-float -mfp64 -mnan=2008" CACHE INTERNAL "")set(CMAKE_SHARED_LINKER_FLAGS "" CACHE INTERNAL "")set(CMAKE_CXX_FLAGS           "-O3 -march=i6500 -EL -mmsa -mabi=64 -mhard-float -mfp64 -mnan=2008" CACHE INTERNAL "")set(CMAKE_MODULE_LINKER_FLAGS "" CACHE INTERNAL "")set(CMAKE_EXE_LINKER_FLAGS    "-lpthread -lrt -ldl" CACHE INTERNAL "Added for mips cross build error")set(CMAKE_CXX_FLAGS           "${CMAKE_CXX_FLAGS} -fdata-sections -Wa,--noexecstack -fsigned-char -Wno-psabi")set(CMAKE_C_FLAGS             "${CMAKE_C_FLAGS} -fdata-sections -Wa,--noexecstack -fsigned-char -Wno-psabi")endif()set(CMAKE_SHARED_LINKER_FLAGS "${MIPS_LINKER_FLAGS} ${CMAKE_SHARED_LINKER_FLAGS}")set(CMAKE_MODULE_LINKER_FLAGS "${MIPS_LINKER_FLAGS} ${CMAKE_MODULE_LINKER_FLAGS}")set(CMAKE_EXE_LINKER_FLAGS    "${MIPS_LINKER_FLAGS} ${CMAKE_EXE_LINKER_FLAGS}")
endif()set(CMAKE_FIND_ROOT_PATH ${CMAKE_FIND_ROOT_PATH} ${MIPS_LINUX_SYSROOT})set(TOOLCHAIN_CONFIG_VARS ${TOOLCHAIN_CONFIG_VARS}MIPS_LINUX_SYSROOT
)
toolchain_save_config()

3.3 配置PKG_CONFIG_LIBDIR

export PKG_CONFIG_LIBDIR=/data3/sku_mount/chw/x264_ffmpeg_opencv_20241230/ffmpeg-3.4.13/install/lib/pkgconfig/:$PKG_CONFIG_LIBDIR

用PKG_CONFIG_LIBDIR不要用PKG_CONFIG_PATH。 

  •  PKG_CONFIG_PATH:用于扩展 pkg-config 的搜索路径,适合添加额外的库路径而不影响默认路径。
  • PKG_CONFIG_LIBDIR:用于完全替换 pkg-config 的默认搜索路径,适合需要严格控制库路径的场景,如交叉编译。

3.4 cmake

cd build
cmake -DCMAKE_BUILD_TYPE=Debug -DCMAKE_TOOLCHAIN_FILE=../platforms/linux/mips32r5el-gnu.toolchain.cmake -DCMAKE_INSTALL_PREFIX=../install -DBUILD_TESTS=OFF  -DBUILD_EXAMPLES=OFF -DWITH_FFMPEG=ON -DHAVE_FFMPEG=ON -DBUILD_ZLIB=ON -DZLIB_INCLUDE_DIR=/data3/sku_mount/chw/x264_ffmpeg_opencv_20241230/opencv-3.4.9/3rdparty/zlib ..

cmake命令中也不需要增加那些什么FFMPEG的头文件路径库文件路径一类的。 

3.5 编译、安装

make -j
make install

然后

file ../install/lib/libopencv_videoio.so.3.4.9
../install/lib/libopencv_videoio.so.3.4.9: ELF 32-bit LSB shared object, MIPS, MIPS32 rel2 version 1 (SYSV), dynamically linked, with debug_info, not stripped

可以了。

4 软件解码

直接就用opencv的接口读取视频

    VideoCapture cap(inputPath);if (!cap.isOpened()) {cerr << "Error opening video stream or file" << endl;return -1;}

4.1 libopencv_core.so: undefined reference to `__atomic_compare_exchange_8'

我的opencv编译通过之后,我把我的opencv库放到我的工程中使用的时候,编译报这个错误

./lib/opencv/libopencv_core.so: undefined reference to `__atomic_compare_exchange_8'
./lib/opencv/libopencv_core.so: undefined reference to `__atomic_fetch_sub_8'
./lib/opencv/libopencv_core.so: undefined reference to `__atomic_load_8'
./lib/opencv/libopencv_core.so: undefined reference to `__atomic_store_8'
./lib/opencv/libopencv_core.so: undefined reference to `__atomic_fetch_add_8'
collect2: error: ld returned 1 exit status

我本来以为又是opencv编译有问题,但是我去看了下我opencv的opencv-3.4.9/platforms/linux/mips.toolchain.cmake里面有一个

set(CMAKE_EXE_LINKER_FLAGS    "-lpthread -lrt -ldl -latomic" CACHE INTERNAL "Added for mips cross build error")

然后那么我又看了下我的工程的makefile,我觉得问题在于我工程中没有包含atomic,所以我在工程的makefile中增加-latomic,重新编译,问题解决。

4.2 illegal instruction

再次运行程序,提示illegal instruction,然后网上搜大多数说是ffmpeg的问题,但是我按照网上的各种方法试了,不行,然后我调试发现

那就是跟opencv有关系,于是我修改opencv-3.4.9/platforms/linux/mips.toolchain.cmake把里面的类似-mmsa -mhard-float  -O3等这些东西去掉,最终改成

# ----------------------------------------------------------------------------------------------
#  MIPS ToolChanin can be downloaded from https://www.mips.com/develop/tools/codescape-mips-sdk/ .
#  Toolchains with 'mti' in the name (and install directory) are for MIPS R2-R5 instruction sets.
#  Toolchains with 'img' in the name are for MIPS R6 instruction sets.
#  It is recommended to use cmake-gui application for build scripts configuration and generation:
#  1. Run cmake-gui
#  2. Specifiy toolchain file for cross-compiling, mips32r5el-gnu.toolchian.cmake or mips64r6el-gnu.toolchain.cmake
#     can be selected.
#  3. Configure and Generate makefiles.
#  4. make -j4 & make install
# ----------------------------------------------------------------------------------------------if(COMMAND toolchain_save_config)return() # prevent recursive call
endif()set(CMAKE_SYSTEM_NAME Linux)
set(CMAKE_SYSTEM_VERSION 1)
if(NOT DEFINED CMAKE_SYSTEM_PROCESSOR)set(CMAKE_SYSTEM_PROCESSOR mips)
endif()include("${CMAKE_CURRENT_LIST_DIR}/gnu.toolchain.cmake")if(CMAKE_SYSTEM_PROCESSOR STREQUAL mips AND NOT MIPS_IGNORE_FP)set(FLOAT_ABI_SUFFIX "")
endif()if(NOT "x${GCC_COMPILER_VERSION}" STREQUAL "x")set(__GCC_VER_SUFFIX "-${GCC_COMPILER_VERSION}")
endif()if(NOT DEFINED CMAKE_C_COMPILER)find_program(CMAKE_C_COMPILER NAMES ${GNU_MACHINE}${FLOAT_ABI_SUFFIX}-gcc${__GCC_VER_SUFFIX})
endif()
if(NOT DEFINED CMAKE_CXX_COMPILER)find_program(CMAKE_CXX_COMPILER NAMES ${GNU_MACHINE}${FLOAT_ABI_SUFFIX}-g++${__GCC_VER_SUFFIX})
endif()
if(NOT DEFINED CMAKE_LINKER)find_program(CMAKE_LINKER NAMES ${GNU_MACHINE}${FLOAT_ABI_SUFFIX}-ld${__GCC_VER_SUFFIX} ${GNU_MACHINE}${FLOAT_ABI_SUFFIX}-ld)
endif()
if(NOT DEFINED CMAKE_AR)find_program(CMAKE_AR NAMES ${GNU_MACHINE}${FLOAT_ABI_SUFFIX}-ar${__GCC_VER_SUFFIX} ${GNU_MACHINE}${FLOAT_ABI_SUFFIX}-ar)
endif()if(NOT DEFINED MIPS_LINUX_SYSROOT AND DEFINED GNU_MACHINE)set(MIPS_LINUX_SYSROOT /usr/bin)
endif()if(NOT DEFINED CMAKE_CXX_FLAGS)if(CMAKE_SYSTEM_PROCESSOR MATCHES "mips32r5el")set(CMAKE_C_FLAGS             "-Wl,-rpath-link=/data3/sku_mount/chw/x264_ffmpeg_opencv_20241230/ffmpeg-4.1.3/install/lib/ -march=mips32r2 -EL -mmsa -mhard-float -mfp64 -mnan=2008 -mabs=2008 -O3 -ffp-contract=off -mtune=p5600" CACHE INTERNAL "")set(CMAKE_SHARED_LINKER_FLAGS "" CACHE INTERNAL "")set(CMAKE_CXX_FLAGS           "-Wl,-rpath-link=/data3/sku_mount/chw/x264_ffmpeg_opencv_20241230/ffmpeg-4.1.3/install/lib/ -march=mips32r2 -EL -mmsa -mhard-float -mfp64 -mnan=2008 -mabs=2008 -O3 -ffp-contract=off -mtune=p5600" CACHE INTERNAL "")set(CMAKE_MODULE_LINKER_FLAGS "" CACHE INTERNAL "")set(CMAKE_EXE_LINKER_FLAGS    "-lpthread -lrt -ldl -latomic" CACHE INTERNAL "Added for mips cross build error")set(CMAKE_CXX_FLAGS           "${CMAKE_CXX_FLAGS} -fdata-sections  -Wa,--noexecstack -fsigned-char -Wno-psabi")set(CMAKE_C_FLAGS             "${CMAKE_C_FLAGS} -fdata-sections  -Wa,--noexecstack -fsigned-char -Wno-psabi")elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "mips64r6el")set(CMAKE_C_FLAGS             "-O3 -march=i6500 -EL -mmsa -mabi=64 -mhard-float -mfp64 -mnan=2008" CACHE INTERNAL "")set(CMAKE_SHARED_LINKER_FLAGS "" CACHE INTERNAL "")set(CMAKE_CXX_FLAGS           "-O3 -march=i6500 -EL -mmsa -mabi=64 -mhard-float -mfp64 -mnan=2008" CACHE INTERNAL "")set(CMAKE_MODULE_LINKER_FLAGS "" CACHE INTERNAL "")set(CMAKE_EXE_LINKER_FLAGS    "-lpthread -lrt -ldl" CACHE INTERNAL "Added for mips cross build error")set(CMAKE_CXX_FLAGS           "${CMAKE_CXX_FLAGS} -fdata-sections -Wa,--noexecstack -fsigned-char -Wno-psabi")set(CMAKE_C_FLAGS             "${CMAKE_C_FLAGS} -fdata-sections -Wa,--noexecstack -fsigned-char -Wno-psabi")endif()set(CMAKE_SHARED_LINKER_FLAGS "${MIPS_LINKER_FLAGS} ${CMAKE_SHARED_LINKER_FLAGS}")set(CMAKE_MODULE_LINKER_FLAGS "${MIPS_LINKER_FLAGS} ${CMAKE_MODULE_LINKER_FLAGS}")set(CMAKE_EXE_LINKER_FLAGS    "${MIPS_LINKER_FLAGS} ${CMAKE_EXE_LINKER_FLAGS}")
endif()set(CMAKE_FIND_ROOT_PATH ${CMAKE_FIND_ROOT_PATH} ${MIPS_LINUX_SYSROOT})set(TOOLCHAIN_CONFIG_VARS ${TOOLCHAIN_CONFIG_VARS}MIPS_LINUX_SYSROOT
)
toolchain_save_config()

然后不报错illegal instruction了,但是运行又出现了新的错误。

4.3 错误: CAP_IMAGES: Stop scanning. Can't read image file

 ./gdbserver :1234 ./sku_demo  ./image/test.h264   ./image/masaic.mp4
Process ./sku_demo created; pid = 696
Listening on port 1234
Remote debugging from host 192.168.1.10
[AIP@12b00000] successfully initialized, version[10105]
inputPath: ./image/test.h264
[ INFO:0] VIDEOIO: Enabled backends(4, sorted by priority): FFMPEG(1000); V4L2(990); CV_IMAGES(980); CV_MJPEG(970)
warning: Error opening file (/data3/sku_mount/chw/x264_ffmpeg_opencv_20241230/opencv-3.4.9/modules/videoio/src/cap_ffmpeg_impl.hpp:940)
warning: ./image/test.h264 (/data3/sku_mount/chw/x264_ffmpeg_opencv_20241230/opencv-3.4.9/modules/videoio/src/cap_ffmpeg_impl.hpp:941)
[ INFO:0] Pattern: ./image/test.h%03d @ 264
[ INFO:0] CAP_IMAGES: Stop scanning. Can't read image file: ./image/test.h264
Error opening video stream or fileChild exited with status 255

我明明是想打开视频,但是报错怎么是image file,论七八糟的,我现在先不运行我的工程代码了,我先试试命令行不行,先保证命令行了之后再往下进行

./ffmpeg -i /mnt/chw/cars.mp4 -threads 0 -f mp4 -movflags +faststart decoded_output.mp4 

我又重新下载ffmpeg代码,然后编译完了之后,./ffmpeg -i /mnt/chw/cars.mp4 -threads 0 -f mp4 -movflags +faststart decoded_output.mp4 
可以用了,但是继续运行我的工程代码,发现还是报错

 ./sku_demo ./image/cars.mp4 ./image/m
as.mp4
[AIP@12b00000] successfully initialized, version[10105]
inputPath: ./image/cars.mp4
[ INFO:0] VIDEOIO: Enabled backends(4, sorted by priority): FFMPEG(1000); V4L2(990); CV_IMAGES(980); CV_MJPEG(970)
OpenCV: FFMPEG: tag 0x34363248/'H264' is not supported with codec id 28 and format 'mp4 / MP4 (MPEG-4 Part 14)'
OpenCV: FFMPEG: fallback to use tag 0x31637661/'avc1'
[h264_v4l2m2m @ 0xa84560] Could not find a valid device
[h264_v4l2m2m @ 0xa84560] can't configure encoder
Could not open codec 'h264_v4l2m2m': Unspecified error
Could not open the output video file for write

这是因为我不仅仅用ffmpeg解码,我还用他编码了,我先把编码的删掉,只用opencv ffmpeg打开视频就不会报错了,至于编码后面我会用君正的SDK做硬件编码。 

5 交叉编译ffmepg----正确步骤,直接看这个

通过上面的这些错误,我重新整理了一下正确的步骤。 

5.1 下载源码 

 Download FFmpeg

这次下载3.4.13的版本。 

5.2 配置

tar xzvf ffmpeg-3.4.13.tar.gz 
cd ffmpeg-3.4.13/
mkdir install
 ./configure --cross-prefix=mips-linux-uclibc- --enable-cross-compile --target-os=linux --cc=mips-linux-uclibc-gcc --arch=mips --prefix=$PWD/install --enable-shared --disable-static --enable-ffmpeg --enable-mips32r2 --disable-mips32r5 --disable-mips64r2 --disable-mips32r6 --disable-mips64r6 --disable-mipsdsp --disable-mipsdspr2 --disable-mipsfpu

5.3 编译、安装

make -j
make install

然后在板子上用下面的命令发现可以

./ffmpeg -i /mnt/chw/cars.mp4 -threads 0 -f mp4 -movflags +faststart decoded_output.mp4 

参考文献:

Linux aarch64-linux-gnu-交叉编译x264、ffmpeg、opencv并移植-CSDN博客

ubuntu交叉编译opencv-CSDN博客

RK1808交叉编译opencv with ffmpeg(解决FFMPEG始终为NO)_交叉编译opencv带有ffmpeg-CSDN博客

OpenCV+FFmpeg交叉编译_opencv ffmpeg-CSDN博客

Linux aarch64-linux-gnu-交叉编译x264、ffmpeg、opencv并移植-CSDN博客

 Download FFmpeg

 

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.rhkb.cn/news/503012.html

如若内容造成侵权/违法违规/事实不符,请联系长河编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

感知器的那些事

感知器的那些事 历史背景Rosenblatt和Minsky关于感知机的争论弗兰克罗森布拉特简介提出感知器算法Mark I感知机争议与分歧马文明斯基简介单层感知器工作原理训练过程多层感知器工作原理单层感知机 vs 多层感知机感知器模型(Perceptron),是由心理学家Frank Rosenblatt在1957年…

C语言:枚举类型

一、枚举类型的声明 枚举顾名思义就是一一列举。我们可以把可能的取值一一列举。比如我们现实生活中&#xff1a; 星期一到星期日是有限的7天&#xff0c;可以一一列举 &#xff1b;性别有&#xff1a;男、女、保密&#xff0c;也可以一一列举 &#xff1b;月份有12个月&#x…

25/1/6 算法笔记<强化学习> 初玩V-REP

我们安装V-REP之后&#xff0c;使用的是下面Git克隆的项目。 git clone https://github.com/deep-reinforcement-learning_book/Chapter16-Robot-Learning-in-Simulation.git 项目中直接组装好了一个机械臂。 我们先来分析下它的对象树 DefaultCamera:摄像机&#xff0c;用于…

CODESYS MODBUS TCP通信(AM400PLC作为主站通信)

禾川Q1 PLC MODBUS-TCP通信 禾川Q1 PLC MODBUS-TCP通信(CODESYS平台完整配置+代码)-CSDN博客文章浏览阅读17次。MATLAB和S7-1200PLC水箱液位高度PID控制联合仿真(MODBUSTCP通信)_将matlab仿真导入plc-CSDN博客文章浏览阅读722次。本文详细介绍了如何使用MATLAB与S7-1200PLC进行…

OSPF - 影响OSPF邻居建立的因素

总结为这么10种 routerID 冲突区域id不一致认证MA网络掩码需一致区域类型(特殊区域)hello、dead时间MTU(如果开启检查)静默接口网络类型不匹配MA网络中路由器接口优先级全为0 如何建立邻居可以查看上一篇文章&#xff0c;可以直接专栏找&#xff08;&#x1f92b;挂链接会没流…

【大数据】(选修)实验4 安装熟悉HBase数据库并实践

实验4 安装熟悉HBase数据库并实践 1、实验目的 (1)理解HBase在Hadoop体系结构中的角色; (2)熟练使用HBase操作常用的Shell命令; (3)熟悉HBase操作常用的Java API。 2、实验平台 操作系统:Linux Hadoop版本:2.6.0或以上版本 HBase版本:1.1.2或以上版本 JDK版…

windeployqt.exe打包qt程序总结(MSVC)

文章目录 前言打包步骤问题 前言 打包环境&#xff1a;windows10VS2017QT5.12.12 参考&#xff1a;Qt 打包发布程序&#xff0c;解决找不到msvcp140.dll等动态库问题正确方案 打包步骤 运行Qt5.12.12&#xff08;MSVC 2017 64-bits&#xff09; 在开始软件菜单里找到Qt文件夹…

算法的学习笔记—不用常规控制语句求 1 到 n 的和

&#x1f600;前言 在算法编程中&#xff0c;有时我们会遇到一些特殊的限制条件&#xff0c;这些限制会迫使我们跳出常规思维。本文讨论的问题就是一个典型案例&#xff1a;在不能使用基本控制语句的情况下&#xff0c;如何求解 1 到 n 的和。这个问题不仅考验编程技巧&#xf…

计算机网络 (27)IP多播

前言 IP多播&#xff08;也称多址广播或组播&#xff09;技术是一种允许一台或多台主机&#xff08;多播源&#xff09;发送单一数据包到多台主机&#xff08;一次性的、同时的&#xff09;的TCP/IP网络技术。 一、基本概念 定义&#xff1a;多播作为一点对多点的通信&#xff…

CSS 学习之正确看待 CSS 世界里的 margin 合并

一、什么是 margin 合并 块级元素的上外边距(margin-top)与下外边距(margin-bottom)有时会合并为单个外边距&#xff0c;这样的现象称为“margin 合并”。从此定义上&#xff0c;我们可以捕获两点重要的信息。 块级元素&#xff0c;但不包括浮动和绝对定位元素&#xff0c;尽…

小程序组件 —— 28 组件案例 - 推荐商品区域 - 实现结构样式

这一节目标是实现底部推荐商品的结构和样式&#xff0c;由于这里要求横向滚动&#xff0c;所以需要使用上节介绍的 scroll-view 功能&#xff0c;并使用 scroll-x 属性支持横向滚动&#xff0c;推荐商品区域中的每一个商品是一个单独的 view&#xff0c;每个view 中需要写三个组…

单片机-LED点阵实验

要将第一个点点亮&#xff0c;则 1 脚接高电平 a 脚接低电平&#xff0c;则第一个点就亮了&#xff1b;如果要将第一行点亮&#xff0c;则第 1 脚要接高电平&#xff0c;而&#xff08;a、b、c、d、e、f、g、h &#xff09;这些引脚接低电平&#xff0c;那么第一行就会点亮&…

软件项目体系建设文档,项目开发实施运维,审计,安全体系建设,验收交付,售前资料(word原件)

软件系统实施标准化流程设计至关重要&#xff0c;因为它能确保开发、测试、部署及维护等各阶段高效有序进行。标准化流程能减少人为错误&#xff0c;提升代码质量和系统稳定性。同时&#xff0c;它促进了团队成员间的沟通与协作&#xff0c;确保项目按时交付。此外&#xff0c;…

Java基础 注解

分类 Java自带的标准注解&#xff0c;包括Override、Deprecated和SuppressWarnings&#xff0c;分别用于标明重写某个方法、标明某个类或方法过时、标明要忽略的警告&#xff0c;用这些注解标明后编译器就会进行检查。元注解&#xff0c;元注解是用于定义注解的注解&#xff0…

Linux中rsync命令使用

一、rsync简介 rsync 是一种高效的文件复制和同步工具&#xff0c;常用于在本地或远程计算机之间同步文件和目录 主要特性增量同步&#xff1a;rsync 会检测源和目标文件之间的差异&#xff0c;只传输发生变化的部分&#xff0c;而不是重新传输整个文件。这样就能有效减少数据…

基于STM32的自动水满报警系统设计

目录 引言系统设计 硬件设计软件设计系统功能模块 水位检测模块报警模块自动控制模块控制算法 水位检测逻辑报警触发逻辑代码实现 水位检测模块报警控制模块自动控制逻辑系统调试与优化结论与展望 1. 引言 水满报警系统在家庭、农业、工业等领域广泛应用&#xff0c;通过实时…

【Java数据结构】二叉树

1.树型结构 1.1树的概念 树是一种非线性的数据结构&#xff0c;由n个结点组成的具有层次关系的集合。下面是它的特点&#xff1a; 根结点是没有前驱的结点&#xff08;没有父结点的结点&#xff09;子结点之间互不相交除了根结点外&#xff0c;其它结点都只有一个父结点n个结…

学习threejs,导入AWD格式的模型

&#x1f468;‍⚕️ 主页&#xff1a; gis分享者 &#x1f468;‍⚕️ 感谢各位大佬 点赞&#x1f44d; 收藏⭐ 留言&#x1f4dd; 加关注✅! &#x1f468;‍⚕️ 收录于专栏&#xff1a;threejs gis工程师 文章目录 一、&#x1f340;前言1.1 ☘️THREE.AWDLoader AWD模型加…

Chapter4.3:Implementing a feed forward network with GELU activations

4 Implementing a GPT model from Scratch To Generate Text 4.3 Implementing a feed forward network with GELU activations 本节即将实现子模块&#xff0c;用于transformer block&#xff08;变换器块&#xff09;的一部分。为此&#xff0c;我们需要从激活函数开始。 深…

弥散张量分析开源软件 DSI Studio 简体中文汉化版可以下载了

网址&#xff1a; (63条消息) DSIStudio简体中文汉化版(2022年7月)-算法与数据结构文档类资源-CSDN文库