如何生成视频缩略图iOS而无需网络调用服务器?

时间:2015-08-25 11:54:07

标签: ios objective-c

我想要的是,当用户从图库中选择视频时,我想获取视频的缩略图。那么是否可以获取视频的缩略图而无需将其上传到服务器?

1 个答案:

答案 0 :(得分:0)

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
    NSURL *urlvideo = [info objectForKey:UIImagePickerControllerMediaURL];
    __block NSData *movieData = [[NSData alloc]initWithContentsOfURL:urlvideo];AVURLAsset *asset=[[AVURLAsset alloc] initWithURL:urlvideo options:nil];
    AVAssetImageGenerator *generator = [[AVAssetImageGenerator alloc] initWithAsset:asset];
    generator.appliesPreferredTrackTransform=TRUE;


    CMTime thumbTime = CMTimeMakeWithSeconds(0,30);

    AVAssetImageGeneratorCompletionHandler handler = ^(CMTime requestedTime, CGImageRef im, CMTime actualTime, AVAssetImageGeneratorResult result, NSError *error){
        if (result != AVAssetImageGeneratorSucceeded) {
            NSLog(@"couldn't generate thumbnail, error:%@", error);
        }

        UIImage *img = [UIImage imageWithCGImage:im];
    };
}