目录
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