Ask Your Question
1

How to build opencv_ffmpeg.dll from patched FFmpeg source

asked 2017-02-04 08:01:33 -0600

ryantheseer gravatar image

updated 2017-02-06 07:44:15 -0600

I am trying to write a patch to the FFmpeg API, and I am able to build the FFmpeg library dlls for Windows successfully using the instructions on their website (MinGW/FFmpeg installation guide). However, I'm not sure how to package these various dlls (avfilter.dll, avformat.dll, avcodec.dll, etc.) into the opencv_ffmpeg.dll that the CMake looks for when building OpenCV. I will eventually want to build my custom FFmpeg libraries and OpenCV cross-platform for Linux and Mac OS X, as well. The end game is to have Java-wrapped OpenCV working cross-platform with a modified FFmpeg API. How do I do this?

edit retag flag offensive close merge delete

Comments

Going to try to follow the steps here: http://code.opencv.org/issues/4362#no...

ryantheseer gravatar imageryantheseer ( 2017-02-06 15:20:20 -0600 )edit

1 answer

Sort by » oldest newest most voted
2

answered 2017-02-14 13:01:51 -0600

ryantheseer gravatar image

updated 2017-02-14 13:06:25 -0600

This worked for me to build the 64-bit FFmpeg API from source:

1. Build the FFmpeg .a static library archives(which are object that are inputs to a linker). On 64-bit Windows, I configured the FFmpeg build like this:
./configure --target-os=win32 --disable-programs --disable-doc --enable-static --enable-shared
make
make install

2. Copy the .a static library archives into a folder in the OpenCV source folder under \3rdparty\lib, and add the suffix 64 for the 64-bit archives:

  • ffmpeg/libavcodec/libavcodec.a → opencv/3rdparty/lib/libavcodec64.a
  • ffmpeg/libavdevice/libavdevice.a → opencv/3rdparty/lib/libavdevice64.a
  • ffmpeg/libavfilter/libavfilter.a → opencv/3rdparty/lib/libavfilter64.a
  • ffmpeg/libavformat/libavformat.a → opencv/3rdparty/lib/libavformat64.a
  • ffmpeg/libavutil/libavutil.a → opencv/3rdparty/lib/libavutil64.a
  • ffmpeg/libswresample/libswresample.a → opencv/3rdparty/lib/libswresample64.a
  • ffmpeg/libswscale/libswscale.a → opencv/3rdparty/lib/libswscale64.a

3. Copy all the C/C++ header files in the FFmpeg source directory to a new OpenCV source directory called \3rdparty\include\ffmpeg_. For example:
cp /ffmpeg/libavcodec/*.h /opencv/3rdparty/include/ffmpeg_/libavcodec
cp /ffmpeg/libavdevice/*.h /opencv/3rdparty/include/ffmpeg_/libavdevice
cp /ffmpeg/libavfilter/*.h /opencv/3rdparty/include/ffmpeg_/libavfilter
cp /ffmpeg/libavformat/*.h /opencv/3rdparty/include/ffmpeg_/libavformat
cp /ffmpeg/libavresample/*.h /opencv/3rdparty/include/ffmpeg_/libavresample
cp /ffmpeg/libavutil/*.h /opencv/3rdparty/include/ffmpeg_/libavutil
cp /ffmpeg/libpostproc/*.h /opencv/3rdparty/include/ffmpeg_/libpostproc
cp /ffmpeg/libswresample/*.h /opencv/3rdparty/include/ffmpeg_/libswresample
cp /ffmpeg/libswscale/*.h /opencv/3rdparty/include/ffmpeg_/libswscale

4. In the OpenCV \3rdparty\ffmpeg folder, create a file called ffopencv.c, with these contents:
#include "cap_ffmpeg_impl.hpp"

5. From the OpenCV \3rdparty\ffmpeg folder, run the following from the Windows command line with Cygwin and MingW installed:
x86_64-w64-mingw32-g++ -m64 -Wall -static -static-libgcc -static-libstdc++ -shared -o opencv_ffmpeg320_64.dll -O2 -x c++ -I../include -I../include/ffmpeg_ -I../../modules/videoio/src -I/../../modules/highgui/src ffopencv.c -L../lib -lavdevice64 -lavfilter64 -lavformat64 -lavcodec64 -lavutil64 -lswscale64 -lswresample64 -lws2_32 -liconv -lz -lbz2 -lsecur32

This will produce the opencv_ffmpeg320_64.dll (or you can use another name, if applicable) in the correct folder. Whenever you change the OpenCV FFmpeg API, you will only have to re-run Step 5. Whenever you change FFmpeg source code, you will have to re-run Steps 1-5.

edit flag offensive delete link more

Comments

Hello, I am getting an error "could not create temporary library" when executing make statement in msys.bat.

I have downloaded MingW from https://sourceforge.net/projects/ming...

Can you please help me direct to correct MingW version (whether 32bit or 64bit) and any other software required for compile. I am new to all this.

I am try to compile it on windows 10 64 bit.

Jaideep gravatar imageJaideep ( 2017-07-03 03:39:38 -0600 )edit

I am currently using msvc and I have .dlls and .lib files after compiling FFMPEG. Could you guide me on How to create a opencv_ffmpeg320.dll with msys2? Here is the procedure: https://gist.github.com/RangelReale/3...

Dronzer gravatar imageDronzer ( 2020-04-16 04:51:08 -0600 )edit

Question Tools

2 followers

Stats

Asked: 2017-02-04 08:01:33 -0600

Seen: 6,436 times

Last updated: Feb 14 '17