ios - Swift - 从 CMSampleBuffer 获取 kCMSampleBufferAttachmentKey_DroppedFrameReason

标签 ios swift avfoundation

我想了解为什么我的 AVCaptureOutput 丢帧。在 captureOutput(_ output: AVCaptureOutput, didDrop sampleBuffer: CMSampleBuffer, from connection: AVCaptureConnection) 委托(delegate)方法中,我得到一个 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 常量相匹配

最佳答案

我愚蠢地没有看到正确的输出:

var mode: CMAttachmentMode = 0
let reason = CMGetAttachment(sampleBuffer, kCMSampleBufferAttachmentKey_DroppedFrameReason, &mode)
print("reason \(String(describing: reason))") // Optional(OutOfBuffers)

关于ios - Swift - 从 CMSampleBuffer 获取 kCMSampleBufferAttachmentKey_DroppedFrameReason,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45336425/

相关文章:

ios - 如何快速从google place api获取地点图片

ios - Swift:将 NSManagedObject 向上转换为 Entity 的子类

ios - 下拉列表 ios swift

ios - 无法使用 AVCapturePhotoOutput 捕捉照片 swift + xcode

ios - 在 AVMutableComposition 中的多个视频轨道之间切换

iOS 快速将 mp3 转换为 aac

ios - 使用多人连接发送和接收邀请

ios - faSTLane gym 你能跳过存档和导出步骤吗

ios - Swift - 使用 SpriteKit 提高移动节点的速度

swift - 在 swift 中覆盖系统 UI 样式时如何更改默认状态栏颜色