Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>If you are working on OS X only I would stick with the QTKit APIs because they are much higher level and generally easier to work with.</p> <p>The general gist of what you want to do is:</p> <ol> <li>Step Through each frame in a movie</li> <li>Get a image representation for the current frame</li> <li>Save the current frame's image to a file on disk</li> </ol> <p>To step through the frames in a QuickTime movie, you can use the <a href="http://developer.apple.com/mac/library/documentation/QuickTime/Reference/QTKitFramework/Classes/QTMovie_Class/Reference/Reference.html" rel="nofollow noreferrer">QTMovie</a> class in QTKit to do this as follows:</p> <pre><code>- (void)dumpFramesWithMovie:(QTMovie*)movie toFolder:(NSString*)folderPath { [movie setIdling:NO]; // Don't idle the movie [movie gotoEnd]; QTTime endTime = [movie currentTime]; [movie gotoBeginning]; // Number of frames counted so far unsigned long numFrames = 0; // Turn off the Movie's looping so we are quaranteed to stop [movie setAttribute:[NSNumber numberWithBool:NO] forKey:QTMovieLoopsAttribute]; // Construct a Dictionary of to use when reading frames from a movie NSMutableDictionary *attributes = [NSMutableDictionary dictionary]; [attributes setObject:QTMovieFrameImageTypeNSImage forKey:QTMovieFrameImageType]; while (true) { QTTime curTime = [movie currentTime]; if (QTTimeCompare(curTime, endTime) == NSOrderedSame) { // Reached end of file break; } // Get the Current Frame as an NSImage NSImage* image = [movie frameImageAtTime:curTime withAttributes:attributes error:nil]; // Get the bitmap representation of this image // NOTE: This code assumes the first image representation is a NSBitmapImageRep, which is true // by default in OS X 10.5 and later. // Production code should do error checking here. NSBitmapImageRep *bitmap = [[image representations] objectAtIndex: 0]; // Construct a filename based upon the folder path and number of frames read so far NSString* fileName = [NSString stringWithFormat:@"%@/frame%d.png", folderPath, numFrames]; // Get an PNG representation of this file NSData *data = [bitmap representationUsingType: NSPNGFileType properties: nil]; // Write to disk [data writeToFile: fileName atomically: NO]; // Step to the next Frame [movie stepForward]; numFrames++; } [movie gotoBeginning]; } @end </code></pre> <p>This code compiles but has not been fully tested.</p> <p>One caveat with this approach is that MPEG-1 files will not decode properly on OS X 10.5 and earlier. This has been fixed as of 10.6 as far as I know. Also, if are writing a Windows application, you'll need to use the lower lever Quicktime-C APIs.</p> <p>Be sure to check the following reference pages while working on this:</p> <ul> <li><a href="http://developer.apple.com/mac/library/documentation/Cocoa/Conceptual/QTKitApplicationProgrammingGuide/Introduction/Introduction.html" rel="nofollow noreferrer">QTKit Application Programming Guide</a></li> <li><a href="http://developer.apple.com/mac/library/technotes/tn2005/tn2138.html#TNTAG11" rel="nofollow noreferrer">QTKit Frequently Asked Questions</a></li> <li><a href="http://developer.apple.com/mac/library/documentation/QuickTime/Reference/QTKitFramework/Classes/QTMovie_Class/Reference/Reference.html" rel="nofollow noreferrer">QTMovie Class Reference</a></li> <li><a href="http://borkware.com/quickies/one?topic=NSImage" rel="nofollow noreferrer">Quickies for NSImage</a></li> <li><a href="http://developer.apple.com/mac/library/documentation/cocoa/Reference/ApplicationKit/Classes/NSBitmapImageRep_Class/Reference/Reference.html" rel="nofollow noreferrer">NSBitmapImageRep Reference</a></li> <li><a href="http://developer.apple.com/mac/library/documentation/cocoa/Reference/ApplicationKit/Classes/NSImage_Class/Reference/Reference.html" rel="nofollow noreferrer">NSImage Reference</a></li> </ul>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload