Take the 2-minute tour ×

So I'm trying to write a video using the openCV videoWriter as such:


So instead of supplying the FOURCC I supplied -1 in order to see what codecs I have available. Result was Microsoft RLE, Microsoft Video 1, Intel YUV, and Uncompressed.

The reason is that when configuring openCV using CMAKE for Visual Studio 10 x64, this is what I have in the video i/o: Video I/O: DirectShow

Is there a way to switch this to FFMPEG? I know the ffmpeg dll is present in \3dparty\ffmpeg. I looked for Cmake FFMPEG flags but found none whatsoever. The weird thing is in the CmakeLists.txt in the opencv root under the video section:

<FFMPEG stuff>
    status("  Video I/O:"        HAVE_VIDEOINPUT     THEN DirectShow ELSE NO)

So it seems to me that opencv automatically switched to DirectShow and gives no choice of using FFMpeg. Or rather can one upgrade Driectshow to support other formats such as Divx or h264? Any ideas?

share|improve this question
i saw that but there is NO USE_FFMPEG flag as the answer suggests –  octi Feb 22 '12 at 15:01
add comment

2 Answers

The answer your looking for is here and it works for the 32 bit and 64 bit configurations. I used this build of FFMPEG. http://ffmpeg.zeranoe.com/builds/win64/dev/ffmpeg-git-1aeb88b-win64-dev.7z

1) Download OpenCV 2.3

2) Open the root CMakeLists.txt and insert the line set(HAVE_FFMPEG 1)

3) Download http://ffmpeg.zeranoe.com/builds/win64/dev/ffmpeg-git-1aeb88b-win64-dev.7z (or the 32 bit build if u fancy it)

4) Edit avformat.h found in the ffmpeg include dir with #define INT64_C

5) Edit cap_ffmpeg_impl.hpp from the highgui project with #define snprintf _snprintf

6) in your highgui project properties under C/C++>Additional Include Directories add path of the include directory of FFMPEG you just downloaded

7)On the same property page under Linker>General>Additional Library Dependencies add the path of the lib directory of FFMPEG you just downloaded

8)On the same property page under Linker>Input>Additional dependencies add ALL the names of the libraries of ffmpeg found in lib (avformat.lib, avscale.lib, avcore.lib etc)

9) build the highgui project

10) Add the path of the .dll files that came with FFMPEG to the System Path environment variable.

That's it! 10 easy steps ;)

share|improve this answer
ALso in OpenCV 2.4 everything is streamlined and the ffmpeg dll is bundled in the 3rdparty libraries. The code has been adapted to load the dll at runtime and call the functions rather than linking the FFMPEG static libraries to the OpenCV projects. –  octi Jun 26 '12 at 19:39
add comment

If you're still unable to compile OpenCV with FFMpeg support, the library that is linked on this blogpost provides a pretty good starting point for creating a windows-compatible FFMpeg wrapper: Making OpenCV-2.3 work with ffmpeg library and Microsoft Visual Studio 2010

share|improve this answer
I'll look into it but if it works it would be great. –  octi Apr 11 '12 at 2:45
I adapted it to my own project and it works like a charm. :) Good luck. –  Colin Ray Apr 12 '12 at 17:21
So i looked more carefully into the solution and I had to adapt it to a 64 bit build. I got the 64-bit binaries from the FFMPEG website. but now I get 3 linking errors when I'm attempting to build test-ffmpeg-api. specifically, dump_format av_open_input_file and avcodec_decode_video. One of them I figured out because it was deprecated. dump_format I could not –  octi May 2 '12 at 17:24
Ok so I used the 64 libraries equivalent to the 32 bit ones bundled in the zip you linked and it works! However, this is just using the interface he provides. I developed a more general solution that builds the highgui library itself with FFMPEG support. This means that any library linking to highgui will have it (pythonbindings, video etc) –  octi May 2 '12 at 20:37
Nice! I will have to try out your solution. –  Colin Ray May 2 '12 at 23:22
add comment

Your Answer


