iosswiftcameraxcode10cmsamplebuffer

Value of type 'CMSampleBuffer' has no member 'imageBuffer'


I am currently working on a project that uses a live camera view in Swift. I used some code I found on GitHub to give me that live camera view, and it works great on my MacBook Pro running Mojave. I have all my files stored on an external HDD, so I went to my iMac and started working on the project there. I think I have two different versions of the Xcode 10 beta, which could be part of the problem? Basically this line works fine on my MacBook but not on that iMac, which btw is running macOS high Sierra version 15:

guard let pixelBuffer : CVPixelBuffer = sampleBuffer.imageBuffer else { return }

It gives me the following error:

Value of type 'CMSampleBuffer' has no member 'imageBuffer'

But when opening the exact same project on my macbook this works with no problems whatsoever. Could this be an Xcode version thing or is it because I am running two different macOS version?


Solution

  • You can still use this function:

    CMSampleBufferGetImageBuffer(_ sbuf: CMSampleBuffer) to get a CVPixelBuffer?.

    The direct replacement would be:

    guard let pixelBuffer: CVPixelBuffer = CMSampleBufferGetImageBuffer(sampleBuffer) else { return }