1

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

writer=cv.CreateVideoWriter(path+"test_output.avi",-1,fps,(W,H),1)

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:

if(UNIX AND NOT APPLE)
<FFMPEG stuff>
elseif(WIN32)
    status("  Video I/O:"        HAVE_VIDEOINPUT     THEN DirectShow ELSE NO)
endif()

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?

octi
  • 1,470
  • 1
  • 17
  • 28
  • 1
    possible duplicate of [How to compile OpenCV 2.3 with ffmpeg support with Visual Studio 2010](http://stackoverflow.com/questions/7075180/how-to-compile-opencv-2-3-with-ffmpeg-support-with-visual-studio-2010) – karlphillip Feb 22 '12 at 11:49
  • 1
    i saw that but there is NO USE_FFMPEG flag as the answer suggests – octi Feb 22 '12 at 15:01

2 Answers2

8

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 ;)

octi
  • 1,470
  • 1
  • 17
  • 28
  • 1
    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
  • 1
    Can you tell me, how can accomplish the same in android stdio with opencv – Abdul Muheet Feb 07 '18 at 09:21
2

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

Colin Ray
  • 165
  • 2
  • 14
  • 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 02 '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 02 '12 at 20:37
  • Nice! I will have to try out your solution. – Colin Ray May 02 '12 at 23:22