We can convert CMSampleBuffer to NSData with following function. But we could not find a way to convert it to Data.
We tried using
Data(bytes: <#T##UnsafeRawPointer#>, count: <#T##Int#>)
instead of
NSData(bytes: <#T##UnsafeRawPointer?#>, length: <#T##Int#>)
but no luck. Is there anyone who could do it.
func frameData() -> NSData {
let imageBuffer = CMSampleBufferGetImageBuffer(sampleBuffer)
CVPixelBufferLockBaseAddress(imageBuffer!, CVPixelBufferLockFlags(rawValue: 0))
let bytesPerRow = CVPixelBufferGetBytesPerRow(imageBuffer!)
let height = CVPixelBufferGetHeight(imageBuffer!)
let src_buff = CVPixelBufferGetBaseAddress(imageBuffer!)
let nsdata = NSData(bytes: src_buff, length: bytesPerRow * height)
CVPixelBufferUnlockBaseAddress(imageBuffer!, CVPixelBufferLockFlags(rawValue: 0))
return nsdata
}