if(CMAKE_VERSION VERSION_LESS 3.10)
message(FATAL_ERROR "CMake 3.10 is required by Findffmpeg.cmake")
endif()
set(ffmpeg_VERSION 6.1)
set(HEADS_PATH ${PROJECT_SOURCE_DIR}/external/ffmpeg/prebuild/include)
set(LIB_PATH ${PROJECT_SOURCE_DIR}/external/ffmpeg/prebuild/lib/${CMAKE_SYSTEM_PROCESSOR}/linux/lib64)
find_path(ffmpeg_INCLUDE_DIR
NAMES libavcodec/avcodec.h
HINTS ${HEADS_PATH}
)
find_library(ffmpeg_LIBRARY
NAMES
avfilter
avformat
avcodec
avutil
swresample
swscale
avdevice
HINTS ${LIB_PATH}
)
include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(ffmpeg
FOUND_VAR
ffmpeg_FOUND
REQUIRED_VARS
ffmpeg_LIBRARY
ffmpeg_INCLUDE_DIR
VERSION_VAR
ffmpeg_VERSION
)
if(ffmpeg_FOUND)
add_library(ffmpeg UNKNOWN IMPORTED)
set_target_properties(ffmpeg PROPERTIES
IMPORTED_LOCATION "${ffmpeg_LIBRARY}"
INTERFACE_COMPILE_OPTIONS "${ffmpeg_DEFINITIONS}"
INTERFACE_INCLUDE_DIRECTORIES "${ffmpeg_INCLUDE_DIR}"
)
endif()
#接口库的方式导入ffmpeg
set(FFMPEG_LIB_PATH ${PROJECT_SOURCE_DIR}/external/ffmpeg/prebuild/lib/${CMAKE_SYSTEM_PROCESSOR}/linux/lib64)
set(FFMPEG_LIBS
"\
${FFMPEG_LIB_PATH}/libavfilter.so;\
${FFMPEG_LIB_PATH}/libavformat.so;\
${FFMPEG_LIB_PATH}/libavcodec.so;\
${FFMPEG_LIB_PATH}/libavutil.so;\
${FFMPEG_LIB_PATH}/libswresample.so;\
${FFMPEG_LIB_PATH}/libswscale.so;\
${FFMPEG_LIB_PATH}/libavdevice.so\
")
#x86_64平台编译的ffmpeg依赖libx264-dev libx265-dev库
string(FIND "${CMAKE_SYSTEM_PROCESSOR}" "x86_64" NEED_X264)
if(NEED_X264 GREATER -1)
string(APPEND FFMPEG_LIBS ";${FFMPEG_LIB_PATH}/libx264.so;${FFMPEG_LIB_PATH}/libx265.so")
endif()
add_library(ffmpeg INTERFACE IMPORTED GLOBAL)
set_target_properties(ffmpeg PROPERTIES
INTERFACE_LINK_LIBRARIES
"${FFMPEG_LIBS}"
)
set_target_properties(ffmpeg PROPERTIES
INTERFACE_INCLUDE_DIRECTORIES
"${PROJECT_SOURCE_DIR}/external/ffmpeg/prebuild/include"
)