Ios 为.mov文件目标C生成视频缩略图
我正在尝试生成缩略图并将其保存到文件中。这是我的密码Ios 为.mov文件目标C生成视频缩略图,ios,objective-c,Ios,Objective C,我正在尝试生成缩略图并将其保存到文件中。这是我的密码 AVURLAsset *asset = [[AVURLAsset alloc] initWithURL:object[@"path"] options:nil]; AVAssetImageGenerator *generator = [[AVAssetImageGenerator alloc] initWithAsset:asset]; NSError *err = NULL; CMTime reques
AVURLAsset *asset = [[AVURLAsset alloc] initWithURL:object[@"path"] options:nil];
AVAssetImageGenerator *generator = [[AVAssetImageGenerator alloc] initWithAsset:asset];
NSError *err = NULL;
CMTime requestedTime = CMTimeMake(1, 60); // To create thumbnail image
CGImageRef imgRef = [generator copyCGImageAtTime:requestedTime actualTime:NULL error:&err];
NSLog(@"err = %@, imageRef = %@", err, imgRef);
UIImage *thumbnailImage = [[UIImage alloc] initWithCGImage:imgRef];
CGImageRelease(imgRef);
NSString* path = [NSHomeDirectory() stringByAppendingString:@"/Documents/myImage.png"];
BOOL ok = [[NSFileManager defaultManager] createFileAtPath:path
contents:nil attributes:nil];
if (!ok)
{
NSLog(@"Error creating file %@", path);
}
else
{
NSFileHandle* myFileHandle = [NSFileHandle fileHandleForWritingAtPath:path];
[myFileHandle writeData:UIImagePNGRepresentation(thumbnailImage)];
[myFileHandle closeFile];
resolve(path);
}
但我得到了一个错误:
Code=-11822 "Cannot Open" UserInfo={NSLocalizedDescription=Cannot Open, NSLocalizedFailureReason=This media format is not supported.}
有什么想法吗 哪一行导致了错误?仅供参考-用于构建文档文件夹路径的代码错误。而且你编写文件的代码比它需要的要困难得多。不,确实是代码,它工作得很好:)。我发送到生成器的URL有问题。在哪一行抛出错误?