3

I am using QTMovie with QTMovieOpenForPlaybackAttribute:YES, and using a QTMovieView to display it. I need to calculate the framerate it is achieving.

One way I can think of doing this is to have a callback which is called every time a frame is about to display or is ready to be displayed - is anyone familiar with such a callback?

Another way would be to have a timer which uses -currentFrameImage and compares it with the last frame image it tested - however firstly I don't know how you would go about comparing two NSImages, and secondly I would imagine this would be problematic if two sequential frames were the same, it would effectively assume a frame was dropped when it was not

The last way I can think of would be to again use a timer, this time to call -currentTime. I have tried this, however, for some reason, the timeScale is set to 1000000000. I read that the time scale is supposed to be 100*fps, so, why is currentTime returning that the FPS is 10000000? This seems completely incorrect. There are no flags set in the QTTime returned.

I have searched everywhere for information on this - any searches to do with frame rate only lead me to how to set a frame rate on capture which is not what I am looking for.

Richard Slater
  • 6,313
  • 4
  • 53
  • 81
BenC
  • 31
  • 3
  • Time scale is not always 100*fps; it can be anything sufficiently large to give the accuracy needed to represent the frame rate. – koan May 30 '12 at 16:36

1 Answers1

3

Try this:

- (double)frameRate
{
    double result = 0;

    for (QTTrack* track in [_movie tracks])
    {
        QTMedia* trackMedia = [track media];

        if ([trackMedia hasCharacteristic:QTMediaCharacteristicHasVideoFrameRate])
        {
            QTTime mediaDuration = [(NSValue*)[trackMedia attributeForKey:QTMediaDurationAttribute] QTTimeValue];
            long long mediaDurationScaleValue = mediaDuration.timeScale;
            long mediaDurationTimeValue = mediaDuration.timeValue;
            long mediaSampleCount = [(NSNumber*)[trackMedia attributeForKey:QTMediaSampleCountAttribute] longValue];
            result = (double)mediaSampleCount * ((double)mediaDurationScaleValue / (double)mediaDurationTimeValue);
            break;
        }
    }
    return result;
}
Davyd Geyl
  • 4,578
  • 1
  • 28
  • 35