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

news2025/1/8 18:56:38

目录

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

 

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

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

基于ASP.NET的动漫网站

一、系统架构与技术实现 系统架构&#xff1a;基于ASP.NET的MVC框架构建&#xff0c;实现网站的层次结构&#xff0c;使得网站更加易于维护和扩展。 技术实现&#xff1a;利用ASP.NET的技术特点&#xff0c;如强大的后端开发能力、丰富的UI控件等&#xff0c;结合前端技术如HT…

「Java 数据结构全面解读」:从基础到进阶的实战指南

「Java 数据结构全面解读」&#xff1a;从基础到进阶的实战指南 数据结构是程序设计中的核心部分&#xff0c;用于组织和管理数据。Java 提供了丰富的集合框架和工具类&#xff0c;涵盖了常见的数据结构如数组、链表、栈、队列和树等。本文将系统性地介绍这些数据结构的概念、…

安卓NDK视觉开发——手机拍照文档边缘检测实现方法与库封装

一、项目创建 创建NDK项目有两种方式&#xff0c;一种从新创建整个项目&#xff0c;一个在创建好的项目添加NDK接口。 1.创建NDK项目 创建 一个Native C项目&#xff1a; 选择包名、API版本与算法交互的语言&#xff1a; 选择C版本&#xff1a; 创建完之后&#xff0c;可…

MATLAB仿真:基于GS算法的经大气湍流畸变涡旋光束波前校正仿真

GS算法流程 GS&#xff08;Gerchberg-Saxton&#xff09;相位恢复算法是一种基于傅里叶变换的最速下降算法&#xff0c;可以通过输出平面和输入平面上光束的光强分布计算出光束的相位分布。图1是基于GS算法的涡旋光束畸变波前校正系统框图&#xff0c;在该框图中&#xff0c;已…

【React+TypeScript+DeepSeek】穿越时空对话机

引言 在这个数字化的时代&#xff0c;历史学习常常给人一种距离感。教科书中的历史人物似乎永远停留在文字里&#xff0c;我们无法真正理解他们的思想和智慧。如何让这些伟大的历史人物"活"起来&#xff1f;如何让历史学习变得生动有趣&#xff1f;带着这些思考&…

深入刨析数据结构之排序(上)

目录 1.内部排序 1.1概述 1.2插入排序 1.2.1其他插入排序 1.2.1.1 折半插入排序 1.2.1.2 2-路插入排序 1.3希尔排序 1.4快速排序 1.4.1起泡排序 1.4.2快速排序 1.4.2.1hoare版本 1.4.2.2挖坑版本 1.4.2.3前后指针版本 1.4.2.4优化版本 1.4.2.4.1小区间插入排序优…

AIA - APLIC之三(附APLIC处理流程图)

本文属于《 RISC-V指令集基础系列教程》之一,欢迎查看其它文章。 1 APLIC复位 APLIC复位后,其所有状态都变得有效且一致,但以下情况除外: 每个中断域的domaincfg寄存器(spec第 4.5.1 节);可能是machine-level interrupt domain的MSI地址配置寄存器(spec第4.5.3 和4.5…

openwrt 清缓存命令行

一、查看缓存 &#xff1a; free -m 二、清缓存&#xff1a;echo 3 > /proc/sys/vm/drop_caches  三、详解。 释放物理页缓存 echo 1 > /proc/sys/vm/drop_caches 释放可回收的slab对象&#xff0c;包含inode and dentry echo 2 > /proc/sys/vm/drop_caches 同时…

Linux -- 端口号、套接字、网络字节序、sockaddr 结构体

目录 什么是端口号&#xff1f; 什么是套接字&#xff1f; 网络字节序 struct sockaddr 结构体 什么是端口号&#xff1f; 我们日常上网的时候&#xff0c;主机其实是在进行两种操作&#xff1a; 1、把远端的数据拉取到本地&#xff0c;比如刷抖音的时候&#xff0c;手机向…

《数据结构》期末考试测试题【中】

《数据结构》期末考试测试题【中】 21.循环队列队空的判断条件为&#xff1f;22. 单链表的存储密度比1&#xff1f;23.单链表的那些操作的效率受链表长度的影响&#xff1f;24.顺序表中某元素的地址为&#xff1f;25.m叉树第K层的结点数为&#xff1f;26. 在双向循环链表某节点…

实际开发中,常见pdf|word|excel等文件的预览和下载

实际开发中,常见pdf|word|excel等文件的预览和下载 背景相关类型数据之间的转换1、File转Blob2、File转ArrayBuffer3、Blob转ArrayBuffer4、Blob转File5、ArrayBuffer转Blob6、ArrayBuffer转File 根据Blob/File类型生成可预览的Base64地址基于Blob类型的各种文件的下载各种类型…

《Opencv》基础操作详解(4)

接上篇&#xff1a;《Opencv》基础操作详解&#xff08;3&#xff09;-CSDN博客 目录 22、图像形态学操作 &#xff08;1&#xff09;、顶帽&#xff08;原图-开运算&#xff09; 公式&#xff1a; 应用场景&#xff1a; 代码示例&#xff1a; &#xff08;2&#xff09;…

大数据高级ACP学习笔记(2)

钻取&#xff1a;变换维度的层次&#xff0c;改变粒度的大小 星型模型 雪花模型 MaxCompute DataHub

尚硅谷· vue3+ts 知识点学习整理 |14h的课程(持续更ing)

vue3 主要内容 核心&#xff1a;ref、reactive、computed、watch、生命周期 常用&#xff1a;hooks、自定义ref、路由、pinia、miit 面试&#xff1a;组件通信、响应式相关api ----> 笔记&#xff1a;ts快速梳理&#xff1b;vue3快速上手.pdf 笔记及大纲 如下&#xff…

阻抗(Impedance)、容抗(Capacitive Reactance)、感抗(Inductive Reactance)

阻抗&#xff08;Impedance&#xff09;、容抗&#xff08;Capacitive Reactance&#xff09;、感抗&#xff08;Inductive Reactance&#xff09; 都是交流电路中描述电流和电压之间关系的参数&#xff0c;但它们的含义、单位和作用不同。下面是它们的定义和区别&#xff1a; …

在 SQL 中,区分 聚合列 和 非聚合列(nonaggregated column)

文章目录 1. 什么是聚合列&#xff1f;2. 什么是非聚合列&#xff1f;3. 在 GROUP BY 查询中的非聚合列问题示例解决方案 4. 为什么 only_full_group_by 要求非聚合列出现在 GROUP BY 中&#xff1f;5. 如何判断一个列是聚合列还是非聚合列&#xff1f;6. 总结 在 SQL 中&#…

B树与B+树:数据库索引的秘密武器

想象一下&#xff0c;你正在构建一个超级大的图书馆&#xff0c;里面摆满了各种各样的书籍。B树和B树就像是两种不同的图书分类和摆放方式&#xff0c;它们都能帮助你快速找到想要的书籍&#xff0c;但各有特点。 B树就像是一个传统的图书馆摆放方式&#xff1a; 1. 书籍摆放&…

回归预测 | MATLAB实现CNN-SVM多输入单输出回归预测

回归预测 | MATLAB实现CNN-SVM多输入单输出回归预测 目录 回归预测 | MATLAB实现CNN-SVM多输入单输出回归预测预测效果基本介绍模型架构程序设计参考资料 预测效果 基本介绍 CNN-SVM多输入单输出回归预测是一种结合卷积神经网络&#xff08;CNN&#xff09;和支持向量机&#…

Linux-Ubuntu之裸机驱动最后一弹PWM控制显示亮度

Linux-Ubuntu之裸机驱动最后一弹PWM控制显示亮度 一&#xff0c; PWM实现原理二&#xff0c;软件实现三&#xff0c;正点原子裸机开发总结 一&#xff0c; PWM实现原理 PWM和学习51时候基本上一致&#xff0c;控制频率&#xff08;周期&#xff09;和占空比&#xff0c;51实验…

自定义校验注解

已有的注解不能满足所有的校验需求,特殊的情况需要自定义校验(自定义校验注解) 1.自定义注解,并在注解上指定校验逻辑 Constraint(validatedBy StateValidation.class) // 指定校验逻辑 package com.example.demo.validation;import jakarta.validation.Constraint; import j…