Reputation: 860
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
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