Reputation: 14722
I get a CVPixelBuffer from ARSessionDelegate.
There is another unchangeable part of my app where I need a CMSampleBuffer object. So I am trying to create a CMSampleBuffer out of CVPixelBuffer.
I am using this method to create CMSampleBuffer:
func CMSampleBufferCreateReadyWithImageBuffer(_ allocator: CFAllocator?,
_ imageBuffer: CVImageBuffer,
_ formatDescription: CMVideoFormatDescription,
_ sampleTiming: UnsafePointer<CMSampleTimingInfo>,
_ sBufOut: UnsafeMutablePointer<CMSampleBuffer?>) -> OSStatus
This function takes 5 parameters:
Here is my attempt at create a CMVideoFormatDescription:
let w = CVPixelBufferGetWidth(pixelBuffer)
let h = CVPixelBufferGetHeight(pixelBuffer)
var format: CMVideoFormatDescription?
CMVideoFormatDescriptionCreate(nil, kCMVideoCodecType_HEVC, Int32(w), Int32(h), nil, &format)
I am pretty sure I should not be hardcoding to kCMVideoCodecType_HEVC
but I am not sure how to figure out the codec type.
Upvotes: 1
Views: 1213
Reputation: 1714
var formatDescription: CMVideoFormatDescription?
CMVideoFormatDescriptionCreateForImageBuffer(allocator: nil,
imageBuffer: yourCVPixelBuffer,
formatDescriptionOut: &formatDescription)
Upvotes: 0
Reputation: 622
Use CMVideoFormatDescriptionCreateForImageBuffer
to create the format description directly from the CVPixelBuffer (which is a CVImageBuffer).
Upvotes: 2