我试过同步这样做:
AVURLAsset *as = [[AVURLAsset alloc] initWithURL:url options:nil];
AVAssetImageGenerator *ima = [[AVAssetImageGenerator alloc] initWithAsset:as];
NSError *err = NULL;
CMTime time = CMTimeMake(0, 30);
CGImageRef imgRef = [ima copyCGImageAtTime:time actualTime:NULL error:&err];
UIImage *currentImg = [[UIImage alloc] initWithCGImage:imgRef];
callback(currentImg, err);
异步:
AVURLAsset *asset=[[AVURLAsset alloc] initWithURL:url options:nil];
AVAssetImageGenerator *generator = [[AVAssetImageGenerator alloc] initWithAsset:asset];
generator.appliesPreferredTrackTransform=TRUE;
CMTime thumbTime = CMTimeMakeWithSeconds(0,30);
AVAssetImageGeneratorCompletionHandler handler = ^(CMTime requestedTime, CGImageRef imgRef, CMTime actualTime, AVAssetImageGeneratorResult result, NSError *error){
if (result != AVAssetImageGeneratorSucceeded) {
NSLog(@"couldn't generate thumbnail, error:%@", error);
callback(nil, error);
}
UIImage *thumbnail = [UIImage imageWithCGImage:imgRef];
callback(thumbnail, nil);
};
CGSize maxSize = CGSizeMake(128, 128);
generator.maximumSize = maxSize;
[generator generateCGImagesAsynchronouslyForTimes:[NSArray arrayWithObject:[NSValue valueWithCMTime:thumbTime]] completionHandler:handler];
无论哪种方式,我都会获得AVFoundationErrorDomain Code=-11800
- NSLocalizedFailureReason=An unknown error occurred
和无图像。
知道我做错了吗?
修改
这是我刚试过的第三个选项,但结果错误相同:
NSDictionary *options = @{ AVURLAssetPreferPreciseDurationAndTimingKey : @NO };
AVURLAsset *asset = [[AVURLAsset alloc] initWithURL:url options:options];
NSArray *keys = [NSArray arrayWithObject:@"readable"];
[asset loadValuesAsynchronouslyForKeys:keys completionHandler:^() {
AVAssetImageGenerator *generate = [[AVAssetImageGenerator alloc] initWithAsset:asset];
NSError *err = NULL;
CMTime time = CMTimeMake(1, 30);
CGImageRef imgRef = [generate copyCGImageAtTime:time actualTime:NULL error:&err];
UIImage *thumbnail = [UIImage imageWithCGImage:imgRef];
dispatch_async(dispatch_get_main_queue(), ^{
callback(thumbnail, err);
});
}];
答案 0 :(得分:0)
处理-11800错误代码未知错误很难。
当您收到此错误代码时,通常会在其中一个日志中记录与您的应用程序关联的OSStatus代码值。 OSStatus代码将提供有关出错的有用指南。
然而,找出OSStatus代码的含义可能很困难。我现在转到我正在构建的SDK并使用以下方法搜索frameworks文件夹:
find . -name "*.h" -exec grep -H "statuscode" {} \;
其中statuscode是找到的数值。
追踪这些额外的信息值得花时间,因为它确实有助于确定问题的原因。