我必须使用 SampleBuffer 的哪些方法来测量帧率?

what methods of SampleBuffer do I must use for measurement of frame rate?

我在 AvFoundation 工作。我需要准确测量 ios 相机的帧率。

算法:

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

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

您需要致电CMSampleBufferGetPresentationTimeStamp(sampleBuffer)

类似这样的东西(在 swift 中,有点尴尬,因为我找不到 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)