Skip to content

Instantly share code, notes, and snippets.

@Air-Craft
Created August 14, 2014 14:02
Show Gist options
  • Save Air-Craft/0e7d037e169247d0020d to your computer and use it in GitHub Desktop.
Save Air-Craft/0e7d037e169247d0020d to your computer and use it in GitHub Desktop.
Grab a snapshot from a video file i#iOS #video #images #snapshot #AVFoundation #intermediate
AVURLAsset *asset = [[AVURLAsset alloc] initWithURL:self.recordedVideoFileURL options:nil];
AVAssetImageGenerator *gen = [[AVAssetImageGenerator alloc] initWithAsset:asset];
gen.appliesPreferredTrackTransform = YES;
NSError *err = NULL;
CMTime cmTime = CMTimeMake(time, 1);
CGImageRef imgRef = [gen copyCGImageAtTime:cmTime actualTime:NULL error:&err];
UIImage *img = [[UIImage alloc] initWithCGImage:imgRef];
return img;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment