【Atlas500】入门(十六)——ffmpeg 264编码 [h264_v4l2m2m @ 0xaaaac8aa5220] Could not find a valid device

参考:https://blog.csdn.net/weixin_45617478/article/details/103449522

好像是没有x264这个包

1. 说明

项目:FaceRecognition
项目原始采用的是mpeg编码器(好像ffmpeg自带的),用rtsp进行推流。这里要推流成rtmp。要求用h264的编码。

2. x264,ffmpeg编译

请参考:readme

3. 可能问题

  • 1 libx264.so.161 not found
/home/yangna/Atlas500_DDK/toolchains/Euler_compile_env_cross/arm/cross_compile/install/bin/../lib64/gcc/aarch64-linux-gnu/7.3.0/../../../../aarch64-linux-gnu/bin/ld: warning: libx264.so.161, needed by /home/yangna/chenjun/Atlas_dependence/ffmpeg_install/lib/libavcodec.so, not found (try using -rpath or -rpath-link)
/home/yangna/Atlas500_DDK/toolchains/Euler_compile_env_cross/arm/cross_compile/install/bin/../lib64/gcc/aarch64-linux-gnu/7.3.0/../../../../aarch64-linux-gnu/bin/ld: warning: libpostproc.so.55, needed by /home/yangna/chenjun/Atlas_dependence/ffmpeg_install/lib/libavfilter.so, not found (try using -rpath or -rpath-link)
/home/yangna/Atlas500_DDK/toolchains/Euler_compile_env_cross/arm/cross_compile/install/bin/../lib64/gcc/aarch64-linux-gnu/7.3.0/../../../../aarch64-linux-gnu/bin/ld: /home/yangna/chenjun/Atlas_dependence/ffmpeg_install/lib/libavcodec.so: undefined reference to `x264_param_default'
/home/yangna/Atlas500_DDK/toolchains/Euler_compile_env_cross/arm/cross_compile/install/bin/../lib64/gcc/aarch64-linux-gnu/7.3.0/../../../../aarch64-linux-gnu/bin/ld: /home/yangna/chenjun/Atlas_dependence/ffmpeg_install/lib/libavfilter.so: undefined reference to `pp_get_mode_by_name_and_quality@LIBPOSTPROC_55'
/home/yangna/Atlas500_DDK/toolchains/Euler_compile_env_cross/arm/cross_compile/install/bin/../lib64/gcc/aarch64-linux-gnu/7.3.0/../../../../aarch64-linux-gnu/bin/ld: /home/yangna/chenjun/Atlas_dependence/ffmpeg_install/lib/libavcodec.so: undefined reference to `x264_param_apply_profile'
/home/yangna/Atlas500_DDK/toolchains/Euler_compile_env_cross/arm/cross_compile/install/bin/../lib64/gcc/aarch64-linux-gnu/7.3.0/../../../../aarch64-linux-gnu/bin/ld: /home/yangna/chenjun/Atlas_dependence/ffmpeg_install/lib/libavcodec.so: undefined reference to `x264_encoder_headers'
/home/yangna/Atlas500_DDK/toolchains/Euler_compile_env_cross/arm/cross_compile/install/bin/../lib64/gcc/aarch64-linux-gnu/7.3.0/../../../../aarch64-linux-gnu/bin/ld: /home/yangna/chenjun/Atlas_dependence/ffmpeg_install/lib/libavcodec.so: undefined reference to `x264_encoder_maximum_delayed_frames'
/home/yangna/Atlas500_DDK/toolchains/Euler_compile_env_cross/arm/cross_compile/install/bin/../lib64/gcc/aarch64-linux-gnu/7.3.0/../../../../aarch64-linux-gnu/bin/ld: /home/yangna/chenjun/Atlas_dependence/ffmpeg_install/lib/libavfilter.so: undefined reference to `pp_free_context@LIBPOSTPROC_55'
/home/yangna/Atlas500_DDK/toolchains/Euler_compile_env_cross/arm/cross_compile/install/bin/../lib64/gcc/aarch64-linux-gnu/7.3.0/../../../../aarch64-linux-gnu/bin/ld: /home/yangna/chenjun/Atlas_dependence/ffmpeg_install/lib/libavcodec.so: undefined reference to `x264_encoder_encode'
/home/yangna/Atlas500_DDK/toolchains/Euler_compile_env_cross/arm/cross_compile/install/bin/../lib64/gcc/aarch64-linux-gnu/7.3.0/../../../../aarch64-linux-gnu/bin/ld: /home/yangna/chenjun/Atlas_dependence/ffmpeg_install/lib/libavcodec.so: undefined reference to `x264_encoder_reconfig'
/home/yangna/Atlas500_DDK/toolchains/Euler_compile_env_cross/arm/cross_compile/install/bin/../lib64/gcc/aarch64-linux-gnu/7.3.0/../../../../aarch64-linux-gnu/bin/ld: /home/yangna/chenjun/Atlas_dependence/ffmpeg_install/lib/libavcodec.so: undefined reference to `x264_param_apply_fastfirstpass'
/home/yangna/Atlas500_DDK/toolchains/Euler_compile_env_cross/arm/cross_compile/install/bin/../lib64/gcc/aarch64-linux-gnu/7.3.0/../../../../aarch64-linux-gnu/bin/ld: /home/yangna/chenjun/Atlas_dependence/ffmpeg_install/lib/libavfilter.so: undefined reference to `pp_get_context@LIBPOSTPROC_55'
/home/yangna/Atlas500_DDK/toolchains/Euler_compile_env_cross/arm/cross_compile/install/bin/../lib64/gcc/aarch64-linux-gnu/7.3.0/../../../../aarch64-linux-gnu/bin/ld: /home/yangna/chenjun/Atlas_dependence/ffmpeg_install/lib/libavcodec.so: undefined reference to `x264_encoder_open_161'
/home/yangna/Atlas500_DDK/toolchains/Euler_compile_env_cross/arm/cross_compile/install/bin/../lib64/gcc/aarch64-linux-gnu/7.3.0/../../../../aarch64-linux-gnu/bin/ld: /home/yangna/chenjun/Atlas_dependence/ffmpeg_install/lib/libavfilter.so: undefined reference to `pp_free_mode@LIBPOSTPROC_55'
/home/yangna/Atlas500_DDK/toolchains/Euler_compile_env_cross/arm/cross_compile/install/bin/../lib64/gcc/aarch64-linux-gnu/7.3.0/../../../../aarch64-linux-gnu/bin/ld: /home/yangna/chenjun/Atlas_dependence/ffmpeg_install/lib/libavcodec.so: undefined reference to `x264_encoder_delayed_frames'
/home/yangna/Atlas500_DDK/toolchains/Euler_compile_env_cross/arm/cross_compile/install/bin/../lib64/gcc/aarch64-linux-gnu/7.3.0/../../../../aarch64-linux-gnu/bin/ld: /home/yangna/chenjun/Atlas_dependence/ffmpeg_install/lib/libavcodec.so: undefined reference to `x264_param_parse'
/home/yangna/Atlas500_DDK/toolchains/Euler_compile_env_cross/arm/cross_compile/install/bin/../lib64/gcc/aarch64-linux-gnu/7.3.0/../../../../aarch64-linux-gnu/bin/ld: /home/yangna/chenjun/Atlas_dependence/ffmpeg_install/lib/libavfilter.so: undefined reference to `pp_postprocess@LIBPOSTPROC_55'
/home/yangna/Atlas500_DDK/toolchains/Euler_compile_env_cross/arm/cross_compile/install/bin/../lib64/gcc/aarch64-linux-gnu/7.3.0/../../../../aarch64-linux-gnu/bin/ld: /home/yangna/chenjun/Atlas_dependence/ffmpeg_install/lib/libavcodec.so: undefined reference to `x264_levels'
/home/yangna/Atlas500_DDK/toolchains/Euler_compile_env_cross/arm/cross_compile/install/bin/../lib64/gcc/aarch64-linux-gnu/7.3.0/../../../../aarch64-linux-gnu/bin/ld: /home/yangna/chenjun/Atlas_dependence/ffmpeg_install/lib/libavcodec.so: undefined reference to `x264_picture_init'
/home/yangna/Atlas500_DDK/toolchains/Euler_compile_env_cross/arm/cross_compile/install/bin/../lib64/gcc/aarch64-linux-gnu/7.3.0/../../../../aarch64-linux-gnu/bin/ld: /home/yangna/chenjun/Atlas_dependence/ffmpeg_install/lib/libavcodec.so: undefined reference to `x264_encoder_close'
/home/yangna/Atlas500_DDK/toolchains/Euler_compile_env_cross/arm/cross_compile/install/bin/../lib64/gcc/aarch64-linux-gnu/7.3.0/../../../../aarch64-linux-gnu/bin/ld: /home/yangna/chenjun/Atlas_dependence/ffmpeg_install/lib/libavcodec.so: undefined reference to `x264_param_default_preset'

原因:

  • 分析和尝试了很久。这其实就是cmakeLists.txt中没有将动态库链接进行。有时间的话,可以参考我:【Atlas500】入门(十三)——opencv交叉编译与使用
  • 其实就是用 link_directories 链接到动态库的路径
  • target_link_libraries 中添加 postproc, x264的库名

解决方案
修改cmakelists.txt,如下:

cmake_minimum_required(VERSION 2.8)
add_compile_options(-std=c++11 -fPIE -fstack-protector-all)
project(FaceRecognition)

# ddk
find_package(DDK REQUIRED)
include_directories(${DDK_INCLUDE_DIRS} ${DDK_CEREAL_INCLUDE_DIRS} ${DDK_PROTOBUF_INCLUDE_DIRS} ${DDK_GFLAGS_INCLUDE_DIRS} ${DDK_OPENCV_INCLUDE_DIRS})

if(NOT DEFINED FFMPEG_PATH)
    message(FATAL_ERROR "please use -DFFMPEG_PATH=<>")
endif()
set(FFMPEG_DIR ${FFMPEG_PATH} CACHE INTERNAL "FFMPEG location")
link_directories(${FFMPEG_DIR}/lib)

# common
include_directories(. ./inc/ ../common ${FFMPEG_DIR}/include)

if(DEFINED X264_DIR)
    link_directories(${X264_DIR}/lib)

    message("FFMPEG USE X264 FOR ENCODE")
    message(STATUS "x264 lib path: ${X264_DIR}/lib")
    message(STATUS "ffmpeg lib path: ${FFMPEG_DIR}/lib")

    # build for host
    file(GLOB SRC cpp/*.cpp)
    add_executable(facedemo_main ${SRC})
    target_link_libraries(facedemo_main ${DDK_HOST_LIBRARIES} ${DDK_THIRD_LIBRARYS} pthread avcodec avdevice avfilter avformat avutil swscale swresample postproc x264 -Wl,-z,relro,-z,now,-z,noexecstack -pie)

else()
    message("FFMPEG ENCODE SELF")
    message(STATUS "the original use rtsp and mpeg")
    message(STATUS "ffmpeg lib path: ${FFMPEG_DIR}/lib")
    # build for host
    file(GLOB SRC cpp/*.cpp)
    add_executable(facedemo_main ${SRC})
    target_link_libraries(facedemo_main ${DDK_HOST_LIBRARIES} ${DDK_THIRD_LIBRARYS} pthread avcodec avdevice avfilter avformat avutil swscale swresample -Wl,-z,relro,-z,now,-z,noexecstack -pie)

endif()


reference

  1. http://blog.chinaunix.net/uid-23069658-id-4028681.html

你可能感兴趣的:(嵌入式AI)