title: OpenCV doesn't report accurate frame rate/count
body: <p>I have a 33 second video that I'm trying to process with OpenCV.  My goal is to determine what instance in time (relative to the start of the video) each frame corresponds to.  I'm doing this in order to be able to compare frames from videos of the same scene that have been recorded at different frame rates.</p>
  
  <p>What's working:</p>
  
  <ul>
  <li>The FPS is correctly reported as 59.75.  This is consistent with what <code>ffprobe</code> reports, so I'm happy to believe that's correct.</li>
  </ul>
  
  <p>The problems I'm having are:</p>
  
  <ul>
  <li><code>CAP_PROP_POS_MSEC</code> returns incorrect values.  By the end of the video, it's up to 557924ms (over 9 min).  For a 33s video, this can't be right.</li>
  <li><code>CAP_PROP_FRAME_COUNT</code> is also incorrect.  It's reported as 33371, which at 59.75 fps would give over 9 minutes worth of footage.  Consistent with the above error, but still incorrect.</li>
  <li><code>CAP_PROP_POS_FRAME</code> is similarly incorrect.</li>
  </ul>
  
  <p>The video can be found <a href="http://dl.dropbox.com/u/15815235/sequence.mp4" rel="noreferrer">here</a> (approx. 10MB). </p>
  
  <p>Any ideas on what could be wrong?</p>
  
  <p><code>ffprobe</code> output:</p>
  
  <pre><code>FFprobe version SVN-r20090707, Copyright (c) 2007-2009 Stefano Sabatini
    libavutil     49.15. 0 / 49.15. 0
    libavcodec    52.20. 0 / 52.20. 1
    libavformat   52.31. 0 / 52.31. 0
    built on Jan 20 2010 00:13:01, gcc: 4.4.3 20100116 (prerelease)
  Input #0, mov,mp4,m4a,3gp,3g2,mj2, from '/home/misha/Dropbox/Public/sequence.mp4':
    Duration: 00:00:33.37, start: 0.000000, bitrate: 2760 kb/s
      Stream #0.0(und): Video: h264, yuv420p, 1920x1080, 59.75 tbr, 1k tbn, 2k tbc
      Stream #0.1(und): Audio: aac, 44100 Hz, stereo, s16
  </code></pre>
  
  <p>Full code:</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;assert.h&gt;
  
  #include &lt;cv.h&gt;    
  #include &lt;highgui.h&gt;
  
  #include &lt;cmath&gt;
  #include &lt;iostream&gt;
  #include &lt;string.h&gt;
  #include &lt;stdio.h&gt;
  
  extern "C"
  {
  #include "options.h"
  }
  
  using namespace std;
  
  #define DEBUG 0
  
  static void
  print_usage(char *argv0)
  {
      cerr &lt;&lt; "usage: " &lt;&lt; argv0 &lt;&lt; " video.avi [options]" &lt;&lt; endl;
  }
  
  int main(int argc, char** argv)
  {
      if (argc &lt; 2)
      {
          print_usage(argv[0]);
          return -1;
      }
  
      int           step      = 30;
      struct Option options[] =
      {
          { "step",        1, &amp;step },
          { NULL,          0, NULL }
      };
  
      int ret = parse_options(2, argc, argv, options);
      if (ret == 0)
      {
          print_usage(argv[0]);
          return -1;
      }
  
      CvCapture *capture = cvCaptureFromFile(argv[1]);
      int counter = 0;
      while (cvGrabFrame(capture))
      {
          ++counter;
  
          IplImage *frame = cvRetrieveFrame(capture);
          double millis   = cvGetCaptureProperty(capture, CV_CAP_PROP_POS_MSEC);
          double current  = cvGetCaptureProperty(capture, CV_CAP_PROP_POS_FRAMES);
          double total    = cvGetCaptureProperty(capture, CV_CAP_PROP_FRAME_COUNT);
          printf("%d %d/%d %f\n", counter, (int)current, (int)total, millis);
          int min = (int)(millis/1000/60);
          millis -= min*60000;
          int sec = (int)(millis/1000);
          millis -= sec*1000;
  
          printf("%d %02d:%02d:%f\n", counter, min, sec, millis);
      }
      cvReleaseCapture(&amp;capture);
  
      return 0;
  }
  </code></pre>