Ask Your Question
0

problem playing avi video, cvcreateFileCapture returning NULL pointer

asked 2013-08-16 02:29:50 -0600

Deepak gravatar image

updated 2013-08-16 06:11:58 -0600

Haris gravatar image

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” );

}
edit retag flag offensive close merge delete

Comments

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.

StevenPuttemans gravatar imageStevenPuttemans ( 2013-08-17 03:48:47 -0600 )edit

3 answers

Sort by » oldest newest most voted
0

answered 2013-08-16 18:49:01 -0600

Gus gravatar image

I did have the same problem, when trying to run this code with some videos, because I did not have the right codecs to play it. I do not see any problems with your code. Try more videos with different codecs.

edit flag offensive delete link more
0

answered 2013-08-17 03:52:45 -0600

updated 2013-08-17 03:59:47 -0600

berak gravatar image

And to complement my suggestion made, try this code in C++, you can already see how much easier it is :)

#include "opencv2/highgui/highgui.hpp" 
#include "stdio.h"

int main( int argc, char** argv ) { 
     cv::VideoCaptuee capture ( argv[1] );
     cv::Mat frame;
     for(;;) {
         capture >> frame;
         if( frame.empty() )  { 
             printf("EMPTY OR NULL");
             break;//ends HERE!!!!!
         }
         cv::imshow( "Example2", frame );  
         char c = cv::waitKey(33);
         if( c == 27 ) break;
    }    
}
edit flag offensive delete link more
0

answered 2013-12-12 02:27:37 -0600

your codes are correct. the only reason is you did not put the dll file of opencv_ffmpeg240.dll in your project.

edit flag offensive delete link more

Comments

If your opencv is built correctly and your dlls are where they are supposed to be, than your project will find the ffmpeg dll on its own... Placing dlls in the project specifically is not always a good idea...

StevenPuttemans gravatar imageStevenPuttemans ( 2013-12-12 06:07:23 -0600 )edit

thank you its only just right now work,, i was tried so much of codes but any of them is able to work and when i add this dll file all of them are works perfectly

agtw.07 gravatar imageagtw.07 ( 2017-02-05 19:01:29 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2013-08-16 02:29:50 -0600

Seen: 5,816 times

Last updated: Dec 12 '13