problem playing avi video, cvcreateFileCapture returning NULL pointer
Hi there! I used the following code, which compiled successfully and used lots of avi files to test a.out with.
But every time, NULL pointer was returned. Please help, same problem is stated here :http://nuigroup.com/forums/viewthread/6132/, but solutions there havent helped me yet.
Code:
#include “highgui.h”
#include "stdio.h"
int main( int argc, char** argv ) {
cvNamedWindow( “Example2”, CV_WINDOW_AUTOSIZE );
CvCapture* capture = cvCreateFileCapture( argv[1] );
IplImage* frame;
while(1) {
frame = cvQueryFrame( capture );
if( !frame )
{
printf("EMPTY OR NULL");
break;//ends HERE!!!!!
}
cvShowImage( “Example2”, frame );
char c = cvWaitKey(33);
if( c == 27 ) break;
}
cvReleaseCapture( &capture );
cvDestroyWindow( “Example2” );
}
Two suggestions: 1 - get rid of the old C style API and switch to the newer C++ API with the VideoCapture class and VideoWriter class, which does everything like decoding, encoding, opening and closing for you in a smart way. 2 - make sure your system has somewhere a decent codec pack installed. This can be done by googling for a complete codec pack or by just installing software like VLC media player which supports more codecs than I can imagine. BUT my best guess is that switching to the newer C++ API will immediatly solve all your problems.