【问题标题】:Load thumbnail image from video saved at NSDocumentDirectory从保存在 NSDocumentDirectory 的视频中加载缩略图
【发布时间】:2012-09-02 18:16:51
【问题描述】:

我使用以下代码从给定路径的视频中获取图像。

- (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;
    previewImage = thumbnailImage;

    return thumbnailImage;
}

但是,这不适用于保存在 NSDocumentDirectory 中的视频。我们不能使用 NSURL 访问 NSDocumentDIrectory 吗?如果没有其他选择。主要思想是显示保存在文档目录中的图像的缩略图,然后允许它上传到服务器。这也可以是一个临时目录。

【问题讨论】:

    标签: iphone ios4 avfoundation ios5 nsdocumentdirectory


    【解决方案1】:

    当你使用 NSURL *outputURL = [[NSURL alloc] initFileURLWithPath: path]; 时有效

    【讨论】:

      猜你喜欢
      • 2019-06-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-12-04
      • 1970-01-01
      • 2013-07-22
      • 1970-01-01
      相关资源
      最近更新 更多