Convert Data to stream of CVPixelBuffer

56 Views Asked by At

How to convert Data to stream of CVPixelBuffer,

I am working on CVPixelBuffer output from AVSession and ARSession. following is the code on which I am converting CVPixelBuffer to Data and able to save the data as a file, Now I want to read the same file with Data and convert it back to the stream of CVPixelBuffer

  1. Code to create data file
// private var
   private var depthFramesData : Data = Data()
   private let DEPTH_FRAME_REQUIRED_MEMORY = 640 * 480 * 2

// depthFrame is CVPixelBuffer output as stream from sensor 
func saveDepthFramesOnDiskIfNeeded(depthFrame: CVPixelBuffer){
        
  CVPixelBufferLockBaseAddress(depthFrame, .readOnly)
  guard let eachFrame = CVPixelBufferGetBaseAddress(depthFrame) else {return}
  CVPixelBufferUnlockBaseAddress(depthFrame, .readOnly)
          
  let depthBinary = Data(bytes: eachFrame, count: DEPTH_FRAME_REQUIRED_MEMORY)
  depthFramesData.append(depthBinary)

 // after this I am saving the file to the filesystem 

}

Now I want to read the file say depthFramesData from above back to stream of CVPixelBuffer

Any helpful link will be appreciated.

0

There are 0 best solutions below