Andrew Kachalin Andrew Kachalin - 2 years ago 85
iOS Question

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

I work with AvFoundation. I need to measure accurately frame rate from ios camera.


Frame rate =

= __ (frame per second);

Where time(f2) – it's time when come second frame, and (f1) – it's time of first frame.
How do it with using sampleBuffer?

Answer Source

You need to call CMSampleBufferGetPresentationTimeStamp(sampleBuffer)

Something like this (in swift, a little awkward because I couldn't find a 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)
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download