2012-09-09 81 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]時工作;