美文网首页
iOS获取视频封面 代码实现

iOS获取视频封面 代码实现

作者: 等不来的期待 | 来源:发表于2021-09-03 15:25 被阅读0次
//获取视频封面,本地视频,网络视频都可以用
- (UIImage*)thumbnailImageForVideo:(NSURL *)videoURL {

    AVURLAsset *asset = [[AVURLAsset alloc] initWithURL:videoURL options:nil];
    AVAssetImageGenerator *gen = [[AVAssetImageGenerator alloc]initWithAsset:asset];
    gen.appliesPreferredTrackTransform = YES;
    CMTime time = CMTimeMakeWithSeconds(2.0, 600);
    CMTime actualTime;
    CGImageRef image = [gen copyCGImageAtTime:time actualTime:&actualTime error:nil];
    UIImage *thumbImg = [[UIImage alloc] initWithCGImage:image];

    return thumbImg;

}

一个好用的图片浏览器支持图片和视频浏览:YBImageBrowser

相关文章

网友评论

      本文标题:iOS获取视频封面 代码实现

      本文链接:https://www.haomeiwen.com/subject/nojkwltx.html