gpt4 book ai didi

iphone - 抓取帧时的 AVCaptureSession 确切时间戳

转载 作者:可可西里 更新时间:2023-11-01 03:47:37 25 4
gpt4 key购买 nike

我在 AVCaptureSession 中,我需要知道正在捕获的帧数。

当捕捉开始时,我会将帧数计数器重置为零。因此,第一帧的时间戳将为零。后续帧将具有这样的捕获时间戳,例如:

0
0.033
0.066
0.099
etc

但这不是确切的数字,因为帧可能会丢失并且可能会出现细微差异。我需要知道捕获帧的确切时间。

我有这个方法,每次抓取帧时都会调用...

- (void)captureOutput:(AVCaptureOutput *)captureOutput didOutputSampleBuffer:(CMSampleBufferRef)sampleBuffer fromConnection:(AVCaptureConnection *)connection 

在此方法中,我可以获得帧的 CMTime 并使用以下命令将其打印到控制台:

CMTime timestamp = CMSampleBufferGetPresentationTimeStamp( sampleBuffer );
NSLog(@"%lld", timestamp.value);

但这会给我像这样的疯狂数字

156317265588132
156317307247388
156317348909678
156317390573453
156317432230603

一个数字与下一个数字之间的差异约为 41,659,256,这似乎并不代表抓取帧时以秒为单位的带小数位的时间。

如果我将这个数字除以时间刻度,使用

NSLog(@"%lld", timestamp.value/timestamp.timescale);

25 帧的数字将相同,并且只会在达到一整秒时改变。

如何在抓取帧时获取精确的时间戳(以秒为单位,带小数位)?谢谢。

最佳答案

If I divide this numbers by the timescale, the numbers will be the same for 25 frames and will only change when a full second is reached.

因为整数除法会截断。怎么样

NSLog(@"%f", (float)timestamp.value / timestamp.timescale);

关于iphone - 抓取帧时的 AVCaptureSession 确切时间戳,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13322569/

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