From 41c291f51ccd4b9579e4268f6d3cab3cbf1b659a Mon Sep 17 00:00:00 2001 From: Stephen Seo Date: Fri, 18 Feb 2022 15:24:31 +0900 Subject: [PATCH] Apply fixes based on FFmpeg 5.0 See README.md for more details --- CMakeLists.txt | 21 --------------------- README.md | 9 +++++++-- src/video.cc | 8 ++++++++ 3 files changed, 15 insertions(+), 23 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index dd75a64..6939390 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -30,27 +30,6 @@ find_package(PkgConfig REQUIRED) pkg_check_modules(FFMPEG_LIBAVCODEC REQUIRED libavcodec libavformat libavutil libswscale) -if(${FFMPEG_LIBAVCODEC_libavcodec_VERSION} VERSION_GREATER "58.134.100" - OR - ${FFMPEG_LIBAVCODEC_libavformat_VERSION} VERSION_GREATER "58.76.100" - OR - ${FFMPEG_LIBAVCODEC_libavutil_VERSION} VERSION_GREATER "56.70.100" - OR - ${FFMPEG_LIBAVCODEC_libswscale_VERSION} VERSION_GREATER "5.9.100") - message(FATAL_ERROR "FFmpeg version is newer than expected, please use FFmpeg version 4.4") -# The following may be necessary when moving to FFmpeg 5.0 -#elseif(${FFMPEG_LIBAVCODEC_libavcodec_VERSION} VERSION_LESS_EQUAL "58.91.100" -# OR -# ${FFMPEG_LIBAVCODEC_libavformat_VERSION} VERSION_LESS_EQUAL "58.45.100" -# OR -# ${FFMPEG_LIBAVCODEC_libavutil_VERSION} VERSION_LESS_EQUAL "56.51.100" -# OR -# ${FFMPEG_LIBAVCODEC_libswscale_VERSION} VERSION_LESS_EQUAL "5.7.100") -# message(FATAL_ERROR "FFmpeg version is older than expected, please use FFmpeg version 4.4") -else() - message("FFmpeg version is OK") -endif() - target_include_directories(DitheringProject PUBLIC ${OpenCL_INCLUDE_DIRS} ${PNG_INCLUDE_DIRS} diff --git a/README.md b/README.md index f455cef..4a0165c 100644 --- a/README.md +++ b/README.md @@ -2,14 +2,19 @@ ## Note about Maintenance and Versions -The project at tag `1.0.0` refers to the state of the project upon completion +~~The project at tag `1.0.0` refers to the state of the project upon completion of the course. Newer versions are meant to be maintenance releases; fixes that keep the project working. As of 2022-01-18, there may be (after now) a version `1.1.0` or `1.0.1` due to keeping up to date with the FFmpeg dependency as a new major version of FFmpeg was released (version `5.0`). To be clear, version `1.0.0` of this project is expected to work with FFmpeg -version `4.4`. +version `4.4`.~~ + +Fixes were applied for FFmpeg version 5. A macro is used to change incompatible +code based on what version of FFmpeg is specified in the headers, so external +checking of version is not necessary. Thus, the latest version of this repo +should work with both FFmpeg 5.0 and 4.4. ## Background diff --git a/src/video.cc b/src/video.cc index 200edfc..146c5c0 100644 --- a/src/video.cc +++ b/src/video.cc @@ -74,7 +74,11 @@ bool Video::DitherVideo(const std::string &output_filename, Image *blue_noise, } // Get "best" video stream +#if LIBAVFORMAT_VERSION_MAJOR >= 59 + const AVCodec *dec_codec = nullptr; +#else AVCodec *dec_codec = nullptr; +#endif return_value = av_find_best_stream( avf_dec_context, AVMediaType::AVMEDIA_TYPE_VIDEO, -1, -1, &dec_codec, 0); if (return_value < 0) { @@ -193,7 +197,11 @@ bool Video::DitherVideo(const std::string &output_filename, Image *blue_noise, // set output video codec (h264) AVCodecContext *enc_codec_context = nullptr; +#if LIBAVCODEC_VERSION_MAJOR >= 59 + const AVCodec *enc_codec = nullptr; +#else AVCodec *enc_codec = nullptr; +#endif // get H264 codec if (!output_as_pngs) {