如何在 Windows 中使用 openCV FFMPEG 视频 I/O 而不是 DirectShow?
所以我尝试使用 openCV videoWriter 编写一个视频,如下所示:
writer=cv.CreateVideoWriter(path+"test_output.avi",-1,fps,(W,H),1)
因此,我没有提供 FOURCC,而是提供了 -1 来查看我有哪些可用的编解码器。 结果是 Microsoft RLE、Microsoft Video 1、Intel YUV 和未压缩。
原因是,当使用 CMAKE for Visual Studio 10 x64 配置 openCV 时,这就是我在视频 i/o 中的内容: 视频 I/O:DirectShow
有没有办法将其切换到 FFMPEG?我知道 ffmpeg dll 存在于 \3dparty\ffmpeg 中。 我寻找了 Cmake FFMPEG 标志,但没有找到任何东西。奇怪的是在视频部分下opencv根目录下的CmakeLists.txt中:
if(UNIX AND NOT APPLE)
<FFMPEG stuff>
elseif(WIN32)
status(" Video I/O:" HAVE_VIDEOINPUT THEN DirectShow ELSE NO)
endif()
所以在我看来opencv自动切换到DirectShow并且没有选择使用FFMpeg。 或者更确切地说,是否可以升级 Driectshow 以支持其他格式,例如 Divx 或 h264? 有什么想法吗?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您寻找的答案就在这里,它适用于 32 位和 64 位配置。我使用了这个版本的 FFMPEG。 http://ffmpeg.zeranoe.com/builds/win64/dev/ ffmpeg-git-1aeb88b-win64-dev.7z
1) 下载 OpenCV 2.3
2) 打开根 CMakeLists.txt 并插入行集(HAVE_FFMPEG 1)
3) 下载 http://ffmpeg.zeranoe .com/builds/win64/dev/ffmpeg-git-1aeb88b-win64-dev.7z (或者 32 位版本,如果你喜欢它)
4)使用#define INT64_C编辑在ffmpeg包含目录中找到的avformat.h
5)使用#define snprintf _snprintf从highgui项目编辑cap_ffmpeg_impl.hpp
6)在C/C++>Additional Include下的highgui项目属性中目录添加您刚刚下载的 FFMPEG 的包含目录的路径
7)在同一属性页下Linker>General>Additional Library Dependencies 添加刚刚下载的 FFMPEG 的 lib 目录的路径
8) 在 Linker>Input>Additional dependency 下的同一属性页上添加 lib 中找到的 ffmpeg 的所有库名称(avformat.lib、 avscale.lib、avcore.lib等)
9)构建highgui项目
10)将FFMPEG附带的.dll文件的路径添加到系统路径中环境变量。
就是这样! 10 个简单步骤;)
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 ;)
如果您仍然无法编译支持 FFMpeg 的 OpenCV,本博文中链接的库为创建 Windows 兼容的 FFMpeg 包装器提供了一个非常好的起点:使 OpenCV-2.3 与 ffmpeg 库和 Microsoft Visual Studio 2010 一起使用
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