ADC Home > Reference Library > Technical Q&As > QuickTime > Movie Basics >

How to Compute Data Rate for QuickTime Movies

Q How do I compute the data rate for QuickTime movies? Is this rate stored somewhere in the QuickTime movie?

A QuickTime is a time-based sample media. In other words, various samples are organized on a track and are played using a uniform time clock. Typically, in the case of video, one sample equals one frame; in the case of sound and other media, this 1:1 relationship does not necessarily hold. Additionally, none of the video samples in a continuous stream are exactly the same size, even if in practical terms this is often assumed.

QuickTime always tries to synchronize video and sound. If the CPU does not have enough cycles to play back samples, the video samples are sacrificed for a period, and, in the worst case, sound samples may also be skipped to the next anchor point (a key frame).

There are two aspects to measuring the rate of samples, one based on a static estimation of the duration of the movie and the amount of video samples (frames), and the other based on when the movie is played back.

In the first case, you can make a quick estimate by assuming that all video samples are of equal duration, then taking the duration of the movie and dividing it by the duration of the first sample, yielding the number of video samples present per one second unit.

Here's a code snippet showing this technique:

framecount = GetMovieDuration(theMovie)/GetDurationofFirstMovieSample(theMovie,
VideoMediaType);

pascal TimeValue GetDurationOfFirstMovieSample(Movie theMovie, OSType theMediaType)
{
    OSErr             anErr = noErr;
    TimeValue        interestingDuration = 0;
    short            timeFlags = nextTimeMediaSample+nextTimeEdgeOK;

    GetMovieNextInterestingTime(theMovie, timeFlags, (TimeValue)1, &theMediaType,
    0, fixed1, NULL, &interestingDuration);
    anErr = GetMoviesError(); DebugAssert(anErr == noErr);

    return interestingDuration;
}

If you want the exact number of frames, you need to parse each one using GetMovieNextInterestingTime (or any of its variants), find out the duration of each sample and its starting point, and use this information to calculate the frame rate.

Note that when you digitize, and you specify the frame rate, you will most likely create similarly-sized video samples.

In the second case, to create a dynamic testing of frames displayed, install a MovieDrawingCompleteProc that is triggered every time a frame is drawn. In this way you can keep a counter of how many frames are drawn per time unit. Note that if end user information is drawn too often, the results will be skewed. Refer to Technote QT 04 for more information about how to install a MovieDrawingCompleteProc.

[Sep 15 1995]


Did this document help you?
Yes: Tell us what works for you.
It’s good, but: Report typos, inaccuracies, and so forth.
It wasn’t helpful: Tell us what would have helped.