基于海思平台交叉编译opencv+ffmpeg但是ffmpeg始终为NO

opencv 版本:3.1.0

ffmpeg版本:3.1.4

操作系统:Ubuntu 14.04

ffmpeg编译

./configure --disable-shared --enable-static --cross-prefix=arm-hisiv500-linux- --arch=arm

--target-os=linux --disable-stripping --enable-cross-compile --disable-asm --enable-gpl --enable-avresample

--extra-cflags=-I<install_path>include --extra-ldflags=-L<install_path>lib --prefix=<install_path>

--enable-avresample 在编译opencv时需要,一开始在网上找的命令没有加这个,而在编译opencv时报错,如下

Scanning dependencies of target opencv_annotation
make[2]: *** No rule to make target '/home/mrsy/project/machine-learning-lib/ffmpeg_opencv/install/ffmpeg/lib/libavresample.a', needed by 'bin/opencv_annotation'.  Stop.
make[2]: *** Waiting for unfinished jobs....

make

make install

opencv编译

先修改CMake的toolchain.cmake

在opencv目录下的 platforms/linux,修改 arm-gnueabi.toolchain.cmake

set(CMAKE_SYSTEM_PROCESSOR arm) --->> set(CMAKE_SYSTEM_PROCESSOR arm-hisiv500-linux-uclibcgnueabi)

注释掉

find_program(CMAKE_C_COMPILER NAMES arm-linux-gnueabi${FLOAT_ABI_SUFFIX}-gcc-${GCC_COMPILER_VERSION})
find_program(CMAKE_CXX_COMPILER NAMES arm-linux-gnueabi${FLOAT_ABI_SUFFIX}-g++-${GCC_COMPILER_VERSION})
set(ARM_LINUX_SYSROOT /usr/arm-linux-gnueabi${FLOAT_ABI_SUFFIX} CACHE PATH "ARM cross compilation system root")

修改为自己的编译器和编译选项:

set(TOOLCHAIN_DIR "/opt/hisi-linux/x86-arm/arm-hisiv500-linux/")
set(CMAKE_C_COMPILER "/opt/hisi-linux/x86-arm/arm-hisiv500-linux/bin/arm-hisiv500-linux-uclibcgnueabi-gcc")
set(CMAKE_CXX_COMPILER "/opt/hisi-linux/x86-arm/arm-hisiv500-linux/bin/arm-hisiv500-linux-uclibcgnueabi-g++")
set(CMAKE_FIND_ROOT_PATH /opt/hisi-linux/ /opt/hisi-linux/x86-arm/arm-hisiv500-linux/)
set(ARM_LINUX_SYSROOT /opt/hisi-linux/x86-arm/arm-hisiv500-linux/ CACHE PATH "ARM cross compile system root")
MESSAGE(STATUS "This is cross compile dir --->" ${CMAKE_C_COMPILER})

set(CMAKE_CXX_FLAGS           "-fPIC -fopenmp -mcpu=cortex-a17.cortex-a7 -mfloat-abi=softfp -mfpu=neon-vfpv4 -mno-unaligned-access -fno-aggressive-loop-optimizations -ffunction-sections -fdata-sections"                    CACHE STRING "c++ flags")
set(CMAKE_C_FLAGS             "-fPIC -fopenmp -mcpu=cortex-a17.cortex-a7 -mfloat-abi=softfp -mfpu=neon-vfpv4 -mno-unaligned-access -fno-aggressive-loop-optimizations -ffunction-sections -fdata-sections"                    CACHE STRING "c flags")
set(CMAKE_SHARED_LINKER_FLAGS "-fPIC -fopenmp -mcpu=cortex-a17.cortex-a7 -mfloat-abi=softfp -mfpu=neon-vfpv4 -mno-unaligned-access -fno-aggressive-loop-optimizations -ffunction-sections -fdata-sections"                    CACHE STRING "shared linker flags")
set(CMAKE_MODULE_LINKER_FLAGS "-fPIC -fopenmp -mcpu=cortex-a17.cortex-a7 -mfloat-abi=softfp -mfpu=neon-vfpv4 -mno-unaligned-access -fno-aggressive-loop-optimizations -ffunction-sections -fdata-sections"                    CACHE STRING "module linker flags")
set(CMAKE_EXE_LINKER_FLAGS    "-fPIC -fopenmp -mcpu=cortex-a17.cortex-a7 -mfloat-abi=softfp -mfpu=neon-vfpv4 -mno-unaligned-access -fno-aggressive-loop-optimizations -ffunction-sections -fdata-sections -Wl,-z,nocopyreloc"  CACHE STRING "executable linker flags")

然后CMake:

cmake -DCMAKE_BUILD_WITH_INSTALL_RPATH=ON \
      -DCMAKE_TOOLCHAIN_FILE="/home/mrsy/project/machine-learning-lib/ffmpeg_opencv/opencv-3.1.0/platforms/linux/hisi3519.toolchain.cmake" \
      -DBUILD_SHARED_LIBS=OFF \
      -DCMAKE_BUILD_TYPE=Release \
      -D WITH_MATLAB=OFF \
      -D WITH_CUDA=OFF \
      -D BUILD_DOCS=OFF \
      -D BUILD_PERF_TESTS=OFF \
      -D BUILD_TESTS=OFF \
      -D ENABLE_NEON=ON \
      -D CUDA_USE_STATIC_CUDA_RUNTIME=OFF \
      -D HAVE_FFMPEG=ON \
      -D WITH_FFMPEG=ON \
      -D FFMPEG_INCLUDE_DIR="/home/mrsy/project/machine-learning-lib/ffmpeg_opencv/install/ffmpeg/include" \
      -D FFMPEG_LIB_DIR="/home/mrsy/project/machine-learning-lib/ffmpeg_opencv/install/ffmpeg/lib" \
      -DOPENCV_EXTRA_MODULES_PATH="../../opencv_contrib-3.1.0/modules" \
      -DCMAKE_INSTALL_PREFIX="/home/mrsy/project/machine-learning-lib/ffmpeg_opencv/install/opencv" \
      ..

如果直接这么CMake,你会发现 ffmpeg 总是在 NO 状态,如下图

这时查看 CMakeCache.txt,查找 FFMPEG,你会发现,如下图:


ffmpeg里面库的路径都是 NOTFOUND,所以你需要在 CMake时加上他们的路径,以下是我的:

      -D FFMPEG_INCLUDE_DIR="/home/mrsy/project/machine-learning-lib/ffmpeg_opencv/install/ffmpeg/include" \
      -D FFMPEG_LIB_DIR="/home/mrsy/project/machine-learning-lib/ffmpeg_opencv/install/ffmpeg/lib" \
      -D FFMPEG_CODEC_LIB="/home/mrsy/project/machine-learning-lib/ffmpeg_opencv/install/ffmpeg/lib" \
      -D FFMPEG_FORMAT_LIB="/home/mrsy/project/machine-learning-lib/ffmpeg_opencv/install/ffmpeg/lib" \
      -D FFMPEG_RESAMPLE_LIB="/home/mrsy/project/machine-learning-lib/ffmpeg_opencv/install/ffmpeg/lib" \
      -D FFMPEG_SWSCALE_LIB="/home/mrsy/project/machine-learning-lib/ffmpeg_opencv/install/ffmpeg/lib" \
      -D FFMPEG_UTIL_LIB="/home/mrsy/project/machine-learning-lib/ffmpeg_opencv/install/ffmpeg/lib" \

这样,即可以 make , make install 了

当 opencv 未链接到 ffmpeg 时,使用opencv 在海思板子上打开视频是失败的,只有链接了 ffmpeg 之后才能打开视频。

  • 1
    点赞
  • 10
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值