生成视频缩略图时出错

时间:2011-11-11 05:13:48

标签: iphone objective-c xcode

以下是我生成视频缩略图的代码:

           NSString *getUrl = [[NSUserDefaults standardUserDefaults] valueForKey:@"newpath"];
NSLog(@"getURL=%@",getUrl);
NSLog(@"newpath for url=%@",newPath);
NSURL *url = [NSURL URLWithString:getUrl];
AVURLAsset *asset=[[AVURLAsset alloc] initWithURL:url options:nil];
AVAssetImageGenerator *generator = [[AVAssetImageGenerator alloc] initWithAsset:asset];
generator.appliesPreferredTrackTransform=TRUE;
[asset release];
CMTime thumbTime = CMTimeMakeWithSeconds(0,30);

AVAssetImageGeneratorCompletionHandler handler = ^(CMTime requestedTime, CGImageRef im, CMTime actualTime, AVAssetImageGeneratorResult result, NSError *error){
    if (result != AVAssetImageGeneratorSucceeded) {
        NSLog(@"couldn't generate thumbnail, error:%@", error);
    }
    [btnVideo setImage:[UIImage imageWithCGImage:im] forState:UIControlStateNormal];
   // thumbImg=[[UIImage imageWithCGImage:im] retain];
    [generator release];
};

CGSize maxSize = CGSizeMake(320, 180);
generator.maximumSize = maxSize;
[generator generateCGImagesAsynchronouslyForTimes:[NSArray arrayWithObject:[NSValue valueWithCMTime:thumbTime]] completionHandler:handler];

当我使用此代码时,它会出现以下错误:

   couldn't generate thumbnail, error:Error Domain=AVFoundationErrorDomain Code=-11800 "The operation could not be completed" UserInfo=0x5bbbb0 {NSLocalizedFailureReason=An unknown error occurred (-12935), NSUnderlyingError=0x59ae40 "The operation couldn’t be completed. (OSStatus error -12935.)", NSLocalizedDescription=The operation could not be completed}

有谁能告诉我这是什么错误?

1 个答案:

答案 0 :(得分:5)

如果您使用的是捆绑的视频文件,请按照上一篇文章:AVURLAsset refuses to load video

这是非常重要的案例。