Objective c CMTimeGetSeconds返回0,而不是0.0666667
您好,我正在尝试将一个表示帧速率的整数转换为CMTime,以便能够在AVCaptureScreenInput中设置minFrameDuration 到现在为止,我一直Objective c CMTimeGetSeconds返回0,而不是0.0666667,objective-c,avfoundation,cmtime,Objective C,Avfoundation,Cmtime,您好,我正在尝试将一个表示帧速率的整数转换为CMTime,以便能够在AVCaptureScreenInput中设置minFrameDuration 到现在为止,我一直 int numberOfFrames = [self convertFrameRateStringToInt:[parameters objectForKey:@"frameRate"]]; Float64 frameDuration = 1.0/numberOfFrames; NSLog(@"numberOfFrames %i
int numberOfFrames = [self convertFrameRateStringToInt:[parameters objectForKey:@"frameRate"]];
Float64 frameDuration = 1.0/numberOfFrames;
NSLog(@"numberOfFrames %i - frameDuration %f",numberOfFrames, frameDuration);
NSLog(@"timeshow %f",CMTimeGetSeconds(CMTimeMakeWithSeconds(frameDuration, 1)));
return CMTimeMakeWithSeconds(frameDuration,1);
如果numberOfFrames设置为每秒15帧,则帧持续时间为0.066667,因此CMTimeMakeWithSeconds的参数为0.066667和1,这意味着CMTimeGetSeconds应返回0.066667/1=0.066667,而不是返回0
有人能找出我做错了什么并解释原因吗?
谢谢
Edit1:我成功地改变了功能,如下所示:
int numberOfFrames = [self convertFrameRateStringToInt:string];
NSLog(@"timeshow %f",CMTimeGetSeconds(CMTimeMake(1, (int32_t)numberOfFrames)));
return CMTimeMake(1, (int32_t)numberOfFrames);
我仍然不明白为什么最后一种方法不起作用你应该像这样构建你的
CMTime
:
CMTimeMake(1, numberOfFrames);
CMTime表示为有理数,带有分子(int64_t值)和分母(int32_t时间刻度)。从概念上讲,时间刻度指定分子中每个单位所占的秒数。因此,如果时间刻度为4,则每个单位表示四分之一秒;如果时间刻度为10,则每个单位表示十分之一秒,依此类推
您的呼叫
CMTimeMakeWithSeconds
将kCMTimeFlags\u添加到CMTime
。这就是为什么它会四舍五入到最接近的整秒。哦,对不起,你是对的,它是这样工作的,但是你能解释为什么我的方法不工作吗NSLog(@“timeshow%f”,CMTimeGetSeconds(CMTimeMake(1,numberOfFrames))代码>为我输出“timeshow 0.066667”。这就是你想要的结果。我在我的答案中添加了关于舍入的部分是的,很抱歉我没有很好地阅读你的答案我自己找到了解决方案,我想发布它。非常感谢CMTime对象给了我一个可怕的惊喜