君正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.9
 2425  unzip opencv-3.4.9.zip 
 2426  cd opencv-3.4.9/
 2427  ll
 2428  mkdir build
 2429  mkdir install
 2430  cd build
 2431  export PKG_CONFIG_PATH=/data3/sku_mount/chw/x264_ffmpeg_opencv_20241230/ffmpeg-3.3.9/install/lib/pkgconfig:$PKG_CONFIG_PATH
 2432  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 -j
 2434  export PKG_CONFIG_PATH=/data3/sku_mount/chw/x264_ffmpeg_opencv_20241230/ffmpeg-3.3.9/install/lib/pkgconfig:$PKG_CONFIG_PATH
 2435  make -j
 2436  make clean
 2437  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_PATH
 2439  make -j
 2440  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 file

Child 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

 

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

如若内容造成侵权/违法违规/事实不符,请联系我们进行投诉反馈qq邮箱809451989@qq.com,一经查实,立即删除!

相关文章

Sublime Text4 4189 安装激活【 2025年1月3日 亲测可用】

-----------------测试时间2025年1月3日------------------- 下载地址 官方网址&#xff1a;https://www.sublimetext.com 更新日志&#xff1a;https://www.sublimetext.com/download V4189 64位&#xff1a;https://www.sublimetext.com/download_thanks?targetwin-x64 ....…

Zabbix5.0版本(监控Nginx+PHP服务状态信息)

目录 1.监控Nginx服务状态信息 &#xff08;1&#xff09;通过Nginx监控模块&#xff0c;监控Nginx的7种状态 &#xff08;2&#xff09;开启Nginx状态模块 &#xff08;3&#xff09;配置监控项 &#xff08;4&#xff09;创建模板 &#xff08;5&#xff09;用默认键值…

Java高频面试之SE-08

hello啊&#xff0c;各位观众姥爷们&#xff01;&#xff01;&#xff01;本牛马baby今天又来了&#xff01;哈哈哈哈哈嗝&#x1f436; 成员变量和局部变量的区别有哪些&#xff1f; 在 Java 中&#xff0c;成员变量和局部变量是两种不同类型的变量&#xff0c;它们在作用域…

Linux(Centos 7.6)命令行快捷键

Linux(Centos 7.6)操作系统一般都是使用命令行进行管理&#xff0c;如何能高效的进行命令编辑与执行&#xff0c;需要我们记住一些常见的命令&#xff0c;也需要连接一些常见快捷键的使用&#xff0c;常见快捷键如下&#xff1a; 快捷键快捷键说明tab命令行补齐ctrlr快速查找之…

Geoserver修行记-后端调用WMS/WMTS服务无找不到图层Could not find layer

项目场景 调用geoserver地图服务WMS,找不到图层 我在进行地图服务调用的时候&#xff0c;总是提示我找不多图层 Could not find layer&#xff0c;重点是这个图层我明明是定义了&#xff0c;发布了&#xff0c;且还能够正常查看图层的wms的样式&#xff0c;但是在调用后端调用…

ip属地的信息准确吗?ip归属地不准确怎么办

在数字化时代&#xff0c;IP属地信息成为了我们日常生活中不可或缺的一部分。在各大社交媒体平台上&#xff0c;IP属地信息都扮演着重要的角色。然而&#xff0c;随着技术的不断进步和网络的复杂性增加&#xff0c;IP属地信息的准确性问题也日益凸显。那么&#xff0c;IP属地信…

nginx高可用集群搭建

本文介绍nginx高可用集群的搭建。利用keepalived实时检查nginx进程是否存活、keepalived的虚拟ip技术&#xff0c;达到故障转移的目的。终端用户通过访问虚拟ip&#xff0c;感知不到实际发生的故障。架构图如下&#xff1a; 0、环境 Ubuntu&#xff1a;22.04.2 ltsnginx: 1.…

UE5材质节点Distance

Distance可以计算两个物体间的距离&#xff0c;可以用来做过渡效果 当相机和物体距离3000的时候&#xff0c;就会渐渐从蓝过渡到红色&#xff0c;除以500是为了平滑过渡

CS·GO搬砖流程详细版

说简单点&#xff0c;就是Steam买了然后BUFF上卖&#xff0c;或许大家都知道这点&#xff0c;但就是一些操作和细节问题没那么明白。我相信&#xff0c;你看完这篇文章以后&#xff0c;至少会有新的认知。 好吧&#xff0c;废话少说&#xff0c;直接上实操&#xff01; 首先准…

【Cocos TypeScript 零基础 3.1】

目录 场景跳转 场景跳转 把新建好的TS文件与场景绑定 选中 场景 或 camera 拖进右边的 属性检查器 双击T文件,进入编辑 至于用什么IDE看个位朋友高兴 我这里有 VScode ,先用这个,老师也没有推荐 (老师也用的是这个) VScode UI 也有中文包,请自行上网搜索 打开创建的TS文件后…

分析服务器 systemctl 启动gozero项目报错的解决方案

### 分析 systemctl start beisen.service 报错 在 Linux 系统中&#xff0c;systemctl 是管理系统和服务的主要工具。当我们尝试重启某个服务时&#xff0c;如果服务启动失败&#xff0c;systemctl 会输出错误信息&#xff0c;帮助我们诊断和解决问题。 本文将通过一个实际的…

pd虚拟机 Parallels Desktop 20 for Mac 安装教程【支持M芯片】

文章目录 效果图一、下载软件二、安装运行⚠️注意事项&#xff1a;1、前往 系统设置–> 隐私与安全性 –> 完整磁盘访问权限&#xff0c;中允许终端&#xff1a;2、安装运行【ParallelsDesktop-20.1.2-55742.dmg】&#xff0c;运行【安装.app】3、将【Patch】文件夹拖到…

回归预测 | MATLAB实现CNN-GRU卷积门控循环单元多输入单输出回归预测

回归预测 | MATLAB实现CNN-GRU卷积门控循环单元多输入单输出回归预测 目录 回归预测 | MATLAB实现CNN-GRU卷积门控循环单元多输入单输出回归预测预测效果基本介绍程序设计参考资料 预测效果 基本介绍 MATLAB实现CNN-GRU卷积门控循环单元多输入单输出回归预测 数据准备&#x…

JAVA创建绘图板JAVA构建主窗口鼠标拖动来绘制线条

前些天发现了一个巨牛的人工智能学习网站&#xff0c;通俗易懂&#xff0c;风趣幽默&#xff0c; 忍不住分享一下给大家。点击跳转到网站 学习总结 1、掌握 JAVA入门到进阶知识(持续写作中……&#xff09; 2、学会Oracle数据库入门到入土用法(创作中……&#xff09; 3、手把…

CSS层叠样式表

目标 能够说出什么是CSS能够使用CSS基础选择器能够设置字体样式能够设置文本样式能够说出CSS的三种引入方式能够使用Chrome调试工具调试样式 目录 CSS简介CSS基础选择器CSS字体属性CSS文本属性CSS的引入方式综合案例Chrome调试工具 1.1 HTML的局限性 说起HTML&#xff0c;…

Win32汇编学习笔记03.RadAsm和补丁

Win32汇编学习笔记03.RadAsm和补丁-C/C基础-断点社区-专业的老牌游戏安全技术交流社区 - BpSend.net 扫雷游戏啊下补丁 在扫雷游戏中,点关闭弹出一个确认框,确认之后再关闭,取消就不关闭 首先第一步就是确认关闭按钮响应的位置,一般都是 WM_CLOSE 的消息 ,消息响应一般都在过…

深入Android架构(从线程到AIDL)_08 认识Android的主线程

目录 3、 认识Android的主线程(又称UI线程) 复习&#xff1a; 各进程(Process)里的主线程​编辑 UI线程的责任&#xff1a; 迅速处理UI事件 举例 3、 认识Android的主线程(又称UI线程) 复习&#xff1a; 各进程(Process)里的主线程 UI线程的责任&#xff1a; 迅速处理UI事…

4.CSS文本属性

4.1文本颜色 div { color:red; } 属性值预定义的颜色值red、green、blue、pink十六进制#FF0000,#FF6600,#29D794RGB代码rgb(255,0,0)或rgb(100%,0%,0%) 4.2对齐文本 text-align 属性用于设置元素内文本内容的水平对齐方式。 div{ text-align:center; } 属性值解释left左对齐ri…

数据挖掘——支持向量机分类器

数据挖掘——支持向量机分类器 支持向量机最小间隔面推导基于软间隔的C-SVM非线性SVM与核变换常用核函数 支持向量机 根据统计学习理论&#xff0c;学习机器的实际风险由经验风险值和置信范围值两部分组成。而基于经验风险最小化准则的学习方法只强调了训练样本的经验风险最小…

慧集通iPaaS集成平台低代码培训-基础篇

训练使用素材&#xff1a; 1.数据源&#xff1a; 单号业务日期工厂仓库物料单位数量批次0100012022-5-1210031001030001kg500202304150100012022-5-1210031001030001kg122202304150100012022-5-1210031001030001kg1250202304150100012022-5-1210031001030002kg130202304110100…