iOS - How to get thumbnail from video without play?

后端 未结 8 1136
鱼传尺愫
鱼传尺愫 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:50

    //(Local URL)
    NSURL *videoURL = [NSURL fileURLWithPath:filepath];// filepath is your video file path 
    
    
    
    AVURLAsset *asset = [[AVURLAsset alloc] initWithURL:videoURL options:nil];
    AVAssetImageGenerator *generateImg = [[AVAssetImageGenerator alloc] initWithAsset:asset];
    NSError *error = NULL;
    CMTime time = CMTimeMake(1, 1);
    CGImageRef refImg = [generateImg copyCGImageAtTime:time actualTime:NULL error:&error];
    NSLog(@"error==%@, Refimage==%@", error, refImg);
    
    UIImage *frameImage= [[UIImage alloc] initWithCGImage:refImg];
    return frameImage;
    

提交回复
热议问题