Spa*_*Dog 6 iphone ipad ios avcapturesession
我在AVCaptureSession中,我需要知道正在捕获的帧的数量.
捕获开始时,我将帧数计数器重置为零.因此,第一帧的时间戳将为零.后续帧将具有这样的捕获时间戳,例如:
0
0.033
0.066
0.099
etc
Run Code Online (Sandbox Code Playgroud)
但这些不是确切的数字,因为可以丢弃帧并且可能发生轻微的差异.我需要知道捕获帧的确切时间.
我有这个方法,每次抓取一个帧时调用...
- (void)captureOutput:(AVCaptureOutput *)captureOutput didOutputSampleBuffer:(CMSampleBufferRef)sampleBuffer fromConnection:(AVCaptureConnection *)connection
Run Code Online (Sandbox Code Playgroud)
在这个方法中我可以获得一个帧的CMTime并使用以下命令将其打印到控制台:
CMTime timestamp = CMSampleBufferGetPresentationTimeStamp( sampleBuffer );
NSLog(@"%lld", timestamp.value);
Run Code Online (Sandbox Code Playgroud)
但这会给我带来狂野的数字
156317265588132
156317307247388
156317348909678
156317390573453
156317432230603
Run Code Online (Sandbox Code Playgroud)
一个数字和下一个数字之间的差异大约是41,659,256,它似乎不代表抓取帧时带小数位的秒数.
如果我将这个数字除以时间刻度,使用
NSLog(@"%lld", timestamp.value/timestamp.timescale);
Run Code Online (Sandbox Code Playgroud)
这些数字对于25帧是相同的,并且只有在达到一整秒时才会改变.
当抓取一个帧时,如何获得带小数位的精确时间戳(以秒为单位)?谢谢.
小智 8
如果我将这个数字除以时间刻度,那么25帧的数字将是相同的,并且只有在达到一整秒时才会改变.
因为整数除法截断.怎么样
NSLog(@"%f", (float)timestamp.value / timestamp.timescale);
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2455 次 |
| 最近记录: |