我试图理解为什么我的AVCaptureOutput正在丢帧。在captureOutput(_ output: AVCaptureOutput, didDrop sampleBuffer: CMSampleBuffer, from connection: AVCaptureConnection)
委托方法中,我得到一个CMSampleBuffer
,其中应包含一个附件,说明删除框架的原因(doc)
原因应该是CFString之一:
kCMSampleBufferDroppedFrameReason_FrameWasLate // "FrameWasLate"
kCMSampleBufferDroppedFrameReason_OutOfBuffers // "OutOfBuffers"
kCMSampleBufferDroppedFrameReason_Discontinuity // "Discontinuity"
从文档来看,目前还不清楚如何获得这个价值。我尝试使用CMGetAttachment
,但这会返回CMAttachmentMode
又名UInt32
:
func captureOutput(_ output: AVCaptureOutput, didDrop sampleBuffer: CMSampleBuffer, from connection: AVCaptureConnection) {
var reason: CMAttachmentMode = 0
CMGetAttachment(sampleBuffer, kCMSampleBufferAttachmentKey_DroppedFrameReason, &reason)
print("reason \(reason)") // 1
}
我真的不知道如何将这个UInt32与CFString常量匹配
答案 0 :(得分:2)
我愚蠢地没有看正确的输出:
var mode: CMAttachmentMode = 0
let reason = CMGetAttachment(sampleBuffer, kCMSampleBufferAttachmentKey_DroppedFrameReason, &mode)
print("reason \(String(describing: reason))") // Optional(OutOfBuffers)