简体   繁体   中英

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

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. 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.

Is there a way to direct openCV to select one of these codecs using VideoWriter, or some other method?

THINGS I HAVE TRIED ALREADY: copying opencv_ffmpeg.dll to python folder and selecting FMP4 codec from FOURCC

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

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. For example I have openCV 2.4.10 so I changed it to opencv_ffmpg2410.dll. More examples can be found on this question.

OpenCV 2.4 VideoCapture not working on Windows

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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