现在的位置: 首页 > 综合 > 正文

截取视频缩略图

2018年05月25日 ⁄ 综合 ⁄ 共 815字 ⁄ 字号 评论关闭

UIImage *image =[self getImage:[[NSBundle mainBundle] pathForResource:@"video" ofType:@"mp4"]];


+(UIImage *)getImage:(NSString *)videoURL
{
    NSDictionary *opts = [NSDictionary dictionaryWithObject:[NSNumber numberWithBool:NO] forKey:AVURLAssetPreferPreciseDurationAndTimingKey];
    

    NSURL *url = [[[NSURL alloc] initFileURLWithPath:videoURL] autorelease];
    
    AVURLAsset *urlAsset = [AVURLAsset URLAssetWithURL:url options:opts];
    
    AVAssetImageGenerator *generator = [AVAssetImageGenerator assetImageGeneratorWithAsset:urlAsset];

    generator.appliesPreferredTrackTransform = YES;
    generator.maximumSize = CGSizeMake(600, 450);
    
    NSError *error = nil;
    CGImageRef img = [generator copyCGImageAtTime:CMTimeMake(10, 10) actualTime:NULL error:&error];
    UIImage *image = [UIImage imageWithCGImage: img];
    
    return image;
}

注意添加????AVFoundation框架

【上篇】
【下篇】

抱歉!评论已关闭.