AVFoundation视频截图

//1. URL
    NSURL *url = [[NSBundle mainBundle] URLForResource:@"Cupid_高清.mp4" withExtension:nil];
    
    //2. 获取资源
    AVAsset *asset = [AVAsset assetWithURL:url];
    
    //3. 创建 资源图像生成器
    AVAssetImageGenerator *imageGenerator = [[AVAssetImageGenerator alloc] initWithAsset:asset];
    
    //4. 开始生成图像
    
    //Times : 用来表示影片的时间的值
    
    //value: 帧数
    //timescale: 当前视频的每秒的帧数
    
    CMTime time = CMTimeMake(60, 1);
    
    NSValue *value = [NSValue valueWithCMTime:time];
    
    [imageGenerator generateCGImagesAsynchronouslyForTimes:@[value] completionHandler:^(CMTime requestedTime, CGImageRef  _Nullable image, CMTime actualTime, AVAssetImageGeneratorResult result, NSError * _Nullable error) {
        
        //5. 主线程中更新UI
        dispatch_sync(dispatch_get_main_queue(), ^{
            self.imageView.image = [UIImage imageWithCGImage:image];
        });
        
    }];
```

你可能感兴趣的:(AVFoundation视频截图)