Skip to content

Instantly share code, notes, and snippets.

@nonstriater
Created May 4, 2014 06:12
Show Gist options
  • Save nonstriater/222014229a113c2c2df8 to your computer and use it in GitHub Desktop.
Save nonstriater/222014229a113c2c2df8 to your computer and use it in GitHub Desktop.
从视频文件中获得一张图片(截图)
从视频文件中获得一张图片(截图)
AVURLAsset *asset = [[AVURLAsset alloc] initWithURL:url options:nil];
AVAssetImageGenerator *gen = [[AVAssetImageGenerator alloc] initWithAsset:asset];
gen.appliesPreferredTrackTransform = YES;
CMTime time = CMTimeMakeWithSeconds(0.0, 600);
NSError *error = nil;
CMTime actualTime;
CGImageRef image = [gen copyCGImageAtTime:time actualTime:&actualTime error:&error];
UIImage *img = [[UIImage alloc] initWithCGImage:image];
CGImageRelease(image);
[self performSelector:@selector(saveImg:) withObject:img afterDelay:0.1];
[img release];
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment