how can I use the openCV FFMPEG video I/O rather than the DirectShow one in Windows?
Asked Answered
A

2

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?

Ardy answered 22/2, 2012 at 0:19 Comment(2)
possible duplicate of How to compile OpenCV 2.3 with ffmpeg support with Visual Studio 2010Mitman
i saw that but there is NO USE_FFMPEG flag as the answer suggestsArdy
A
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 ;)

Ardy answered 2/5, 2012 at 20:38 Comment(2)
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.Ardy
Can you tell me, how can accomplish the same in android stdio with opencvBillbug
V
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

Vandenberg answered 2/4, 2012 at 19:54 Comment(4)
I adapted it to my own project and it works like a charm. :) Good luck.Vandenberg
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 notArdy
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)Ardy
Nice! I will have to try out your solution.Vandenberg

© 2022 - 2024 — McMap. All rights reserved.