ios 获取视频封面

  • 内容
  • 评论
  • 相关

//videoURL:本地视频路径    time:用来控制视频播放的时间点图片截取

-(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;

}

评论

0条评论

发表回复

您的电子邮箱地址不会被公开。 必填项已用 * 标注