Skip to content

Instantly share code, notes, and snippets.

@zapsleep
Created December 7, 2012 13:40
Show Gist options
  • Save zapsleep/4233335 to your computer and use it in GitHub Desktop.
Save zapsleep/4233335 to your computer and use it in GitHub Desktop.
Getting a screenshot with AVAssetImageGenerator
- (UIImage *)screenshotFromFileURL:(NSURL *)url {
AVPlayerItem *item = [AVPlayerItem playerItemWithURL:url];
AVURLAsset *asset = (AVURLAsset *)item.asset;
AVAssetImageGenerator *imageGenerator = [[AVAssetImageGenerator alloc]
initWithAsset:asset];
CGImageRef thumb = [imageGenerator
copyCGImageAtTime:CMTimeMakeWithSeconds(10.0, 1.0)
actualTime:NULL
error:NULL];
UIImage *image = [UIImage imageWithCGImage:thumb];
return image;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment