iOS获取视频图片(视屏截图)

+(UIImage *)getImage:(NSString *)videoURL


{   

    //视频地址   

    NSURL *url = [[NSURL alloc] initWithString:videoURL];//initFileURLWithPath:videoURL];  

    AVURLAsset *urlAsset = [AVURLAsset URLAssetWithURL:url options:nil];//

    //获取视频时长,单位:秒

    NSLog(@"%llu",urlAsset.duration.value/urlAsset.duration.timescale);

    

    AVAssetImageGenerator *generator = [AVAssetImageGenerator assetImageGeneratorWithAsset:urlAsset];

    generator.appliesPreferredTrackTransform = YES

    generator.maximumSize = CGSizeMake(1136, 640);


    NSError *error = nil;   

    CGImageRef img = [generator copyCGImageAtTime:CMTimeMake(10, 10) actualTime:NULL error:&error]; 

    UIImage *image = [UIImage imageWithCGImage: img];

    

    return image;    

}


你可能感兴趣的:(ios,iOS获取视频图片,iOS视屏截图)