2012-09-09 83 views
0

我使用以下代码从给定路径的视频获取图像。加载保存在NSDocumentDirectory的视频的缩略图图像

- (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?如果没有其他选择。主要想法是显示保存在文档目录中的图像的缩略图,然后允许它上传到服务器。这也可以是临时目录。

回答

0

当您使用NSURL * outputURL = [[NSURL alloc] initFileURLWithPath:path]时工作;