btomtom5
btomtom5

Reputation: 860

CVPixelBufferGetAddress returns Nil

I am currently trying to get the baseAddress of a CVVideoPixelBuffer but it kept returning nil even when I was able to see that CVVideoPixelBuffer itself was not nil.

let baseAddress = CVPixelBufferGetBaseAddressOfPlane(cvPixelBuffer, 0) // -> nil =(

Upvotes: 0

Views: 583

Answers (1)

btomtom5
btomtom5

Reputation: 860

I found out that the reason is because I was trying to access the pixelBuffer from CPU and therefore requires the CVPixelBuffer's addressed to be locked into a specific address in memory.

CVPixelBufferLockBaseAddress(cvPixelBuffer, CVPixelBufferLockFlags.readOnly)
let baseAddress = CVPixelBufferGetBaseAddressOfPlane(cvPixelBuffer, 0)
CVPixelBufferUnlockBaseAddress(cvPixelBuffer, CVPixelBufferLockFlags.readOnly)

This works!

Upvotes: 5

Related Questions