美文网首页iOS开发资料收集区
iOS获取视频的第一帧图片

iOS获取视频的第一帧图片

作者: Appstore_花木源 | 来源:发表于2017-08-11 10:45 被阅读47次

    - (UIImage*) thumbnailImageForVideo:(NSURL *)videoURL atTime:(NSTimeInterval)time {

    AVURLAsset *asset = [[AVURLAsset alloc] initWithURL:videoURL options:nil];

    NSParameterAssert(asset);

    AVAssetImageGenerator *assetImageGenerator =[[AVAssetImageGenerator alloc] initWithAsset:asset];

    assetImageGenerator.appliesPreferredTrackTransform = YES;

    assetImageGenerator.apertureMode =AVAssetImageGeneratorApertureModeEncodedPixels;

    CGImageRef thumbnailImageRef = NULL;

    CFTimeInterval thumbnailImageTime = time;

    NSError *thumbnailImageGenerationError = nil;

    thumbnailImageRef = [assetImageGenerator copyCGImageAtTime:CMTimeMake(thumbnailImageTime, 60)actualTime:NULL error:&thumbnailImageGenerationError];

    if(!thumbnailImageRef)

    NSLog(@"thumbnailImageGenerationError %@",thumbnailImageGenerationError);

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

    return thumbnailImage;

    }

    相关文章

      网友评论

        本文标题:iOS获取视频的第一帧图片

        本文链接:https://www.haomeiwen.com/subject/akjlrxtx.html