ビデオファイルのサムネイルを作成しようとしています。
- (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;
}
}
問題は、ビデオファイルがコンテンツアドレス可能なストアに保存されており、拡張子がないことです。AVURLAsset
アセットが作成されると、これはうまくいかないように見えますが、フレームイメージを読み取ると、次のエラーが発生します。
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}
これはどこかに文書化または言及されていますか?ファイル名を介してファイル形式情報を渡すことを本当に強制されているとは信じられません。イニシャライザへのoptions
引数AVURLAsset
はファイルタイプを提供するのに適した場所のように見えますが、ドキュメントによると、それをサポートしていないようです。
PS。コードをテストしましたが、正しい拡張子の同じファイルでサムネイルが正常に生成されます。