how can I use the openCV FFMPEG video I/O rather t

2019-06-08 16:39发布

问题:

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?

回答1:

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



回答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