您的位置:首页 > 理论基础 > 计算机网络

获取视频封面,本地视频,网络视频都可以用

2016-04-11 10:04 447 查看
/**

* 获取视频封面,本地视频,网络视频都可以用

*

* @param videoURL video的Url

*/

+ (void)thumbnailImageForVideo:(NSURL *)videoURL completion:(void(^)(UIImage *image))completion{

dispatch_async(dispatch_get_global_queue(0,
0), ^{

AVURLAsset *asset = [[AVURLAsset
alloc] initWithURL:videoURL
options:nil];

AVAssetImageGenerator *gen = [[AVAssetImageGenerator
alloc]
initWithAsset:asset];

gen.appliesPreferredTrackTransform =
YES;

CMTime time =
CMTimeMakeWithSeconds(2.0,
600);

NSError *error =
nil;

CMTime actualTime;

CGImageRef image = [gen
copyCGImageAtTime:time actualTime:&actualTime
error:&error];

UIImage *thumbImg = [[UIImage
alloc] initWithCGImage:image];

dispatch_async(dispatch_get_main_queue(), ^{

if (completion) {

completion(thumbImg);

}

});

});

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: