1

我与 AvFoundation 合作。我需要从 ios 相机准确测量帧速率。

算法:

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

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

4

1 回答 1

2

你需要打电话CMSampleBufferGetPresentationTimeStamp(sampleBuffer)

像这样的东西(很快,有点尴尬,因为我找不到CMTime1/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)
于 2016-05-30T12:50:22.847 回答