iOS - How to get thumbnail from video without play?

后端 未结 8 1144
鱼传尺愫
鱼传尺愫 2020-12-16 00:36

I\'m trying to get thumbnail from video and show it in my tableview. Here is my code:

- (UIImage *)imageFromVideoURL:(NSURL *)contentURL {
    AVAsset *asse         


        
8条回答
  •  不知归路
    2020-12-16 00:52

    Just use this code.. Pass your video URL and get an image.

    +(UIImage *)getPlaceholderImageFromVideo:(NSString *)videoURL {
        NSURL *url = [NSURL URLWithString:videoURL];
        AVAsset *asset = [AVAsset assetWithURL:url];
        AVAssetImageGenerator *imageGenerator = [[AVAssetImageGenerator alloc] initWithAsset:asset];
        CMTime time = [asset duration];
        time.value = 0;
        CGImageRef imageRef = [imageGenerator copyCGImageAtTime:time actualTime:NULL error:NULL];
        UIImage *thumbnail = [UIImage imageWithCGImage:imageRef];
        CGImageRelease(imageRef);
        return thumbnail;
    }
    

    Hope, this is what you're looking for. Any concern get back to me. :)

提交回复
热议问题