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>'
答案 0 :(得分:3)
是的,您正在传递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
。
答案 1 :(得分:0)
这是另一种方法..将var
用于sampleTime
let duration = CMSampleBufferGetDuration(self)
let timeStamp = CMSampleBufferGetPresentationTimeStamp(self)
let decodeTimeStamp = CMSampleBufferGetDecodeTimeStamp(self)
var sampleTime = CMSampleTimingInfo(duration: duration, presentationTimeStamp: timeStamp, decodeTimeStamp: decodeTimeStamp)
var videoInfo: CMVideoFormatDescriptionRef? = nil
CMVideoFormatDescriptionCreateForImageBuffer(kCFAllocatorDefault, pixelBuffer!, &videoInfo)
var oBuf: CMSampleBufferRef?
CMSampleBufferCreateForImageBuffer(kCFAllocatorDefault, pixelBuffer!, true, nil, nil, videoInfo!, &sampleTime, &oBuf)
我接受这个作为答案,因为语法比withUnsafePointer()
方法更清晰。但如果您愿意使用它,withUnsafePointer
也会起作用。