Today see a lot of people on the Internet ask, Cvcreatefilecapture read AVI, why always return null. I checked the literature, summed up as follows: (source program attached to the bottom)
Question: Why does my Computer support AVI or can broadcast AVI, but why use the Cvcreatefilecapture function to always return null? Answer: Although it is an AVI file, it is possible to use some kind of codec, such as: MJPEG decompressor. Need to convert it to OPENCV supported AVI files. The OPENCV supports AVI as follows:
Container |
FourCC |
Name |
Description |
Avi |
' DIB ' |
RGB (A) |
Uncompressed RGB, or bit |
Avi |
' I420 ' |
RAW I420 |
Uncompressed YUV, 4:2:0 chroma subsampled |
Avi |
' iYUV ' |
RAW I420 |
Identical to I420 |
Conversion format Workaround: Workaround 1: Download Mencoder.exe, use under Window command line: mencoder IN.AVI-OVC raw-vf Format=i420-o Out.avi (Note: I tested this method, did not succeed, reason unknown , I hope some friends can discuss it in detail. )
Workaround 2: Download Vitualdub, I use 1.9.4 version A. File->open video File; B. video->filters->add->convert format; Select 4:2:0 Planar YCbCr (YV12) or 32-bit RGB. C. Save as AVI. Save complete. (Note: successful use.) )
We can test it. If still not, please reply and discuss together.
My source code, (VS C + + 2008 Expression, WinXP SP3,)//----------------------------------------------------------------------- -------------------------
#include "stdafx.h" #include <iostream> #include <cv.h> #include <cxcore.h> #include iplimage* frame; Cvnamedwindow ("PlayAVI", cv_window_autosize); while (1) {frame = Cvqueryframe (capture ); if (!frame) break;
Cvshowimage ("PlayAVI", frame); key = Cvwaitkey ()//Quit when users press ' ESC ' if (key = =) break; } cvreleasecapture (&capture); Cvdestroywindow ("PlayAVI");
return 0;} from http://hq.huang.blog.163.com/blog/static/ 1066821912009758958885/