let duration = CMSampleBufferGetDuration(self)
let timeStamp = CMSampleBufferGetPresentationTimeStamp(self)
let decodeTimeStamp = CMSampleBufferGetDecodeTimeStamp(self)
let sampleTime = CMSampleTimingInfo(duration: duration, presentationTimeStamp: timeStamp, decodeTimeStamp: decodeTimeStamp)

let videoInfo: CMVideoFormatDescriptionRef?
CMVideoFormatDescriptionCreateForImageBuffer(kCFAllocatorDefault, pixelBuffer!, &videoInfo)

var oBuf: CMSampleBufferRef?
CMSampleBufferCreateForImageBuffer(kCFAllocatorDefault, pixelBuffer!, true, nil, nil, videoInfo!, sampleTime, &oBuf)
self是CMSampleBufferRef的实例。

最后一行引发构建错误:Cannot convert value of type 'CMSampleTimingInfo' to expected argument type 'UnsafePointer<CMSampleTimingInfo>'

最佳答案

是的,您正在传递CMSampleTimingInfo,并且该函数需要UnsafePointer<CMSampleTimingInfo>。我没有尝试过,但是其他SO答案(like this)似乎提出了以下建议:

withUnsafePointer(&sampleTime) {
    (unsafeSampleTime: UnsafePointer<CMSampleTimingInfo>) -> Void in
    CMSampleBufferCreateForImageBuffer(kCFAllocatorDefault, pixelBuffer!, true, nil, nil, videoInfo!, unsafeSampleTime, &oBuf)
}

如果您通过函数的签名解决了sampleTime的问题,那么oBuf似乎也会遇到同样的问题。在这种情况下,您将需要withUnsafeMutablePointer

09-07 16:47