I have to extract a thumbnail from a video (from url) and I use this code:
NSString *stringUrl = video.stringurl;
NSURL *url = [NSURL URLWithString:stringUrl];
AVURLAsset *asset = [[AVURLAsset alloc] initWithURL:url options:nil];
AVAssetImageGenerator *imageGenerator = [[AVAssetImageGenerator alloc]initWithAsset:asset];
[imageGenerator setRequestedTimeToleranceBefore:kCMTimeZero];
[imageGenerator setRequestedTimeToleranceAfter:kCMTimeZero];
CGImageRef imageRef = [imageGenerator copyCGImageAtTime:playerCurrentTime actualTime:&actualtime error:&error];
UIImage *thumbnail = [UIImage imageWithCGImage:imageRef];
CGImageRelease(imageRef);
But sometime I have an error with copyCGImageAtTime and the thumbnail is not generated. The error is: Error save image Error Domain=AVFoundationErrorDomain Code=-11800 "The operation could not be completed"(OSStatus error -12792.)", NSLocalizedFailureReason=An unknown error occurred (-12792)}
Here is the link which I have read a solution but if a use fileURLWithPath: instead of URLWithString: the method add to the end of the url an "-- file://localhost/" that invalidates the url. So I don't know what I can do.