gpt4 book ai didi

image - 我无法获得用于从 1.8 秒视频生成静止图像的精确 CMTime

转载 作者:行者123 更新时间:2023-11-28 21:40:27 25 4
gpt4 key购买 nike

每次我尝试从我的视频 Assets 生成静止帧时,它都会在 0.000.. 秒的时间生成。我可以从我的日志消息中看到这一点。好消息是我可以在时间 0.000 获取图像......以显示在名为“myImageView”的 UIImageView 中。我认为问题是 AVURLAssetPreferPreciseDurationAndTimingKey 没有设置,但即使在我想出如何做到这一点之后,它仍然无法正常工作..

这是我的..

time、actualTime、generate在Header中声明

NSString *path = [NSHomeDirectory() stringByAppendingPathComponent:[NSString stringWithFormat:@"Documents/videoTest4.m4v"]];
//UISaveVideoAtPathToSavedPhotosAlbum(path, self, @selector(video:didFinishSavingWithError:contextInfo:), nil);
NSURL *url = [NSURL fileURLWithPath:path];

NSDictionary *options = [NSDictionary dictionaryWithObject:[NSNumber numberWithBool:YES] forKey:AVURLAssetPreferPreciseDurationAndTimingKey];
AVURLAsset *asset = [[AVURLAsset alloc] initWithURL:url options:options];

Float64 durationSeconds = CMTimeGetSeconds([asset duration]);

generate = [[AVAssetImageGenerator alloc] initWithAsset:asset];
NSError *err = nil;

time = CMTimeMake(600,600.0);
CGImageRef imgRef = [generate copyCGImageAtTime:time actualTime:&actualTime error:&err];
UIImage *currentImg = [[UIImage alloc] initWithCGImage:imgRef];
myImageView.image = currentImg;

NSLog(@"The total Video Duration is %f",durationSeconds);
NSLog(@"The time I want my image is %f",CMTimeGetSeconds(time));
NSLog(@"The actual time my image was take was %f",CMTimeGetSeconds(actualTime));

我的控制台显示..

2011-04-28 18:49:59.062 videoTest[26553:207] 视频总时长为 1.880000

2011-04-28 18:49:59.064 videoTest[26553:207] 我想要我的图像的时间是 1.000000

2011-04-28 18:49:59.064 videoTest[26553:207] 我拍摄图像的实际时间是 0.000000

......................................

提前非常感谢你们..:)

最佳答案

要解决此问题,您只需将 requestedTimeToleranceBeforerequestedTimeToleranceAfter 设置为 AVAssetImageGenerator 的 kCMTimeZero。

AVAssetImageGenerator Class Reference

关于image - 我无法获得用于从 1.8 秒视频生成静止图像的精确 CMTime,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5825990/

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