我使用AvFoundation。我需要从ios相机准确测量帧速率。
Algoritm:
帧率 = 1/(time(f2)-time(f1))
= __(每秒帧数);
时间(f2) - 是第二帧的时间,(f1) - 是第一帧的时间。 如何使用sampleBuffer?
答案 0 :(得分:2)
您需要致电CMSampleBufferGetPresentationTimeStamp(sampleBuffer)
像这样(快速,有点尴尬,因为我找不到CMTime
1 / x):
let delta = CMTimeSubtract(CMSampleBufferGetPresentationTimeStamp(buf2), CMSampleBufferGetPresentationTimeStamp(buf1))
// awkward 1/x, beware that delta.value may overflow as a timescale
// what's the right way?
let frameRate = CMTime(value: CMTimeValue(delta.timescale), timescale: CMTimeScale(delta.value))
// maybe you want floating point instead of CMTime:
let frameRateAsFloat64 = CMTimeGetSeconds(frameRate)