diff --git a/CMakeLists.txt b/CMakeLists.txt --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -20,6 +20,7 @@ include(ECMGenerateHeaders) include(ECMAddQch) include(ECMQtDeclareLoggingCategory) +include(CheckStructHasMember) option(BUILD_QCH "Build API documentation in QCH format (for e.g. Qt Assistant, Qt Creator & KDevelop)" OFF) add_feature_info(QCH ${BUILD_QCH} "API documentation in QCH format (for e.g. Qt Assistant, Qt Creator & KDevelop)") @@ -56,11 +57,18 @@ URL "http://www.exiv2.org" TYPE OPTIONAL PURPOSE "Support for image metadata") -find_package(FFmpeg 3.1) +find_package(FFmpeg 57.48 COMPONENTS AVCODEC) +find_package(FFmpeg 57.40 COMPONENTS AVFORMAT) +find_package(FFmpeg 55.27 COMPONENTS AVUTIL) set_package_properties(FFmpeg PROPERTIES DESCRIPTION "Video Tag reader" URL "http://ffmpeg.org" TYPE OPTIONAL PURPOSE "Support for video metadata") +if (FFmpeg_AVFORMAT_FOUND) + set(CMAKE_REQUIRED_INCLUDES ${AVCODEC_INCLUDE_DIRS}) + CHECK_STRUCT_HAS_MEMBER(AVStream codecpar "stdint.h;libavformat/avformat.h" HAVE_AVSTREAM_CODECPAR LANGUAGE CXX) +endif() + find_package(EPub) set_package_properties(EPub PROPERTIES DESCRIPTION "Ebook epub reader" URL "http://sourceforge.net/projects/ebook-tools" TYPE OPTIONAL diff --git a/cmake/FindFFmpeg.cmake b/cmake/FindFFmpeg.cmake --- a/cmake/FindFFmpeg.cmake +++ b/cmake/FindFFmpeg.cmake @@ -65,6 +65,7 @@ if (${_component}_LIBRARIES AND ${_component}_INCLUDE_DIRS) # message(STATUS " - ${_component} found.") set(${_component}_FOUND TRUE) + set(FFmpeg_${_component}_FOUND TRUE) else () # message(STATUS " - ${_component} not found.") endif () @@ -76,14 +77,14 @@ # Checks for the given component by invoking pkgconfig and then looking up the libraries and # include directories. # -macro(find_component _component _pkgconfig _library _header) +macro(find_component _component _pkgconfig _library _header _version) if (NOT WIN32) # use pkg-config to get the directories and then use these values # in the FIND_PATH() and FIND_LIBRARY() calls find_package(PkgConfig) if (PKG_CONFIG_FOUND) - pkg_check_modules(PC_${_component} ${_pkgconfig}) + pkg_check_modules(PC_${_component} ${_pkgconfig}>=${_version}) endif () endif (NOT WIN32) @@ -114,17 +115,16 @@ endmacro() - # Check for cached results. If there are skip the costly part. if (NOT FFMPEG_LIBRARIES) # Check for all possible component. - find_component(AVCODEC libavcodec avcodec libavcodec/avcodec.h) - find_component(AVFORMAT libavformat avformat libavformat/avformat.h) - find_component(AVDEVICE libavdevice avdevice libavdevice/avdevice.h) - find_component(AVUTIL libavutil avutil libavutil/avutil.h) - find_component(SWSCALE libswscale swscale libswscale/swscale.h) - find_component(POSTPROCESS libpostproc postproc libpostproc/postprocess.h) + find_component(AVCODEC libavcodec avcodec libavcodec/avcodec.h ${FFmpeg_FIND_VERSION}) + find_component(AVFORMAT libavformat avformat libavformat/avformat.h ${FFmpeg_FIND_VERSION}) + find_component(AVDEVICE libavdevice avdevice libavdevice/avdevice.h ${FFmpeg_FIND_VERSION}) + find_component(AVUTIL libavutil avutil libavutil/avutil.h ${FFmpeg_FIND_VERSION}) + find_component(SWSCALE libswscale swscale libswscale/swscale.h ${FFmpeg_FIND_VERSION}) + find_component(POSTPROCESS libpostproc postproc libpostproc/postprocess.h ${FFmpeg_FIND_VERSION}) # Check if the required components were found and add their stuff to the FFMPEG_* vars. foreach (_component ${FFmpeg_FIND_COMPONENTS}) @@ -165,5 +165,10 @@ list(APPEND _FFmpeg_REQUIRED_VARS ${_component}_LIBRARIES ${_component}_INCLUDE_DIRS) endforeach () + + # Give a nice error message if some of the required vars are missing. -find_package_handle_standard_args(FFmpeg DEFAULT_MSG ${_FFmpeg_REQUIRED_VARS}) +find_package_handle_standard_args(FFmpeg + REQUIRED_VARS ${_FFmpeg_REQUIRED_VARS} + HANDLE_COMPONENTS) + diff --git a/src/config-kfilemetadata.h.in b/src/config-kfilemetadata.h.in --- a/src/config-kfilemetadata.h.in +++ b/src/config-kfilemetadata.h.in @@ -2,4 +2,6 @@ #define CONFIGKFILEMETADATA_H #define LIBEXEC_INSTALL_DIR "${CMAKE_INSTALL_PREFIX}/${KF5_LIBEXEC_INSTALL_DIR}" +#cmakedefine01 HAVE_AVSTREAM_CODECPAR + #endif // CONFIGKFILEMETADATA_H diff --git a/src/extractors/CMakeLists.txt b/src/extractors/CMakeLists.txt --- a/src/extractors/CMakeLists.txt +++ b/src/extractors/CMakeLists.txt @@ -47,10 +47,12 @@ if(FFMPEG_FOUND) add_library(kfilemetadata_ffmpegextractor MODULE ffmpegextractor.cpp) - target_include_directories(kfilemetadata_ffmpegextractor SYSTEM PRIVATE ${FFMPEG_INCLUDE_DIRS}) + target_include_directories(kfilemetadata_ffmpegextractor SYSTEM PRIVATE ${AVCODEC_INCLUDE_DIRS} ${AVFORMAT_INCLUDE_DIRS} ${AVUTIL_INCLUDE_DIRS}) target_link_libraries(kfilemetadata_ffmpegextractor KF5::FileMetaData - ${FFMPEG_LIBRARIES} + ${AVCODEC_LIBRARIES} + ${AVFORMAT_LIBRARIES} + ${AVUTIL_LIBRARIES} ) set_target_properties(kfilemetadata_ffmpegextractor PROPERTIES LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin/kf5/kfilemetadata") diff --git a/src/extractors/ffmpegextractor.cpp b/src/extractors/ffmpegextractor.cpp --- a/src/extractors/ffmpegextractor.cpp +++ b/src/extractors/ffmpegextractor.cpp @@ -23,6 +23,8 @@ #include "ffmpegextractor.h" +#include "config-kfilemetadata.h" + #ifdef __cplusplus #define __STDC_CONSTANT_MACROS #ifdef _STDINT_H @@ -94,7 +96,11 @@ for (uint i = 0; i < fmt_ctx->nb_streams; i++) { const AVStream* stream = fmt_ctx->streams[i]; +#if defined HAVE_AVSTREAM_CODECPAR && HAVE_AVSTREAM_CODECPAR const AVCodecParameters* codec = stream->codecpar; +#else + const AVCodecContext* codec = stream->codec; +#endif if (codec->codec_type == AVMEDIA_TYPE_AUDIO || codec->codec_type == AVMEDIA_TYPE_VIDEO) { /*