gpt4 book ai didi

ios - 试图获取视频缩略图

转载 作者:可可西里 更新时间:2023-11-01 06:19:43 44 4
gpt4 key购买 nike

我正在尝试从保存在 Documents/文件夹中的视频中获取视频缩略图,并将其显示在 UITableViewCell 内的 UIImageView 中。这是我获取缩略图的函数:

- (UIImage*) thumbnailImageForVideo:(NSURL *)sourceURL
{
AVAsset *asset = [AVAsset assetWithURL:sourceURL];
AVAssetImageGenerator *imageGenerator = [[AVAssetImageGenerator alloc]initWithAsset:asset];
NSError *err = NULL;
CMTime time = CMTimeMake(1, 1);
CGImageRef imageRef = [imageGenerator copyCGImageAtTime:time actualTime:NULL error:&err];
NSLog(@"err==%@, imageRef==%@", err, imageRef);
UIImage *thumbnail = [[UIImage alloc] initWithCGImage:imageRef];
CGImageRelease(imageRef); // CGImageRef won't be released by ARC
return thumbnail;
}

这里是我使用它的地方:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
LibraryCell *libraryCell = [tableView dequeueReusableCellWithIdentifier:@"LibraryCell" forIndexPath:indexPath];

NSString *videoPath = [NSString stringWithFormat:@"%@/%@", [NSHomeDirectory() stringByAppendingPathComponent:@"Documents"], [libraryFiles objectAtIndex:indexPath.item]];
libraryCell.itemImage.image = [self thumbnailImageForVideo:[NSURL URLWithString:videoPath]];

return libraryCell;
}

应用程序没有崩溃,但没有图像。这是我在控制台中看到的:

2013-04-13 23:44:46.828 GeekOut[14433:907] err==Error Domain=NSURLErrorDomain Code=-1 "unknown error" UserInfo=0x1f0b4610 {NSUnderlyingError=0x1f0b3220 "The operation couldn’t be completed. (OSStatus error -12935.)", NSLocalizedDescription=unknown error}, imageRef==(null)
2013-04-13 23:44:46.859 GeekOut[14433:907] err==Error Domain=NSURLErrorDomain Code=-1 "unknown error" UserInfo=0x1dd8c660 {NSUnderlyingError=0x1dd8c5c0 "The operation couldn’t be completed. (OSStatus error -12935.)", NSLocalizedDescription=unknown error}, imageRef==(null)
2013-04-13 23:44:46.893 GeekOut[14433:907] err==Error Domain=NSURLErrorDomain Code=-1 "unknown error" UserInfo=0x1f0bec80 {NSUnderlyingError=0x1f0be9b0 "The operation couldn’t be completed. (OSStatus error -12935.)", NSLocalizedDescription=unknown error}, imageRef==(null)

最佳答案

您的缩略图提取代码工作正常。问题是您在 tableView:cellForRowAtIndexPath: 中初始化 NSURL 的方式:

尝试改变这个:

[NSURL URLWithString:videoPath]

对此:

[NSURL fileURLWithPath:videoPath]

关于ios - 试图获取视频缩略图,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15993766/

44 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com