我必须使用哪种SampleBuffer方法来测量帧速率?

时间:2016-05-26 10:04:50

标签: ios camera frame cmsamplebuffer

我使用AvFoundation。我需要从ios相机准确测量帧速率。

Algoritm:

帧率 = 1/(time(f2)-time(f1)) = __(每秒帧数);

时间(f2) - 是第二帧的时间,(f1) - 是第一帧的时间。 如何使用sampleBuffer?

1 个答案:

答案 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)