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

Keyframes and AddMediaSample


Q: I'm generating QuickTime movie files from my own data and encountering problems when the movie controller is used to scrub my movie files. These movies seem to play fine unless they are started in the middle or if the movie controller is being moved back and forth. In this case, the picture falls apart until a key frame is processed. Is there a movie option I need to set when creating the movie or something that needs to be done when adding frames?

A: You need to set the flags correctly when adding media samples and be make sure to mark keyframes and difference frames.

With SCCompressSequenceFrame, you get a value called notSyncFlag back to tell you this information. This flag will be set to the mediaSampleNotSync constant for a difference frame, so you can pass it in the flags parameter to AddMediaSample.

When you compress video with CompressSequenceFrame you get a similarity parameter back. If this is non-zero, pass mediaSampleNotSync in the flags to AddMediaSample.

If you don't do this, all frames will be marked as keyframes, and QuickTime doesn't do the extra work to decompress preceding frames when your users scrub back and forth.

// Frame compress loop
for (frameNum = 0; frameNum < frameCount; frameNum++) {

  short notSyncFlag;

  .
  .
  .

  // Compress the frame
  SCCompressSequenceFrame(ci,              // compression seq ID
                          GetGWorldPixMap(srcGWorld),
                          &srcRect,
                          &compressedData, // handle to newly compressed data
                          &dataSize,       // size of compressed data
                          &notSyncFlag);   // key frame flag

  // Append the compressed image data to the media
  AddMediaSample(dstMedia,      // media specifier
       compressedData,          // sample data
       0,
       dataSize,                // size of sample data
       duration,
     (SampleDescriptionHandle)idh,
     1,                         // number of samples
     notSyncFlag,               // sync sample flags 1 = mediaSampleNotSync
     NULL);
  .
  .
  .
}

The above snippet from ConvertToMovie Jr. shows how this flag is returned and how it's passed to AddMediaSample; the full sample can be found at the following URL:

http://developer.apple.com/samplecode/Sample_Code/QuickTime/Importers_and_Exporters/ConvertToMovieJr.htm

[Dec 01 2000]


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.