title: Media Foundation get exact frame ( sample ) count of video file
body: <p>I have a video file and I have successfully extracted the average frameRate and duration:</p>
  
  <pre><code>UINT64 frameRate = 0;
  mediaType-&gt;GetUINT64(MF_MT_FRAME_RATE, &amp;frameRate)
  
  PROPVARIANT prop;
  m_pReader-&gt;GetPresentationAttribute(MF_SOURCE_READER_MEDIASOURCE,
      MF_PD_DURATION, &amp;prop);
  double duration = prop.hVal.QuadPart / 1e7;
  </code></pre>
  
  <p>Now I am simply calculating the number of frames:
     <code>frameCount = duration*frameRate</code></p>
  
  <p>And I compare it with the actual number of samples by iterating over them:</p>
  
  <pre><code>realFrameCount = 0;
  while(true)
  {
      m_pReader-&gt;ReadSample(
              MF_SOURCE_READER_FIRST_VIDEO_STREAM,
              0, &amp;streamIndex, index.  &amp;flags, &amp;llTimeStamp, &amp;videoSample);
  
          if (flags &amp; MF_SOURCE_READERF_ENDOFSTREAM)
              break;
  
      realFrameCount++;
  }
  </code></pre>
  
  <p>In some cases, I get an exact match, but for some files, I do get it within a small difference.</p>
  
  <p>My question is:
  Is there a way to get exact number of frames without iterating over all samples?</p>
  
  <p>Thanks</p>