I’m trying to create thumbnails for video files:
- (UIImage*) thumbnailForVideoAtURL: (NSURL*) videoURL
{
AVURLAsset *asset = [[AVURLAsset alloc] initWithURL:videoURL options:nil];
AVAssetImageGenerator *generator = [[AVAssetImageGenerator alloc] initWithAsset:asset];
CGImageRef imageHandle = [generator copyCGImageAtTime:kCMTimeZero actualTime:NULL error:NULL];
if (imageHandle) {
UIImage *frameImage = [UIImage imageWithCGImage:imageHandle];
CFRelease(imageHandle);
return frameImage;
} else {
return nil;
}
}
The catch is that the video files are stored in a content-addressable store and have no extensions. This appears to throw AVURLAsset
off, as the asset gets created, but upon reading the frame image I get the following error:
Error Domain=AVFoundationErrorDomain Code=-11828 "Cannot Open" UserInfo=0x167170 {NSLocalizedFailureReason=This media format is not supported., NSUnderlyingError=0x163a00 "The operation couldn’t be completed. (OSStatus error -12847.)", NSLocalizedDescription=Cannot Open}
Is this documented or mentioned somewhere? I can’t believe I’m really forced to pass the file format information through the file name. The options
argument to the AVURLAsset
initializer looks like a good place to supply the filetype, but according to the documentation there does not seem to be any support for that.
PS. I have tested the code, the same file with the correct extension produces the thumbnails just fine.