问题
I am trying to fetch the thumbnail of a video from URL. Sometimes it works fine and sometimes I do not get the image and get these 2 random errors, first is:
couldn't generate thumbnail, error:Error Domain=AVFoundationErrorDomain Code=-11800 "The operation could not be completed" UserInfo=0x175aa5f0 {NSLocalizedDescription=The operation could not be completed, NSUnderlyingError=0x1768e470 "The operation couldn’t be completed. (OSStatus error 268451843.)", NSLocalizedFailureReason=An unknown error occurred (268451843)}
and the second is:
couldn't generate thumbnail, error:Error Domain=AVFoundationErrorDomain Code=-11819 "Cannot Complete Action" UserInfo=0x14e46d20 {NSLocalizedRecoverySuggestion=Try again later., NSLocalizedDescription=Cannot Complete Action} 2015-09-06 17:29:18.936 myDemoThumbnailForVideo[2127:582934]
My code:
-(void)getImage
{
NSString *str=@"https://scontent.cdninstagram.com/hphotos-xfa1/t50.2886-16/11719145_918467924880620_816495633_n.mp4";
NSURL *url=[[NSURL alloc]initWithString:str];
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 im, CMTime actualTime, AVAssetImageGeneratorResult result, NSError *error){
if (result != AVAssetImageGeneratorSucceeded) {
NSLog(@"couldn't generate thumbnail, error:%@", error);
}
[_imageView setImage:[UIImage imageWithCGImage:im ]];
}
来源:https://stackoverflow.com/questions/32423062/avassetimagegenerator-not-working-properly-i-am-unable-to-fetch-thumbnail-of-vi