Reputation: 12896
This is a code snippet from O'Reilly Learning Opencv,
cvNamedWindow("Example3", CV_WINDOW_AUTOSIZE);
g_capture = cvCreateFileCapture(argv[1]);
int frames = (int) cvGetCaptureProperty(g_capture, CV_CAP_PROP_FRAME_COUNT);
if (frames != 0) {
cvCreateTrackbar("Position", "Example3", &g_slider_postion, frames, onTrackbarSlide);
}
But unfortunately, cvGetCaptureProperty always return 0. I have searched opencv group in Yahoo, found the same problem.
Upvotes: 3
Views: 8339
Reputation: 3993
Worse is I didn't have this problem on Windows 7, and then a few days later I did, with the same video file. No rhyme or reason.
Upvotes: 0
Reputation: 61
I don't seem to have this problem in the linux version (the one installed after doing a ROS installation), but I keep running into it on OSX. I thought it had to do with the OpenCV version I was using (I installed the linux one rather recently) so I installed OpenCV 2.2 on my mac, but the problem persists.
Does anyone know if this has been corrected completely on the latest version of the repository?
Upvotes: 0
Reputation: 11
I had the same problem. It says it would work on Windows but it does not. I guess it is because I use Dev-C++ and Dev-C++ uses gcc. Though I'm not sure if that is the reason.
Upvotes: 1
Reputation: 12896
Oh, I get it. I have found these code snippet in the Learning OpenCV's samples codes:
/*
OK, you caught us. Video playback under linux is still just bad. Part of this is due to FFMPEG, part of this
is due to lack of standards in video files. But the position slider here will often not work. We tried to at least
find number of frames using the "getAVIFrames" hack below. Terrible. But, this file shows something of how to
put a slider up and play with it. Sorry.
*/
//Hack because sometimes the number of frames in a video is not accessible.
//Probably delete this on Widows
int getAVIFrames(char * fname) {
char tempSize[4];
// Trying to open the video file
ifstream videoFile( fname , ios::in | ios::binary );
// Checking the availablity of the file
if ( !videoFile ) {
cout << "Couldn’t open the input file " << fname << endl;
exit( 1 );
}
// get the number of frames
videoFile.seekg( 0x30 , ios::beg );
videoFile.read( tempSize , 4 );
int frames = (unsigned char ) tempSize[0] + 0x100*(unsigned char ) tempSize[1] + 0x10000*(unsigned char ) tempSize[2] + 0x1000000*(unsigned char ) tempSize[3];
videoFile.close( );
return frames;
}
Upvotes: 4