标签:
///视频取帧
- (UIImage*) thumbnailImageForVideo:(NSURL *)videoURL atTime:(NSTimeInterval)time {
AVURLAsset *asset = [[AVURLAsset alloc] initWithURL:videoURL options:nil] ;
NSParameterAssert(asset);
AVAssetImageGenerator *assetImageGenerator = [[AVAssetImageGenerator alloc] initWithAsset:asset];
assetImageGenerator.appliesPreferredTrackTransform = YES;
assetImageGenerator.apertureMode = AVAssetImageGeneratorApertureModeEncodedPixels;
//取帧
CGImageRef thumbTemp = NULL;
CMTime actualTime ;
// int32_t time = asset.duration.timescale;
NSError *error = nil;
thumbTemp = [assetImageGenerator copyCGImageAtTime:CMTimeMake(time, asset.duration.timescale) actualTime:&actualTime error:&error];
NSLog(@"%lld",actualTime.value);
UIImage *thumb = nil;
if (!error)
{
thumb = [[UIImage alloc] initWithCGImage:thumbTemp];
}
CGImageRelease(thumbTemp);
return thumb;
}
标签:
原文地址:http://www.cnblogs.com/xia0huihui/p/5430806.html