Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Late last night I had an Idea and sure enough it worked this morning. Essentially I just create a new Composition Asset and then create a time range that represents one frame for Video at 24 frames per second. Once I have these compositions created, I just grab the first frame of each comp. I do this for each frame and create an array holding all my frames. Here is what I did..</p> <pre><code>NSString *path = [NSHomeDirectory() stringByAppendingPathComponent:[NSString stringWithFormat:@"Documents/videoTest4.m4v"]]; //UISaveVideoAtPathToSavedPhotosAlbum(path, self, @selector(video:didFinishSavingWithError:contextInfo:), nil); NSURL *url = [NSURL fileURLWithPath:path]; NSDictionary *options = [NSDictionary dictionaryWithObject:[NSNumber numberWithBool:YES] forKey:AVURLAssetPreferPreciseDurationAndTimingKey]; AVURLAsset *asset = [[AVURLAsset alloc] initWithURL:url options:options]; Float64 durationFrames = CMTimeGetSeconds([asset duration]) * 24.0; AVMutableComposition *myComp = [AVMutableComposition composition]; AVMutableCompositionTrack *compositionVideoTrack = [myComp addMutableTrackWithMediaType:AVMediaTypeVideo preferredTrackID:kCMPersistentTrackID_Invalid]; NSError *error = nil; BOOL ok = NO; NSMutableArray* frameArray = [[NSMutableArray alloc] init]; generate = [[AVAssetImageGenerator alloc] initWithAsset:myComp]; NSError *err = nil; for (int i = 0; i &lt; floor(durationFrames); i++) { CMTime startTime = CMTimeMake(i, 24); CMTime endTime = CMTimeMake(i+1, 24); CMTimeRange myRange = CMTimeRangeMake(startTime, endTime); AVAssetTrack *sourceVideoTrack = [[asset tracksWithMediaType:AVMediaTypeVideo] objectAtIndex:0]; ok = [compositionVideoTrack insertTimeRange:myRange ofTrack:sourceVideoTrack atTime:kCMTimeZero error:&amp;error]; if (!ok) { // Deal with the error. } time = CMTimeMake(0,1); CGImageRef imgRef = [generate copyCGImageAtTime:time actualTime:&amp;actualTime error:&amp;err]; UIImage *currentImg = [[UIImage alloc] initWithCGImage:imgRef]; [frameArray addObject:currentImg]; [currentImg release]; } NSLog(@"This video is calculated at %f Frames..",durationFrames); NSLog(@"You made a total of %i Frames!!",[frameArray count]); </code></pre> <p>Then The Console Reads..</p> <p>2011-04-29 10:42:24.292 videoTest[29019:207] This video is calculated at 45.120000 Frames..</p> <p>2011-04-29 10:42:24.293 videoTest[29019:207] You made a total of 45 Frames!!</p>
 

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