iphone - 生成视频缩略图时出错

标签 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}

谁能告诉我这是什么类型的错误?

最佳答案

如果您使用捆绑的视频文件,请按照之前的帖子:AVURLAsset refuses to load video

这是一个非常重要的案例。

关于iphone - 生成视频缩略图时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8089972/

相关文章:

xcode - NSOpenPanel在选择文件时崩溃

iphone - 更改 xib 时 iPhone 上的 SIGABRT

iphone - 核心图像过滤器应用

iphone - NSString 到 NSNumber : what am I doing wrong here?

应用程序运行时, Storyboard中设置的 iOS UITableView 行高加倍

ios - 如何限制 UISearchBar 中的输入?

iphone - UIView 调整大小和平移动画不能正确地为 subview 设置动画

iphone - 在 objective-c 中使用 BOOL 变量时发出警告

ios - 实现类似 WWDC 2012 应用程序的事件 map

ios - 将 View 拆分为四个宽度为 25% 的 subview