从CVPixelBuffer

创建CMSampleBuffer我得到一个CVPixelBuffer从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?

回答:

的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)

以上是 从CVPixelBuffer 的全部内容, 来源链接: utcz.com/qa/265510.html

回到顶部