# openCV - Method to use user-built ffmpeg in windows OS

**URL:** <https://forum.opencv.org/t/opencv-method-to-use-user-built-ffmpeg-in-windows-os/16090>\
**Category:** C++\
**Tags:** ffmpeg, windows, build, videoio\
**Created:** [January 8, 2024, 10:31am UTC](https://forum.opencv.org/t/opencv-method-to-use-user-built-ffmpeg-in-windows-os/16090 "2024-01-08T10:31:46Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ratheesh](https://avatars.discourse-cdn.com/v4/letter/r/c37758/32.png) [@Ratheesh](https://forum.opencv.org/u/Ratheesh)\
**Post date:** [January 8, 2024, 10:31am UTC](https://forum.opencv.org/t/opencv-method-to-use-user-built-ffmpeg-in-windows-os/16090/1 "2024-01-08T10:31:46Z")

</div>

openCV - Method to use user-built ffmpeg in windows OS

Hi Technical Team,

I am using Opencv 4.9.0 in windows 11 OS.

I have read the readme.txt from openCV source directory “opencv-4.9.0\3rdparty\ffmpeg”.  
From the “readme.txt” file, I understood that Linux platform is having support to use user-build ffmpeg but it is not mentioned for windows platform.

My question:

How do i customize/configure CMake to use “user-build ffmpeg” ?

Thanks,  
Ratheesh

---

<div class="post-metadata">

**Author:** ![cudawarped](https://avatars.discourse-cdn.com/v4/letter/c/9dc877/32.png) [@cudawarped](https://forum.opencv.org/u/cudawarped)\
**Post date:** [January 8, 2024, 11:02am UTC](https://forum.opencv.org/t/opencv-method-to-use-user-built-ffmpeg-in-windows-os/16090/2 "2024-01-08T11:02:19Z")

</div>

> [@Error: 'Your platform doesn't suppport hardware accelerated AV1 decoding.' when i use 'cv2.VideoCapture'](https://forum.opencv.org/t/error-your-platform-doesnt-suppport-hardware-accelerated-av1-decoding-when-i-use-cv2-videocapture/9605/14):
>
> To build against FFmpeg and get AV1 decoding you need to: Build or dowload and extract a build of FFMpeg to \<FFMPEG\_BUILD\>. I would suggest simply downloading from [here](https://github.com/BtbN/FFmpeg-Builds/releases) and depending on your license requirements you will want to download either [ffmpeg-n5.0.1-7-g7389a49fd3-win64-gpl-shared-5.0.zip](https://github.com/BtbN/FFmpeg-Builds/releases/download/autobuild-2022-06-30-12-32/ffmpeg-n5.0.1-7-g7389a49fd3-win64-gpl-shared-5.0.zip) or [ffmpeg-n5.0.1-7-g7389a49fd3-win64-lgpl-shared-5.0.zip](https://github.com/BtbN/FFmpeg-Builds/releases/download/autobuild-2022-06-30-12-32/ffmpeg-n5.0.1-7-g7389a49fd3-win64-lgpl-shared-5.0.zip) Create a cmake directory \<FFMPEG\_BUILD\>/cmake. Save the cmake script (ffmpeg-config.cmake) mentioned in the below post to that directory. …

---

<div class="post-metadata">

**Author:** ![Ratheesh](https://avatars.discourse-cdn.com/v4/letter/r/c37758/32.png) [@Ratheesh](https://forum.opencv.org/u/Ratheesh)\
**Post date:** [January 8, 2024, 12:15pm UTC](https://forum.opencv.org/t/opencv-method-to-use-user-built-ffmpeg-in-windows-os/16090/3 "2024-01-08T12:15:15Z")

</div>

Hi,  
Thanks for your immediate response.

From your above link i could not find below suggested directory in source of opencv-4.9.0 or also in build directory `**<FFMPEG_BUILD>`\*\*

My question:

1. Is this directory needs to be created? , if yes please suggest the location?

Regards,  
Ratheesh

---

<div class="post-metadata">

**Author:** ![cudawarped](https://avatars.discourse-cdn.com/v4/letter/c/9dc877/32.png) [@cudawarped](https://forum.opencv.org/u/cudawarped)\
**Post date:** [January 8, 2024, 12:52pm UTC](https://forum.opencv.org/t/opencv-method-to-use-user-built-ffmpeg-in-windows-os/16090/4 "2024-01-08T12:52:19Z")

</div>

> [@Ratheesh](#):
>
> From your above link i could not find below suggested directory in source of opencv-4.9.0 or also in build directory `**<FFMPEG_BUILD>`\*\*
> 
> My question:
> 
> 1. Is this directory needs to be created? , if yes please suggest the location?

`**<FFMPEG_BUILD>`\*\* is the directory containing your ffmpeg build.

You then add the cmake script and add it to your path. I don’t think the linked cmake script works with the latest version of FFMpeg but the two pre-built versions I linked to in that post will.

---

<div class="post-metadata">

**Author:** ![Ratheesh](https://avatars.discourse-cdn.com/v4/letter/r/c37758/32.png) [@Ratheesh](https://forum.opencv.org/u/Ratheesh)\
**Post date:** [January 8, 2024, 4:05pm UTC](https://forum.opencv.org/t/opencv-method-to-use-user-built-ffmpeg-in-windows-os/16090/5 "2024-01-08T16:05:05Z")

</div>

Hi,  
Thanks for your response.

I have followed steps 1 to 4 from the above link.  
For the step 5 ( flag `OPENCV_FFMPEG_USE_FIND_PACKAGE=ON`) , I am not finding this flag `OPENCV_FFMPEG_USE_FIND_PACKAGE` in cmake-gui.

Please find the screenshot for this

 ![image](https://us1.discourse-cdn.com/flex020/uploads/opencv/original/2X/9/9892ff7d87fbffabea4302bcfb6ad98f4e70fdeb.png)

Please give your suggestion.

Regards,  
Ratheesh

---

<div class="post-metadata">

**Author:** ![cudawarped](https://avatars.discourse-cdn.com/v4/letter/c/9dc877/32.png) [@cudawarped](https://forum.opencv.org/u/cudawarped)\
**Post date:** [January 8, 2024, 5:18pm UTC](https://forum.opencv.org/t/opencv-method-to-use-user-built-ffmpeg-in-windows-os/16090/6 "2024-01-08T17:18:52Z")

</div>

Either add it using **Add Entry** or use the command line. I would use the CMake command line and not the GUI because you will be able to get more help when things go wrong. i.e. Its easy to reproduce exactly what you have done.

---

<div class="post-metadata">

**Author:** ![Ratheesh](https://avatars.discourse-cdn.com/v4/letter/r/c37758/32.png) [@Ratheesh](https://forum.opencv.org/u/Ratheesh)\
**Post date:** [January 9, 2024, 4:02pm UTC](https://forum.opencv.org/t/opencv-method-to-use-user-built-ffmpeg-in-windows-os/16090/7 "2024-01-09T16:02:00Z")

</div>

Hi,  
I am not familiar with command line execution in CMake.

After followed your instructed steps, i found below in CMake-GUI console only

Video I/O:  
DC1394: NO  
**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  
DirectShow: YES  
Media Foundation: YES  
DXVA: YES

My Question:

1. which location can i find cmake output log details to confirm the FFMpeg inclusion?

Regards,  
Ratheesh

---

<div class="post-metadata">

**Author:** ![cudawarped](https://avatars.discourse-cdn.com/v4/letter/c/9dc877/32.png) [@cudawarped](https://forum.opencv.org/u/cudawarped)\
**Post date:** [January 9, 2024, 4:46pm UTC](https://forum.opencv.org/t/opencv-method-to-use-user-built-ffmpeg-in-windows-os/16090/8 "2024-01-09T16:46:37Z")

</div>

> [@Ratheesh](#):
>
> which location can i find cmake output log details to confirm the FFMpeg inclusion?

The output above confirms it. The prebuilt binaries output would be

> ```auto
> -- Video I/O:
> -- DC1394: NO
> -- FFMPEG: YES (prebuilt binaries)
> -- avcodec: YES (58.134.100)
> -- avformat: YES (58.76.100)
> -- avutil: YES (56.70.100)
> -- swscale: YES (5.9.100)
> -- avresample: YES (4.0.0)
> -- GStreamer: NO
> -- DirectShow: YES
> -- Media Foundation: YES
> -- DXVA: YES
> 
> ```

Don’t forget to add **\<FFMPEG\_BUILD\>/bin** to your path.

---

<div class="post-metadata">

**Author:** ![dengfeng\_zhan](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.opencv.org/dengfeng_zhan/32/11576_2.png) [@dengfeng\_zhan](https://forum.opencv.org/u/dengfeng_zhan)\
**Post date:** [December 3, 2024, 6:54am UTC](https://forum.opencv.org/t/opencv-method-to-use-user-built-ffmpeg-in-windows-os/16090/9 "2024-12-03T06:54:29Z")

</div>

when i used opencv4.10 and ffmpeg-n5.1-latest-win64-gpl-shared-5.1.zip ,i got as  
Found FFMPEG: C:/ffmpeg51/include (found version “5.1.6-11-gcde3c5fc0c-20241202”) 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 37;#define LIBAVCODEC\_VERSION\_MICRO 100.37.100).  
FFMPEG is disabled. Can’t find suitable libavformat library (minimal 54.20.4, found #define LIBAVFORMAT\_VERSION\_MINOR 27;#define LIBAVFORMAT\_VERSION\_MICRO 100.27.100).  
FFMPEG is disabled. Can’t find suitable libswscale library (minimal 2.1.1, found #define LIBSWSCALE\_VERSION\_MINOR 7;#define LIBSWSCALE\_VERSION\_MICRO 100.7.100).  
FFMPEG libraries version check failed (minimal libav release 9.20, minimal FFMPEG release 1.1.16).

and

Video I/O:  
DC1394: NO  
FFMPEG: NO (find\_package)  
avcodec: YES (#define LIBAVCODEC\_VERSION\_MINOR 37 #define LIBAVCODEC\_VERSION\_MICRO 100.37.100)  
avformat: YES (#define LIBAVFORMAT\_VERSION\_MINOR 27 #define LIBAVFORMAT\_VERSION\_MICRO 100.27.100)  
avutil: YES (57.28.100)  
swscale: YES (#define LIBSWSCALE\_VERSION\_MINOR 7 #define LIBSWSCALE\_VERSION\_MICRO 100.7.100)  
avresample: NO  
GStreamer: NO  
DirectShow: YES  
Media Foundation: YES  
DXVA: YES  
is there some thing wrong？please give me a help!  
thinks,  
jam

---

<div class="post-metadata">

**Author:** ![cudawarped](https://avatars.discourse-cdn.com/v4/letter/c/9dc877/32.png) [@cudawarped](https://forum.opencv.org/u/cudawarped)\
**Post date:** [December 3, 2024, 7:48am UTC](https://forum.opencv.org/t/opencv-method-to-use-user-built-ffmpeg-in-windows-os/16090/10 "2024-12-03T07:48:08Z")

</div>

> [@dengfeng\_zhan](#):
>
> is there some thing wrong？please give me a help!

Yes the output from CMake is incorrect. What are the exact steps you took?

---

<div class="post-metadata">

**Author:** ![dengfeng\_zhan](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.opencv.org/dengfeng_zhan/32/11576_2.png) [@dengfeng\_zhan](https://forum.opencv.org/u/dengfeng_zhan)\
**Post date:** [December 3, 2024, 1:29pm UTC](https://forum.opencv.org/t/opencv-method-to-use-user-built-ffmpeg-in-windows-os/16090/14 "2024-12-03T13:29:26Z")

</div>

maybe the ffmpeg i used is the latest and the `ffmpeg-config.cmake` you mentioned above and provided doesn’t work right。Is there a ffmpeg-config.cmake script fit with the latest ffmpeg

---

<div class="post-metadata">

**Author:** ![cudawarped](https://avatars.discourse-cdn.com/v4/letter/c/9dc877/32.png) [@cudawarped](https://forum.opencv.org/u/cudawarped)\
**Post date:** [December 3, 2024, 1:36pm UTC](https://forum.opencv.org/t/opencv-method-to-use-user-built-ffmpeg-in-windows-os/16090/15 "2024-12-03T13:36:45Z")

</div>

The contents of the file I’m using is below.

> **ffmpeg-config.cmake**
>
> ```auto
> #[==[
> 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}")
> 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)
> 
> ```
