我从ARSessionDelegate得到了一个CVPixelBuffer:
func session(_ session: ARSession, didUpdate frame: ARFrame) {
frame.capturedImage // CVPixelBufferRef
}但我的应用程序的另一部分(我不能更改)使用了CMSampleBuffer。
CMSampleBuffer是CVPixelBuffer的容器。
为了创建一个CMSampleBuffer,我可以使用这个函数:
func CMSampleBufferCreateReadyWithImageBuffer(_ allocator: CFAllocator?,
_ imageBuffer: CVImageBuffer,
_ formatDescription: CMVideoFormatDescription,
_ sampleTiming: UnsafePointer<CMSampleTimingInfo>,
_ sBufOut: UnsafeMutablePointer<CMSampleBuffer?>) -> OSStatus我唯一缺少的参数是sampleTiming --我如何从CVPixelBuffer中提取它?
发布于 2018-01-05 13:32:32
sampleTiming主要包含presentationTimeStamp,您可以通过以下代码轻松创建:
let scale = CMTimeScale(NSEC_PER_SEC)
let pts = CMTime(value: CMTimeValue(frame.timestamp * Double(scale)),
timescale: scale)
var timingInfo = CMSampleTimingInfo(duration: kCMTimeInvalid,
presentationTimeStamp: pts,
decodeTimeStamp: kCMTimeInvalid)https://stackoverflow.com/questions/47993457
复制相似问题