简体   繁体   English

OpenCV VideoWriter自动编解码器选择

[英]OpenCV VideoWriter Automatic Codec selection

I"m experiencing the same problem a lot of other people are experiencing with openCV, in that when I use the following code, openCV fails to write a video file. I am using openCV 2.4.10 and python 2.7 我遇到了很多其他人在使用openCV时遇到的相同问题,因为当我使用以下代码时,openCV无法写入视频文件。我使用的是openCV 2.4.10和python 2.7

out = cv2.VideoWriter('C:\motion\output.avi',cv2.cv.CV_FOURCC('X','V','I','D'), 20, (640,480),True)

a viable work around is to replace the second argument with -1, which gives a popup window with coded choices when the program is run. 可行的解决方法是将第二个参数替换为-1,这将在程序运行时提供带有编码选择的弹出窗口。 When one of these is selected, the video is created. 选择其中一项时,将创建视频。

The problem is, I am adding it to a motion detection software which writes a 15 second timestamped file every time it detects motion, and obviously selecting a codec manually does not work with this scheme. 问题是,我将其添加到运动检测软件中,该软件每次检测到运动时都会写入一个带有时间戳的15秒文件,显然,手动选择编解码器不适用于此方案。

Is there a way to direct openCV to select one of these codecs using VideoWriter, or some other method? 有没有一种方法可以使用VideoWriter或其他方法来指导openCV选择这些编解码器之一?

THINGS I HAVE TRIED ALREADY: copying opencv_ffmpeg.dll to python folder and selecting FMP4 codec from FOURCC 我已经尝试过的事情:将opencv_ffmpeg.dll复制到python文件夹并从FOURCC中选择FMP4编解码器

While I did not find an alternative way to select the codecs available, I did find the answer to the underlying problem of openCV not finding it's own codecs (which is good because the windows codecs were producing files ~50x larger than those produced by the fmp4 codec). 虽然我没有找到选择可用编解码器的另一种方法,但确实找到了openCV的根本问题的答案,即找不到自己的编解码器(这很好,因为Windows编解码器生成的文件比fmp4生成的文件大50倍编解码器)。

Access the codecs, copy the files from the opencv\\sources\\3rdparty\\ffmpeg folder to your python27 folder, then change the names from opencv_ffmpeg.dll to opencv_ffmpegXYZ.dll where XYZ = your version of openCV. 访问编解码器,将文件从opencv \\ sources \\ 3rdparty \\ ffmpeg文件夹复制到python27文件夹,然后将名称从opencv_ffmpeg.dll更改为opencv_ffmpegXYZ.dll,其中XYZ =您的openCV版本。 For example I have openCV 2.4.10 so I changed it to opencv_ffmpg2410.dll. 例如,我有openCV 2.4.10,因此将其更改为opencv_ffmpg2410.dll。 More examples can be found on this question. 有关此问题的更多示例。

OpenCV 2.4 VideoCapture not working on Windows OpenCV 2.4 VideoCapture在Windows上不起作用

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM