Ask Your Question
0

Video propeties different.conflicting results

asked 2012-07-21 02:25:51 -0600

ararr gravatar image

updated 2012-07-21 04:03:59 -0600

hi I try to play a video file and I get mconfilctig results from the getPropery from VideoCapture Class.

from the get propety frame count in my video I get 31222 frames. But fromthe loop in main, mesauring the i variable I get that there are only 6063 frames? My fps is 30 frames per sec.

So which is right? Maybe the get property gets value from the video file without measuring but by checking the headers of the video? I don't know.Cannot understad why. Using OpenCV 2.4.1 and ubuntu

Update::even with the tree.avi video that comes with openCV source it gives different results. So it is not a problem of my video file..

code:

#include <stdio.h>
#include "cv.h"
#include "highgui.h"

int main( int argc, char** argv )
{
    double frameCount;
    IplImage  *frame;
    int       key;

    /* load the AVI file */
    CvCapture *capture = cvCaptureFromAVI( argv[1] );

    /* always check */
    if( !capture ) return 1;


    int i=0;

    /* display video */
    cvNamedWindow( "video", 0 );

    while( key != 'q' ) {
        /* get a frame */
        frame = cvQueryFrame( capture );
        if(!frame){printf("no frame or video finished");}
        i++;

        /* always check */
        if( !frame ) break;

        /* display frame */
        cvShowImage( "video", frame );

        /* quit if user press 'q' */
        key = cvWaitKey( 1);
    }
    frameCount=cvGetCaptureProperty(capture,CV_CAP_PROP_FRAME_COUNT);
    fps = ( int )cvGetCaptureProperty( capture, CV_CAP_PROP_FPS );
    printf("fps is %d frames per second\n",fps);
    printf("frame count as measured in for loop %d\n",i);
    printf("frame count as mesaured from property %f\n",frameCount);
    /* free memory */
    cvReleaseCapture( &capture );
    cvDestroyWindow( "video" );

    return 0;
}
edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
2

answered 2012-07-21 09:01:28 -0600

sammy gravatar image

updated 2012-07-21 09:04:25 -0600

Correct video properties are hard to assess - this is why OpenCV is struggling to offer a solid VideoCapture (CvCapture) object, but until now, it still have some inconsistencies.

What you can do is to install more codecs on your machine, or convert the avi file with a codec that works better on your installation (this is a trial and error process).

Another tip is to rely on parameters that measure the video properties in msecs, and not the COUNT, and FRAME_POS, because those are more buggy

Many others have similar problems, and here are some tips from them:

OpenCV captures only a fraction of the frames from a video file

Creating Video from Images with OpenCV 2.4.1 on Ubuntu

edit flag offensive delete link more

Comments

[ararr] thanks for the answer but in mt project I do not need the frame count.

I just need the actual frame timestamp.

the property CVCAPPROPPOS_MSEC is giving me wrong results, they are in accordance with the frame count as measured from inside the loop. For example,for my 17min video, the max value MSEC is giving me is 202 sec.

Is there a way to adjust this as reference to my actual video length?

I mean at MSEC 101sec how can I adjust it to give me 8.5 min?

Kirill Kornyakov gravatar imageKirill Kornyakov ( 2012-07-22 04:01:51 -0600 )edit

Question Tools

Stats

Asked: 2012-07-21 02:25:51 -0600

Seen: 523 times

Last updated: Jul 21 '12