Skip to content

Instantly share code, notes, and snippets.

@doozMen
Created January 28, 2022 13:07
Show Gist options
  • Save doozMen/1f60e0920d40afd71f4ff761c2a19253 to your computer and use it in GitHub Desktop.
Save doozMen/1f60e0920d40afd71f4ff761c2a19253 to your computer and use it in GitHub Desktop.
Creates a SMSampleBuffer for video to be used in unit tests
func createEmptyVideo() -> CMSampleBuffer {
var pixelBuffer : CVPixelBuffer? = nil
CVPixelBufferCreate(kCFAllocatorDefault, 100, 100, kCVPixelFormatType_444YpCbCr10BiPlanarVideoRange, nil, &pixelBuffer)
var info = CMSampleTimingInfo()
info.presentationTimeStamp = .zero
info.duration = .invalid
info.decodeTimeStamp = .invalid
var formatDesc: CMFormatDescription? = nil
CMVideoFormatDescriptionCreateForImageBuffer(allocator: kCFAllocatorDefault, imageBuffer: pixelBuffer!, formatDescriptionOut: &formatDesc)
var sampleBuffer: CMSampleBuffer? = nil
CMSampleBufferCreateReadyWithImageBuffer(
allocator: kCFAllocatorDefault,
imageBuffer: pixelBuffer!,
formatDescription: formatDesc!,
sampleTiming: &info,
sampleBufferOut: &sampleBuffer
)
return sampleBuffer!
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment