How to build opencv support VVC decoder

I want to compile an OpenCV that supports decoding VVC videos. I have tried multiple times but have not been successful. The specific steps are as follows:
1.
Dowload opencv-4.10.0.zip and ffmpeg-master-latest-win64-gpl-shared.zip

Create a build directory C:/opencv/build and a cmake dirctory C:/fmpeg-master-latest-win64-gpl-shared/cmake
3.
Save the cmake script (ffmpeg-config.cmake ) mentioned in C:/fmpeg-master-latest-win64-gpl-shared/cmake
4.
use cmake-gui_3.3.1.0,set where is the source code: C:/opencv and where to build the binaries: C:/opencv/build,then click Configure 。after a while, use Add Entry add FFMPEG_DIR and OPENCV_FFMPEG_USE_FIND_PACKAGE ,which as follows:

List item click Configure again ,after a while,Cmake output show as follows:

Thank you for any help you have provided

I cannot manage to get the output you describe. I always use the command line but I have tried your approach above and the command line below without any issues

"C:\Program Files\CMake\bin\cmake.exe" -BC:/opencv/build -Hc:/opencv -G"Visual Studio 17 2022" -DOPENCV_FFMPEG_USE_FIND_PACKAGE=ON -DFFMPEG_DIR=C:/fmpeg-master-latest-win64-gpl-shared/cmake

Note: The only difference in the GUI is that I add the FFMPEG_DIR and OPENCV_FFMPEG_USE_FIND_PACKAGE variables before hitting Configure the first time.

The output for FFMpeg config is then:

– Video I/O:
– FFMPEG: YES (find_package)
– avcodec: YES (59.18.100)
– avformat: YES (59.16.100)
– avutil: YES (57.17.100)
– swscale: YES (6.4.100)
– avresample: NO
– GStreamer: NO
– DirectShow: YES
– Media Foundation: YES
– DXVA: YES

Do you receive any warnings etc. in the window at the bottom before the configuration output?


c:\ffmpeg-master-latest-win64-gpl-shared\bin>dir c:\opencv\build
 驱动器 C 中的卷没有标签。
 卷的序列号是 5816-2641

 c:\opencv\build 的目录

2024/12/03  22:41    <DIR>          .
2024/12/03  13:01    <DIR>          ..
               0 个文件              0 字节
               2 个目录 31,592,620,032 可用字节

c:\ffmpeg-master-latest-win64-gpl-shared\bin>dir c:\ffmpeg-master-latest-win64-gpl-shared\cmake
 驱动器 C 中的卷没有标签。
 卷的序列号是 5816-2641

 c:\ffmpeg-master-latest-win64-gpl-shared\cmake 的目录

2024/12/03  21:13    <DIR>          .
2024/12/03  21:13    <DIR>          ..
2024/12/03  21:39             6,855 ffmpeg-config.cmake
               1 个文件          6,855 字节
               2 个目录 31,592,554,496 可用字节

c:\ffmpeg-master-latest-win64-gpl-shared\bin>ffmpeg -codecs|findstr vvc
ffmpeg version N-117968-g1e3dc705df-20241201 Copyright (c) 2000-2024 the FFmpeg developers
  built with gcc 14.2.0 (crosstool-NG 1.26.0.120_4d36f27)
  configuration: --prefix=/ffbuild/prefix --pkg-config-flags=--static --pkg-config=pkg-config --cross-prefix=x86_64-w64-mingw32- --arch=x86_64 --target-os=mingw32 --enable-gpl --enable-version3 --disable-debug --enable-shared --disable-static --disable-w32threads --enable-pthreads --enable-iconv --enable-zlib --enable-libfreetype --enable-libfribidi --enable-gmp --enable-libxml2 --enable-lzma --enable-fontconfig --enable-libharfbuzz --enable-libvorbis --enable-opencl --disable-libpulse --enable-libvmaf --disable-libxcb --disable-xlib --enable-amf --enable-libaom --enable-libaribb24 --enable-avisynth --enable-chromaprint --enable-libdav1d --enable-libdavs2 --enable-libdvdread --enable-libdvdnav --disable-libfdk-aac --enable-ffnvcodec --enable-cuda-llvm --enable-frei0r --enable-libgme --enable-libkvazaar --enable-libaribcaption --enable-libass --enable-libbluray --enable-libjxl --enable-libmp3lame --enable-libopus --enable-librist --enable-libssh --enable-libtheora --enable-libvpx --enable-libwebp --enable-libzmq --enable-lv2 --enable-libvpl --enable-openal --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenh264 --enable-libopenjpeg --enable-libopenmpt --enable-librav1e --enable-librubberband --enable-schannel --enable-sdl2 --enable-libsoxr --enable-libsrt --enable-libsvtav1 --enable-libtwolame --enable-libuavs3d --disable-libdrm --enable-vaapi --enable-libvidstab --enable-vulkan --enable-libshaderc --enable-libplacebo --enable-libvvenc --enable-libx264 --enable-libx265 --enable-libxavs2 --enable-libxvid --enable-libzimg --enable-libzvbi --extra-cflags=-DLIBTWOLAME_STATIC --extra-cxxflags= --extra-libs=-lgomp --extra-ldflags=-pthread --extra-ldexeflags= --cc=x86_64-w64-mingw32-gcc --cxx=x86_64-w64-mingw32-g++ --ar=x86_64-w64-mingw32-gcc-ar --ranlib=x86_64-w64-mingw32-gcc-ranlib --nm=x86_64-w64-mingw32-gcc-nm --extra-version=20241201
  libavutil      59. 47.101 / 59. 47.101
  libavcodec     61. 26.100 / 61. 26.100
  libavformat    61.  9.100 / 61.  9.100
  libavdevice    61.  4.100 / 61.  4.100
  libavfilter    10.  6.101 / 10.  6.101
  libswscale      8. 12.100 /  8. 12.100
  libswresample   5.  4.100 /  5.  4.100
  libpostproc    58.  4.100 / 58.  4.100
 DEV.L. vvc                  H.266 / VVC (Versatile Video Coding) (decoders: vvc vvc_qsv) (encoders: libvvenc)

c:\ffmpeg-master-latest-win64-gpl-shared\bin>cmake -BC:/opencv/build -Hc:/opencv -G"Visual Studio 17 2022" -DOPENCV_FFMPEG_USE_FIND_PACKAGE=ON -DFFMPEG_DIR=C:/fmpeg-master-latest-win64-gpl-shared/cmake
-- 'Release' build type is used by default. Use CMAKE_BUILD_TYPE to specify build type (Release or Debug)
-- Selecting Windows SDK version 10.0.22621.0 to target Windows 10.0.22631.
-- The CXX compiler identification is MSVC 19.37.32825.0
-- The C compiler identification is MSVC 19.37.32825.0
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: C:/Program Files/Microsoft Visual Studio/2022/Community/VC/Tools/MSVC/14.37.32822/bin/Hostx64/x64/cl.exe - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: C:/Program Files/Microsoft Visual Studio/2022/Community/VC/Tools/MSVC/14.37.32822/bin/Hostx64/x64/cl.exe - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- ocv_init_download: OpenCV source tree is not fetched as git repository. 3rdparty resources will be downloaded from github.com by default.
-- Detected processor: AMD64
-- Found PythonInterp: C:/Users/EEO/AppData/Local/Programs/Python/Python37/python.exe (found suitable version "3.7.2", minimum required is "3.2")
-- Found PythonLibs: C:/Users/EEO/AppData/Local/Programs/Python/Python37/libs/python37.lib (found suitable exact version "3.7.2")
-- Performing Test HAVE_CXX_FP:PRECISE
-- Performing Test HAVE_CXX_FP:PRECISE - Success
-- Performing Test HAVE_C_FP:PRECISE
-- Performing Test HAVE_C_FP:PRECISE - Success
-- Performing Test HAVE_CPU_SSE3_SUPPORT (check file: cmake/checks/cpu_sse3.cpp)
-- Performing Test HAVE_CPU_SSE3_SUPPORT - Success
-- Performing Test HAVE_CPU_SSSE3_SUPPORT (check file: cmake/checks/cpu_ssse3.cpp)
-- Performing Test HAVE_CPU_SSSE3_SUPPORT - Success
-- Performing Test HAVE_CPU_SSE4_1_SUPPORT (check file: cmake/checks/cpu_sse41.cpp)
-- Performing Test HAVE_CPU_SSE4_1_SUPPORT - Success
-- Performing Test HAVE_CPU_POPCNT_SUPPORT (check file: cmake/checks/cpu_popcnt.cpp)
-- Performing Test HAVE_CPU_POPCNT_SUPPORT - Success
-- Performing Test HAVE_CPU_SSE4_2_SUPPORT (check file: cmake/checks/cpu_sse42.cpp)
-- Performing Test HAVE_CPU_SSE4_2_SUPPORT - Success
-- Performing Test HAVE_CXX_ARCH:AVX (check file: cmake/checks/cpu_fp16.cpp)
-- Performing Test HAVE_CXX_ARCH:AVX - Success
-- Performing Test HAVE_CXX_ARCH:AVX2 (check file: cmake/checks/cpu_avx2.cpp)
-- Performing Test HAVE_CXX_ARCH:AVX2 - Success
-- Performing Test HAVE_CXX_ARCH:AVX512 (check file: cmake/checks/cpu_avx512.cpp)
-- Performing Test HAVE_CXX_ARCH:AVX512 - Success
-- Performing Test HAVE_CPU_BASELINE_FLAGS
-- Performing Test HAVE_CPU_BASELINE_FLAGS - Success
-- Performing Test HAVE_CPU_DISPATCH_FLAGS_SSE4_1
-- Performing Test HAVE_CPU_DISPATCH_FLAGS_SSE4_1 - Success
-- Performing Test HAVE_CPU_DISPATCH_FLAGS_SSE4_2
-- Performing Test HAVE_CPU_DISPATCH_FLAGS_SSE4_2 - Success
-- Performing Test HAVE_CPU_DISPATCH_FLAGS_FP16
-- Performing Test HAVE_CPU_DISPATCH_FLAGS_FP16 - Success
-- Performing Test HAVE_CPU_DISPATCH_FLAGS_AVX
-- Performing Test HAVE_CPU_DISPATCH_FLAGS_AVX - Success
-- Performing Test HAVE_CPU_DISPATCH_FLAGS_AVX2
-- Performing Test HAVE_CPU_DISPATCH_FLAGS_AVX2 - Success
-- Performing Test HAVE_CPU_DISPATCH_FLAGS_AVX512_SKX
-- Performing Test HAVE_CPU_DISPATCH_FLAGS_AVX512_SKX - Success
-- Performing Test HAVE_CXX_W15240
-- Performing Test HAVE_CXX_W15240 - Success
-- Performing Test HAVE_C_W15240
-- Performing Test HAVE_C_W15240 - Success
-- Looking for malloc.h
-- Looking for malloc.h - found
-- Looking for _aligned_malloc
-- Looking for _aligned_malloc - found
-- Looking for fseeko
-- Looking for fseeko - not found
-- Looking for sys/types.h
-- Looking for sys/types.h - found
-- Looking for stdint.h
-- Looking for stdint.h - found
-- Looking for stddef.h
-- Looking for stddef.h - found
-- Check size of off64_t
-- Check size of off64_t - failed
-- libjpeg-turbo: VERSION = 3.0.3, BUILD = opencv-4.10.0-libjpeg-turbo
-- Check size of size_t
-- Check size of size_t - done
-- Check size of unsigned long
-- Check size of unsigned long - done
-- Looking for include file intrin.h
-- Looking for include file intrin.h - found
-- Looking for a ASM_NASM compiler
-- Looking for a ASM_NASM compiler - NOTFOUND
-- SIMD extensions disabled: could not find NASM compiler.  Performance will suffer.
-- Looking for assert.h
-- Looking for assert.h - found
-- Looking for fcntl.h
-- Looking for fcntl.h - found
-- Looking for inttypes.h
-- Looking for inttypes.h - found
-- Looking for io.h
-- Looking for io.h - found
-- Looking for limits.h
-- Looking for limits.h - found
-- Looking for memory.h
-- Looking for memory.h - found
-- Looking for search.h
-- Looking for search.h - found
-- Looking for string.h
-- Looking for string.h - found
-- Performing Test C_HAS_inline
-- Performing Test C_HAS_inline - Success
-- Check size of signed short
-- Check size of signed short - done
-- Check size of unsigned short
-- Check size of unsigned short - done
-- Check size of signed int
-- Check size of signed int - done
-- Check size of unsigned int
-- Check size of unsigned int - done
-- Check size of signed long
-- Check size of signed long - done
-- Check size of unsigned long
-- Check size of unsigned long - done
-- Check size of signed long long
-- Check size of signed long long - done
-- Check size of unsigned long long
-- Check size of unsigned long long - done
-- Check size of unsigned char *
-- Check size of unsigned char * - done
-- Check size of size_t
-- Check size of size_t - done
-- Check size of ptrdiff_t
-- Check size of ptrdiff_t - done
-- Looking for memmove
-- Looking for memmove - not found
-- Looking for setmode
-- Looking for setmode - found
-- Looking for strcasecmp
-- Looking for strcasecmp - not found
-- Looking for strchr
-- Looking for strchr - found
-- Looking for strrchr
-- Looking for strrchr - found
-- Looking for strstr
-- Looking for strstr - found
-- Looking for strtol
-- Looking for strtol - found
-- Looking for strtol
-- Looking for strtol - found
-- Looking for strtoull
-- Looking for strtoull - found
-- Looking for lfind
-- Looking for lfind - found
-- Could NOT find OpenJPEG (minimal suitable version: 2.0, recommended version >= 2.3.1). OpenJPEG will be built from sources
-- OpenJPEG: VERSION = 2.5.0, BUILD = opencv-4.10.0-openjp2-2.5.0
-- Looking for stdlib.h
-- Looking for stdlib.h - found
-- Looking for stdio.h
-- Looking for stdio.h - found
-- Looking for math.h
-- Looking for math.h - found
-- Looking for float.h
-- Looking for float.h - found
-- Looking for time.h
-- Looking for time.h - found
-- Looking for stdarg.h
-- Looking for stdarg.h - found
-- Looking for ctype.h
-- Looking for ctype.h - found
-- Looking for stdint.h
-- Looking for stdint.h - found
-- Looking for inttypes.h
-- Looking for inttypes.h - found
-- Looking for strings.h
-- Looking for strings.h - not found
-- Looking for sys/stat.h
-- Looking for sys/stat.h - found
-- Looking for unistd.h
-- Looking for unistd.h - not found
-- Looking for include file malloc.h
-- Looking for include file malloc.h - found
-- Looking for _aligned_malloc
-- Looking for _aligned_malloc - found
-- Looking for posix_memalign
-- Looking for posix_memalign - not found
-- Looking for memalign
-- Looking for memalign - not found
-- OpenJPEG libraries will be built from sources: libopenjp2 (version "2.5.0")
-- IPPICV: Downloading ippicv_2021.11.0_win_intel64_20240201_general.zip from https://raw.githubusercontent.com/opencv/opencv_3rdparty/fd27188235d85e552de31425e7ea0f53ba73ba53/ippicv/ippicv_2021.11.0_win_intel64_20240201_general.zip
-- found Intel IPP (ICV version): 2021.11.0 [2021.11.0]
-- at: C:/opencv/build/3rdparty/ippicv/ippicv_win/icv
-- found Intel IPP Integration Wrappers sources: 2021.11.0
-- at: C:/opencv/build/3rdparty/ippicv/ippicv_win/iw
-- Could not find OpenBLAS include. Turning OpenBLAS_FOUND off
-- Could not find OpenBLAS lib. Turning OpenBLAS_FOUND off
-- Looking for sgemm_
-- Looking for sgemm_ - not found
-- Found Threads: TRUE
-- Could NOT find BLAS (missing: BLAS_LIBRARIES)
-- Could NOT find LAPACK (missing: LAPACK_LIBRARIES)
    Reason given by package: LAPACK could not be found because dependency BLAS could not be found.

-- Found Java: C:/Program Files/Java/jdk-22/bin/java.exe (found version "22.0.1")
-- Found JNI: C:/Program Files/Java/jdk-22/include  found components: AWT JVM
-- VTK is not found. Please set -DVTK_DIR in CMake to VTK build directory, or to VTK install subdirectory with VTKConfig.cmake file
-- ADE: Downloading v0.1.2d.zip from https://github.com/opencv/ade/archive/v0.1.2d.zip
-- Found FFMPEG: C:/ffmpeg-master-latest-win64-gpl-shared/include (found version "N-117968-g1e3dc705df-20241201") found components: avutil swresample swscale avcodec avformat avfilter avdevice
-- FFMPEG is disabled. Can't find suitable libavcodec library (minimal 54.35.0, found #define LIBAVCODEC_VERSION_MINOR  26;#define LIBAVCODEC_VERSION_MICRO 100.26.100).
-- FFMPEG is disabled. Can't find suitable libavformat library (minimal 54.20.4, found #define LIBAVFORMAT_VERSION_MINOR   9;#define LIBAVFORMAT_VERSION_MICRO 100.9.100).
-- FFMPEG is disabled. Can't find suitable libswscale library (minimal 2.1.1, found #define LIBSWSCALE_VERSION_MINOR  12;#define LIBSWSCALE_VERSION_MICRO 100.12.100).
-- FFMPEG libraries version check failed (minimal libav release 9.20, minimal FFMPEG release 1.1.16).
-- Looking for mfapi.h
-- Looking for mfapi.h - found
-- Looking for vidcap.h
-- Looking for vidcap.h - found
-- Looking for d3d11_4.h
-- Looking for d3d11_4.h - found
-- Allocator metrics storage type: 'long long'
-- Excluding from source files list: <BUILD>/modules/core/test/test_intrin256.lasx.cpp
-- Excluding from source files list: modules/imgproc/src/imgwarp.lasx.cpp
-- Excluding from source files list: modules/imgproc/src/resize.lasx.cpp
-- Registering hook 'INIT_MODULE_SOURCES_opencv_dnn': C:/opencv/modules/dnn/cmake/hooks/INIT_MODULE_SOURCES_opencv_dnn.cmake
-- opencv_dnn: filter out cuda4dnn source code
-- Excluding from source files list: modules/dnn/src/layers/cpu_kernels/conv_winograd_f63.neon.cpp
-- Excluding from source files list: <BUILD>/modules/dnn/layers/layers_common.rvv.cpp
-- Excluding from source files list: <BUILD>/modules/dnn/layers/layers_common.lasx.cpp
-- Excluding from source files list: <BUILD>/modules/dnn/int8layers/layers_common.rvv.cpp
-- Excluding from source files list: <BUILD>/modules/dnn/int8layers/layers_common.lasx.cpp
-- Excluding from source files list: <BUILD>/modules/dnn/layers/cpu_kernels/conv_block.neon.cpp
-- Excluding from source files list: <BUILD>/modules/dnn/layers/cpu_kernels/conv_block.neon_fp16.cpp
-- Excluding from source files list: <BUILD>/modules/dnn/layers/cpu_kernels/conv_depthwise.rvv.cpp
-- Excluding from source files list: <BUILD>/modules/dnn/layers/cpu_kernels/conv_depthwise.lasx.cpp
-- Excluding from source files list: <BUILD>/modules/dnn/layers/cpu_kernels/conv_winograd_f63.neon_fp16.cpp
-- Excluding from source files list: <BUILD>/modules/dnn/layers/cpu_kernels/fast_gemm_kernels.neon.cpp
-- Excluding from source files list: <BUILD>/modules/dnn/layers/cpu_kernels/fast_gemm_kernels.lasx.cpp
-- imgcodecs: OpenEXR codec is disabled in runtime. Details: https://github.com/opencv/opencv/issues/21326
-- highgui: using builtin backend: WIN32UI
-- Found 'misc' Python modules from C:/opencv/modules/python/package/extra_modules
-- Found 'mat_wrapper;utils' Python modules from C:/opencv/modules/core/misc/python/package
-- Found 'gapi' Python modules from C:/opencv/modules/gapi/misc/python/package
-- Found 'misc' Python modules from C:/opencv/modules/python/package/extra_modules
-- Found 'mat_wrapper;utils' Python modules from C:/opencv/modules/core/misc/python/package
-- Found 'gapi' Python modules from C:/opencv/modules/gapi/misc/python/package
CMake Warning at cmake/OpenCVGenSetupVars.cmake:54 (message):
  CONFIGURATION IS NOT SUPPORTED: validate setupvars script in install
  directory
Call Stack (most recent call first):
  CMakeLists.txt:1180 (include)


--
-- General configuration for OpenCV 4.10.0 =====================================
--   Version control:               unknown
--
--   Platform:
--     Timestamp:                   2024-12-03T14:50:16Z
--     Host:                        Windows 10.0.22631 AMD64
--     CMake:                       3.27.4
--     CMake generator:             Visual Studio 17 2022
--     CMake build tool:            C:/Program Files/Microsoft Visual Studio/2022/Community/MSBuild/Current/Bin/amd64/MSBuild.exe
--     MSVC:                        1937
--     Configuration:               Debug Release
--
--   CPU/HW features:
--     Baseline:                    SSE SSE2 SSE3
--       requested:                 SSE3
--     Dispatched code generation:  SSE4_1 SSE4_2 FP16 AVX AVX2 AVX512_SKX
--       requested:                 SSE4_1 SSE4_2 AVX FP16 AVX2 AVX512_SKX
--       SSE4_1 (18 files):         + SSSE3 SSE4_1
--       SSE4_2 (2 files):          + SSSE3 SSE4_1 POPCNT SSE4_2
--       FP16 (1 files):            + SSSE3 SSE4_1 POPCNT SSE4_2 FP16 AVX
--       AVX (9 files):             + SSSE3 SSE4_1 POPCNT SSE4_2 AVX
--       AVX2 (38 files):           + SSSE3 SSE4_1 POPCNT SSE4_2 FP16 FMA3 AVX AVX2
--       AVX512_SKX (8 files):      + SSSE3 SSE4_1 POPCNT SSE4_2 FP16 FMA3 AVX AVX2 AVX_512F AVX512_COMMON AVX512_SKX
--
--   C/C++:
--     Built as dynamic libs?:      YES
--     C++ standard:                11
--     C++ Compiler:                C:/Program Files/Microsoft Visual Studio/2022/Community/VC/Tools/MSVC/14.37.32822/bin/Hostx64/x64/cl.exe  (ver 19.37.32825.0)
--     C++ flags (Release):         /DWIN32 /D_WINDOWS /W4 /GR  /D _CRT_SECURE_NO_DEPRECATE /D _CRT_NONSTDC_NO_DEPRECATE /D _SCL_SECURE_NO_WARNINGS /Gy /bigobj /Oi  /fp:precise     /EHa /wd4127 /wd4251 /wd4324 /wd4275 /wd4512 /wd4589 /wd4819 /MP  /O2 /Ob2 /DNDEBUG
--     C++ flags (Debug):           /DWIN32 /D_WINDOWS /W4 /GR  /D _CRT_SECURE_NO_DEPRECATE /D _CRT_NONSTDC_NO_DEPRECATE /D _SCL_SECURE_NO_WARNINGS /Gy /bigobj /Oi  /fp:precise     /EHa /wd4127 /wd4251 /wd4324 /wd4275 /wd4512 /wd4589 /wd4819 /MP  /Zi /Ob0 /Od /RTC1
--     C Compiler:                  C:/Program Files/Microsoft Visual Studio/2022/Community/VC/Tools/MSVC/14.37.32822/bin/Hostx64/x64/cl.exe
--     C flags (Release):           /DWIN32 /D_WINDOWS /W3  /D _CRT_SECURE_NO_DEPRECATE /D _CRT_NONSTDC_NO_DEPRECATE /D _SCL_SECURE_NO_WARNINGS /Gy /bigobj /Oi  /fp:precise     /MP   /O2 /Ob2 /DNDEBUG
--     C flags (Debug):             /DWIN32 /D_WINDOWS /W3  /D _CRT_SECURE_NO_DEPRECATE /D _CRT_NONSTDC_NO_DEPRECATE /D _SCL_SECURE_NO_WARNINGS /Gy /bigobj /Oi  /fp:precise     /MP /Zi /Ob0 /Od /RTC1
--     Linker flags (Release):      /machine:x64  /INCREMENTAL:NO
--     Linker flags (Debug):        /machine:x64  /debug /INCREMENTAL
--     ccache:                      NO
--     Precompiled headers:         YES
--     Extra dependencies:
--     3rdparty dependencies:
--
--   OpenCV modules:
--     To be built:                 calib3d core dnn features2d flann gapi highgui imgcodecs imgproc java ml objdetect photo python3 stitching ts video videoio
--     Disabled:                    world
--     Disabled by dependency:      -
--     Unavailable:                 python2
--     Applications:                tests perf_tests apps
--     Documentation:               NO
--     Non-free algorithms:         NO
--
--   Windows RT support:            NO
--
--   GUI:                           WIN32UI
--     Win32 UI:                    YES
--     VTK support:                 NO
--
--   Media I/O:
--     ZLib:                        build (ver 1.3.1)
--     JPEG:                        build-libjpeg-turbo (ver 3.0.3-70)
--       SIMD Support Request:      YES
--       SIMD Support:              NO
--     WEBP:                        build (ver encoder: 0x020f)
--     PNG:                         build (ver 1.6.43)
--       SIMD Support Request:      YES
--       SIMD Support:              YES (Intel SSE)
--     TIFF:                        build (ver 42 - 4.6.0)
--     JPEG 2000:                   build (ver 2.5.0)
--     OpenEXR:                     build (ver 2.3.0)
--     HDR:                         YES
--     SUNRASTER:                   YES
--     PXM:                         YES
--     PFM:                         YES
--
--   Video I/O:
--     DC1394:                      NO
--     FFMPEG:                      NO (find_package)
--       avcodec:                   YES (#define LIBAVCODEC_VERSION_MINOR  26 #define LIBAVCODEC_VERSION_MICRO 100.26.100)
--       avformat:                  YES (#define LIBAVFORMAT_VERSION_MINOR   9 #define LIBAVFORMAT_VERSION_MICRO 100.9.100)
--       avutil:                    YES (59.47.101)
--       swscale:                   YES (#define LIBSWSCALE_VERSION_MINOR  12 #define LIBSWSCALE_VERSION_MICRO 100.12.100)
--       avresample:                NO
--     GStreamer:                   NO
--     DirectShow:                  YES
--     Media Foundation:            YES
--       DXVA:                      YES
--
--   Parallel framework:            Concurrency
--
--   Trace:                         YES (with Intel ITT)
--
--   Other third-party libraries:
--     Intel IPP:                   2021.11.0 [2021.11.0]
--            at:                   C:/opencv/build/3rdparty/ippicv/ippicv_win/icv
--     Intel IPP IW:                sources (2021.11.0)
--               at:                C:/opencv/build/3rdparty/ippicv/ippicv_win/iw
--     Lapack:                      NO
--     Eigen:                       NO
--     Custom HAL:                  NO
--     Protobuf:                    build (3.19.1)
--     Flatbuffers:                 builtin/3rdparty (23.5.9)
--
--   OpenCL:                        YES (NVD3D11)
--     Include path:                C:/opencv/3rdparty/include/opencl/1.2
--     Link libraries:              Dynamic load
--
--   Python 3:
--     Interpreter:                 C:/Users/EEO/AppData/Local/Programs/Python/Python37/python.exe (ver 3.7.2)
--     Libraries:                   C:/Users/EEO/AppData/Local/Programs/Python/Python37/libs/python37.lib (ver 3.7.2)
--     Limited API:                 NO
--     numpy:                       C:/Users/EEO/AppData/Local/Programs/Python/Python37/lib/site-packages/numpy/core/include (ver 1.21.6)
--     install path:                C:/Users/EEO/AppData/Local/Programs/Python/Python37/Lib/site-packages/cv2/python-3.7
--
--   Python (for build):            C:/Users/EEO/AppData/Local/Programs/Python/Python37/python.exe
--
--   Java:
--     ant:                         NO
--     Java:                        YES (ver 22.0.1)
--     JNI:                         C:/Program Files/Java/jdk-22/include C:/Program Files/Java/jdk-22/include/win32 C:/Program Files/Java/jdk-22/include
--     Java wrappers:               YES (JAVA)
--     Java tests:                  NO
--
--   Install to:                    C:/opencv/build/install
-- -----------------------------------------------------------------
--
-- Configuring done (80.8s)
-- Generating done (3.0s)
-- Build files have been written to: C:/opencv/build

in the output of my ffmpeg :
– Video I/O:
– DC1394: NO
– FFMPEG: NO (find_package)
– avcodec: YES (#define LIBAVCODEC_VERSION_MINOR 26 #define LIBAVCODEC_VERSION_MICRO 100.26.100)
– avformat: YES (#define LIBAVFORMAT_VERSION_MINOR 9 #define LIBAVFORMAT_VERSION_MICRO 100.9.100)
– avutil: YES (59.47.101)
– swscale: YES (#define LIBSWSCALE_VERSION_MINOR 12 #define LIBSWSCALE_VERSION_MICRO 100.12.100)
– avresample: NO
– GStreamer: NO
– DirectShow: YES
– Media Foundation: YES
– DXVA: YES

the avutil is seem to which displayed in ffmpeg as followed:

but it is different with yours
– avutil: YES (57.17.100)
Are you sure the ffmpeg you used is the latest ?

The ffmpeg i used is ffmpeg-master-latest-win64-gpl-shared.zip

Now I see the issue. I’m not using the latest, I’m using the ones I recommended in the post.

I think you will need a different script for the latest version of FFMpeg.

I absolutely agree with your statement about the need for a different script for the latest version of FFMpeg.But I know nothing about how to write cmake script。This really frustrates me! :face_with_spiral_eyes:

The issue with the latest version is that some modules have the major version number stored in a seperate header. Adding the section below allowed me to succesfully build OpenCV against the version you linked to. I haven’t tested the build to make sure it works.

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}" major_version
    REGEX "#define  *LIB${component_upper}_VERSION_MAJOR ")
  string(REGEX REPLACE ".*_MAJOR *\([0-9]*\).*" "\\1" major "${major_version}")
endif()

Modified version below.

ffmpeg-config.cmake
#[==[
Provides the following variables:

  * `FFMPEG_INCLUDE_DIRS`: Include directories necessary to use FFMPEG.
  * `FFMPEG_LIBRARIES`: Libraries necessary to use FFMPEG. Note that this only
    includes libraries for the components requested.
  * `FFMPEG_VERSION`: The version of FFMPEG found.

The following components are supported:

  * `avcodec`
  * `avdevice`
  * `avfilter`
  * `avformat`
  * `avresample`
  * `avutil`
  * `swresample`
  * `swscale`

For each component, the following are provided:

  * `FFMPEG_<component>_FOUND`: Libraries for the component.
  * `FFMPEG_<component>_INCLUDE_DIRS`: Include directories for
    the component.
  * `FFMPEG_<component>_LIBRARIES`: Libraries for the component.
  * `FFMPEG::<component>`: A target to use with `target_link_libraries`.

Note that only components requested with `COMPONENTS` or `OPTIONAL_COMPONENTS`
are guaranteed to set these variables or provide targets.
#]==]

if(NOT DEFINED FFMPEG_ROOT)
  get_filename_component(FFMPEG_ROOT "${CMAKE_CURRENT_LIST_DIR}/.." ABSOLUTE)
endif()

function (_ffmpeg_find component headername)
  find_path("FFMPEG_${component}_INCLUDE_DIR"
    NAMES
      "lib${component}/${headername}"
    PATHS
      "${FFMPEG_ROOT}/include"
      ~/Library/Frameworks
      /Library/Frameworks
      /usr/local/include
      /usr/include
      /sw/include # Fink
      /opt/local/include # DarwinPorts
      /opt/csw/include # Blastwave
      /opt/include
      /usr/freeware/include
    PATH_SUFFIXES
      ffmpeg
    DOC "FFMPEG's ${component} include directory")
  mark_as_advanced("FFMPEG_${component}_INCLUDE_DIR")

  # On Windows, static FFMPEG is sometimes built as `lib<name>.a`.
  if (WIN32)
    list(APPEND CMAKE_FIND_LIBRARY_SUFFIXES ".a" ".lib")
    list(APPEND CMAKE_FIND_LIBRARY_PREFIXES "" "lib")
  endif ()

  find_library("FFMPEG_${component}_LIBRARY"
    NAMES
      "${component}"
    PATHS
      "${FFMPEG_ROOT}/lib"
      ~/Library/Frameworks
      /Library/Frameworks
      /usr/local/lib
      /usr/local/lib64
      /usr/lib
      /usr/lib64
      /sw/lib
      /opt/local/lib
      /opt/csw/lib
      /opt/lib
      /usr/freeware/lib64
      "${FFMPEG_ROOT}/bin"
    DOC "FFMPEG's ${component} library")
  mark_as_advanced("FFMPEG_${component}_LIBRARY")

  if (FFMPEG_${component}_LIBRARY AND FFMPEG_${component}_INCLUDE_DIR)
    set(_deps_found TRUE)
    set(_deps_link)
    foreach (_ffmpeg_dep IN LISTS ARGN)
      if (TARGET "FFMPEG::${_ffmpeg_dep}")
        list(APPEND _deps_link "FFMPEG::${_ffmpeg_dep}")
      else ()
        set(_deps_found FALSE)
      endif ()
    endforeach ()
    if (_deps_found)
      if (NOT TARGET "FFMPEG::${component}")
        add_library("FFMPEG::${component}" UNKNOWN IMPORTED)
        set_target_properties("FFMPEG::${component}" PROPERTIES
          IMPORTED_LOCATION "${FFMPEG_${component}_LIBRARY}"
          INTERFACE_INCLUDE_DIRECTORIES "${FFMPEG_${component}_INCLUDE_DIR}"
          IMPORTED_LINK_INTERFACE_LIBRARIES "${_deps_link}")
      endif ()
      set("FFMPEG_${component}_FOUND" 1
        PARENT_SCOPE)

      set(version_header_path "${FFMPEG_${component}_INCLUDE_DIR}/lib${component}/version.h")
      if (EXISTS "${version_header_path}")
        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}")

        # Modification for newer versions of FFMpeg which store the major version in its own header
        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}" major_version
            REGEX "#define  *LIB${component_upper}_VERSION_MAJOR ")
          string(REGEX REPLACE ".*_MAJOR *\([0-9]*\).*" "\\1" major "${major_version}")
        endif()
        #

        if (NOT major STREQUAL "" AND
            NOT minor STREQUAL "" AND
            NOT micro STREQUAL "")
          set("FFMPEG_${component}_VERSION" "${major}.${minor}.${micro}" PARENT_SCOPE)
          set("FFMPEG_lib${component}_VERSION" "${major}.${minor}.${micro}" CACHE INTERNAL "")
        endif ()
      endif ()
    else ()
      set("FFMPEG_${component}_FOUND" 0
        PARENT_SCOPE)
      set(what)
      if (NOT FFMPEG_${component}_LIBRARY)
        set(what "library")
      endif ()
      if (NOT FFMPEG_${component}_INCLUDE_DIR)
        if (what)
          string(APPEND what " or headers")
        else ()
          set(what "headers")
        endif ()
      endif ()
      set("FFMPEG_${component}_NOT_FOUND_MESSAGE"
        "Could not find the ${what} for ${component}."
        PARENT_SCOPE)
    endif ()
  endif ()
endfunction ()

_ffmpeg_find(avutil     avutil.h)
_ffmpeg_find(avresample avresample.h
  avutil)
_ffmpeg_find(swresample swresample.h
  avutil)
_ffmpeg_find(swscale    swscale.h
  avutil)
_ffmpeg_find(avcodec    avcodec.h
  avutil)
_ffmpeg_find(avformat   avformat.h
  avcodec avutil)
_ffmpeg_find(avfilter   avfilter.h
  avutil)
_ffmpeg_find(avdevice   avdevice.h
  avformat avutil)

if(NOT FFMPEG_FIND_COMPONENTS)
  set(FFMPEG_FIND_COMPONENTS avutil swresample swscale avcodec avformat avfilter avdevice)  # optional avresample
endif()

if (TARGET FFMPEG::avutil)
  set(_ffmpeg_version_header_path "${FFMPEG_avutil_INCLUDE_DIR}/libavutil/ffversion.h")
  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}")
    unset(_ffmpeg_version)
  else ()
    set(FFMPEG_VERSION FFMPEG_VERSION-NOTFOUND)
  endif ()
  unset(_ffmpeg_version_header_path)
endif ()

set(FFMPEG_INCLUDE_DIRS)
set(FFMPEG_LIBRARIES)
set(__ffmpeg_version_vars)
set(_ffmpeg_required_vars)
foreach (_ffmpeg_component IN LISTS FFMPEG_FIND_COMPONENTS)
  if (TARGET "FFMPEG::${_ffmpeg_component}")
    set(FFMPEG_${_ffmpeg_component}_INCLUDE_DIRS
      "${FFMPEG_${_ffmpeg_component}_INCLUDE_DIR}")
    set(FFMPEG_${_ffmpeg_component}_LIBRARIES
      "${FFMPEG_${_ffmpeg_component}_LIBRARY}")
    list(APPEND FFMPEG_INCLUDE_DIRS
      "${FFMPEG_${_ffmpeg_component}_INCLUDE_DIRS}")
    list(APPEND FFMPEG_LIBRARIES
      "${FFMPEG_${_ffmpeg_component}_LIBRARIES}")
    if (FFMEG_FIND_REQUIRED_${_ffmpeg_component})
      list(APPEND _ffmpeg_required_vars
        "FFMPEG_${_ffmpeg_required_vars}_INCLUDE_DIRS"
        "FFMPEG_${_ffmpeg_required_vars}_LIBRARIES")
    endif ()
  endif ()
endforeach ()
unset(_ffmpeg_component)

if(FFMPEG_INCLUDE_DIRS)
  list(REMOVE_DUPLICATES FFMPEG_INCLUDE_DIRS)
endif ()

include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(FFMPEG
  REQUIRED_VARS FFMPEG_INCLUDE_DIRS FFMPEG_LIBRARIES ${_ffmpeg_required_vars}
  VERSION_VAR FFMPEG_VERSION
  HANDLE_COMPONENTS)
unset(_ffmpeg_required_vars)
1 Like

IT DOES WORKED,thank you very much!

2 Likes