Commit bb872bbf for libheif

commit bb872bbf062651d159fd3ab55031e9b55b0d0042
Author: Dirk Farin <dirk.farin@gmail.com>
Date:   Thu Jun 25 17:02:08 2026 +0200

    cmake: include ffmpeg decoded formats into list (#1846)

diff --git a/CMakeLists.txt b/CMakeLists.txt
index a690a77e..2d90d5a8 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -282,6 +282,26 @@ endif()
 plugin_option(FFMPEG_DECODER "FFMPEG HEVC decoder (HW accelerated)" OFF OFF)
 if (WITH_FFMPEG_DECODER)
     find_package(FFMPEG COMPONENTS avcodec avutil)
+
+    if (FFMPEG_avcodec_FOUND)
+        # The set of formats the FFmpeg decoder plugin can handle depends on the
+        # FFmpeg version. HT-J2K (High-Throughput JPEG 2000) decoding was added in
+        # FFmpeg 7.0 (libavcodec 61) and a native VVC decoder in FFmpeg 7.1
+        # (libavcodec 61.19); earlier versions only provide the formats listed below.
+        message(STATUS "FFmpeg decoder (libavcodec ${FFMPEG_avcodec_VERSION}) can decode: HEVC, AVC, AV1, JPEG, JPEG 2000")
+        if (FFMPEG_avcodec_VERSION VERSION_GREATER_EQUAL "61.19")
+            message(STATUS "  FFmpeg also supports VVC and HT-J2K (High-Throughput JPEG 2000) decoding")
+        elseif (FFMPEG_avcodec_VERSION VERSION_GREATER_EQUAL "61")
+            message(STATUS "  FFmpeg also supports HT-J2K (High-Throughput JPEG 2000) decoding")
+            # VVC is detected at runtime (avcodec_find_decoder), not at compile time, and
+            # 7.1 is ABI-compatible with this 7.0 build, so VVC works once the FFmpeg
+            # loaded at runtime is 7.1+ -- no rebuild required.
+            message(STATUS "  VVC decoding additionally needs the FFmpeg at runtime to be 7.1 (libavcodec 61.19) or later")
+        else ()
+            message(STATUS "  HT-J2K decoding needs FFmpeg 7.0 (libavcodec 61) or later")
+            message(STATUS "  VVC decoding needs FFmpeg 7.1 (libavcodec 61.19) or later")
+        endif ()
+    endif ()
 endif ()

 # openjph
@@ -402,6 +422,24 @@ if (WITH_UNCOMPRESSED_CODEC)
     set(SUPPORTS_UNCOMPRESSED_ENCODING TRUE)
 endif()

+# The FFmpeg decoder plugin can decode several formats (in addition to the HEIC
+# decoding accounted for above). HEVC/AVC/AV1/JPEG/JPEG2000 work with any supported
+# FFmpeg; HT-J2K needs FFmpeg 7.0 (libavcodec 61) and the native VVC decoder
+# FFmpeg 7.1 (libavcodec 61.19). FFmpeg's SONAME is per-major, so the build-time
+# major version is also the runtime major version.
+if (FFMPEG_avcodec_FOUND)
+    set(SUPPORTS_AVC_DECODING TRUE)
+    set(SUPPORTS_AVIF_DECODING TRUE)
+    set(SUPPORTS_JPEG_DECODING TRUE)
+    set(SUPPORTS_J2K_DECODING TRUE)
+    if (FFMPEG_avcodec_VERSION VERSION_GREATER_EQUAL "61")
+        set(SUPPORTS_J2K_HT_DECODING TRUE)
+    endif()
+    if (FFMPEG_avcodec_VERSION VERSION_GREATER_EQUAL "61.19")
+        set(SUPPORTS_VVC_DECODING TRUE)
+    endif()
+endif()
+
 message("\n=== Supported formats ===")
 message("format        decoding   encoding")
 format_compilation_info("AVC"  SUPPORTS_AVC_DECODING SUPPORTS_AVC_ENCODING)
diff --git a/cmake/modules/FindFFMPEG.cmake b/cmake/modules/FindFFMPEG.cmake
index f777aa70..cb3b16fd 100644
--- a/cmake/modules/FindFFMPEG.cmake
+++ b/cmake/modules/FindFFMPEG.cmake
@@ -103,9 +103,17 @@ function (_ffmpeg_find component headername)
         string(TOUPPER "${component}" component_upper)
         file(STRINGS "${version_header_path}" version
           REGEX "#define  *LIB${component_upper}_VERSION_(MAJOR|MINOR|MICRO) ")
-        string(REGEX REPLACE ".*_MAJOR *\([0-9]*\).*" "\\1" major "${version}")
-        string(REGEX REPLACE ".*_MINOR *\([0-9]*\).*" "\\1" minor "${version}")
-        string(REGEX REPLACE ".*_MICRO *\([0-9]*\).*" "\\1" micro "${version}")
+        # Recent FFmpeg moved LIB<component>_VERSION_MAJOR into a separate
+        # version_major.h, so it may not be present in version.h above.
+        set(version_major_header_path "${FFMPEG_${component}_INCLUDE_DIR}/lib${component}/version_major.h")
+        if (EXISTS "${version_major_header_path}")
+          file(STRINGS "${version_major_header_path}" version_major
+            REGEX "#define  *LIB${component_upper}_VERSION_MAJOR ")
+          list(PREPEND version "${version_major}")
+        endif ()
+        string(REGEX REPLACE ".*_MAJOR *([0-9]+).*" "\\1" major "${version}")
+        string(REGEX REPLACE ".*_MINOR *([0-9]+).*" "\\1" minor "${version}")
+        string(REGEX REPLACE ".*_MICRO *([0-9]+).*" "\\1" micro "${version}")
         if (NOT major STREQUAL "" AND
             NOT minor STREQUAL "" AND
             NOT micro STREQUAL "")
@@ -155,7 +163,7 @@ if (TARGET FFMPEG::avutil)
   if (EXISTS "${_ffmpeg_version_header_path}")
     file(STRINGS "${_ffmpeg_version_header_path}" _ffmpeg_version
       REGEX "FFMPEG_VERSION")
-    string(REGEX REPLACE ".*\"n?\(.*\)\"" "\\1" FFMPEG_VERSION "${_ffmpeg_version}")
+    string(REGEX REPLACE ".*\"n?(.*)\"" "\\1" FFMPEG_VERSION "${_ffmpeg_version}")
     unset(_ffmpeg_version)
   else ()
     set(FFMPEG_VERSION FFMPEG_VERSION-NOTFOUND)