【问题标题】:How do I create a CMVideoFormatDescription object如何创建 CMVideoFormatDescription 对象
【发布时间】:2019-03-24 20:50:30
【问题描述】:

我从 ARSessionDelegate 得到一个 CVPixelBuffer。

我的应用程序还有一个不可更改的部分,我需要一个 CMSampleBuffer 对象。所以我试图从 CVPixelBuffer 中创建一个 CMSampleBuffer。

我正在使用这种方法来创建 CMSampleBuffer:

func CMSampleBufferCreateReadyWithImageBuffer(_ allocator: CFAllocator?, 
                                        _ imageBuffer: CVImageBuffer, 
                                        _ formatDescription: CMVideoFormatDescription, 
                                        _ sampleTiming: UnsafePointer<CMSampleTimingInfo>, 
                                        _ sBufOut: UnsafeMutablePointer<CMSampleBuffer?>) -> OSStatus

这个函数有5个参数:

  1. CFAllocator - 我相信这不是必需的。
  2. imageBuffer - 这是 CVPixelBuffer。
  3. CMVideoFormatDescription - 我如何正确创建它?
  4. sampleTiming:我可以弄清楚如何使用 this answer 创建它。
  5. sBufOut - 只是一个指向我要创建的 CMSampleBuffer 对象的指针。

这是我创建 CMVideoFormatDescription 的尝试:

    let w = CVPixelBufferGetWidth(pixelBuffer)
    let h = CVPixelBufferGetHeight(pixelBuffer)
    var format: CMVideoFormatDescription?
    CMVideoFormatDescriptionCreate(nil, kCMVideoCodecType_HEVC, Int32(w), Int32(h), nil, &format)

我很确定我不应该硬编码到kCMVideoCodecType_HEVC,但我不确定如何确定编解码器类型。

【问题讨论】:

    标签: swift avfoundation core-video


    【解决方案1】:

    使用CMVideoFormatDescriptionCreateForImageBuffer 直接从 CVPixelBuffer(它是一个 CVImageBuffer)创建格式描述。

    【讨论】:

    • 你能给出任何可以帮助直接创建格式描述的示例吗?
    【解决方案2】:
    var formatDescription: CMVideoFormatDescription?
    CMVideoFormatDescriptionCreateForImageBuffer(allocator: nil,
                                                 imageBuffer: yourCVPixelBuffer,
                                                 formatDescriptionOut: &formatDescription)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-04-06
      • 1970-01-01
      • 1970-01-01
      • 2011-12-14
      • 2017-10-28
      • 2018-07-21
      • 2011-03-17
      • 2013-06-23
      相关资源
      最近更新 更多