抓取.webm格式视频网址的第一帧

时间:2018-11-03 12:48:21

标签: ios objective-c avassetimagegenerator

我尝试使用下面的代码来获取视频的单帧,但由于不支持.webm格式而出现错误:NSLocalizedFailureReason=This media format is not supported

+(UIImage *)getFirstFrame:(NSURL *)videoURL {
    NSTimeInterval time = 1;
    AVURLAsset *asset = [[AVURLAsset alloc] initWithURL:videoURL options:nil];
    NSParameterAssert(asset);
    AVAssetImageGenerator *assetIG =
    [[AVAssetImageGenerator alloc] initWithAsset:asset];
    assetIG.appliesPreferredTrackTransform = YES;
    assetIG.apertureMode = AVAssetImageGeneratorApertureModeEncodedPixels;

    CGImageRef thumbnailImageRef = NULL;
    CFTimeInterval thumbnailImageTime = time;
    NSError *igError = nil;
    thumbnailImageRef = [assetIG copyCGImageAtTime:CMTimeMake(thumbnailImageTime, 60) actualTime:NULL error:&igError];

    if (!thumbnailImageRef)
        NSLog(@"thumbnailImageGenerationError %@", igError );

    UIImage *image = thumbnailImageRef
    ? [[UIImage alloc] initWithCGImage:thumbnailImageRef]
    : nil;

    return image;
}

是否有解决方法来获取.webm视频网址的第一帧?

0 个答案:

没有答案