swift - 如何创建 CMVideoFormatDescription 对象
问题描述
我从 ARSessionDelegate 得到一个 CVPixelBuffer。
我的应用程序还有一个不可更改的部分,我需要一个 CMSampleBuffer 对象。所以我试图从 CVPixelBuffer 中创建一个 CMSampleBuffer。
我正在使用这种方法来创建 CMSampleBuffer:
func CMSampleBufferCreateReadyWithImageBuffer(_ allocator: CFAllocator?,
_ imageBuffer: CVImageBuffer,
_ formatDescription: CMVideoFormatDescription,
_ sampleTiming: UnsafePointer<CMSampleTimingInfo>,
_ sBufOut: UnsafeMutablePointer<CMSampleBuffer?>) -> OSStatus
这个函数有 5 个参数:
- CFAllocator - 我相信这不是必需的。
- imageBuffer - 这是 CVPixelBuffer。
- CMVideoFormatDescription -我如何正确创建它?
- sampleTiming:我可以弄清楚如何使用这个答案来创建它。
- 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
但我不确定如何确定编解码器类型。
解决方案
用于CMVideoFormatDescriptionCreateForImageBuffer
直接从 CVPixelBuffer(它是一个 CVImageBuffer)创建格式描述。
推荐阅读
- r - 在 R 中看到 left_join 出现意外错误
- java - Is there a a way I can store information with Java without requiring a dedicated server?
- php - woocommerce 基于支付网关的感谢消息
- javascript - Javascript - 如何将数组中对象的第一个元素分配为另一个数组的键
- rest - 更新资源导致位置更改后的 REST 响应
- javascript - How do I return or make null all other EventListeners if another is triggered using vanilla Javascript
- mysql - 在锁定表时重新编号mysql中的主键
- arrays - React:通过字符串映射并为每次迭代发出命令。然后计算结果
- python - 向量的一维卷积
- java - Why can a double store so much more information than a long? (JAVA)