Instance Property

masterClock

A clock object used for output synchronization.

Declaration

var masterClock: CMClock? { get }

Discussion

The returned CMClock object is read-only and provides a timebase for all sample buffers in capture output. This can be used in conjunction with the clock from an AVCaptureInput.Port object to synchronize capture output with external data sources such as motion samples.

For example, to synchronize output timestamps to the original timestamps provided by an input device, you can do the following in your fileOutput(_:didOutputSampleBuffer:from:) method:

guard let masterClock = captureSession.masterClock,
    let originalClock = connection.inputPorts.first?.clock else { return }

let synchedPTS = sampleBuffer.presentationTimeStamp
let originalPTS = masterClock.convertTime(synchedPTS, to: originalClock)

You can observe the value of this property using Key-value observing.