CVPixelBufferGetBytesPerRowOfPlane strange result

Hello everyone.

I'm decoding an H264 elementary stream with VideoToolbox.

The VTDecompressionSession's output callback returns a CVImageBuffer successfully.

While attempting to convert this YUV image to RGB, I prepare a luma vImage_Buffer and chroma vImage_Buffer, but I get strange values from CVPixelBufferGetBytesPerRowOfPlane:

CVPixelBufferGetBaseAddressOfPlane(0) 0x10e98c000
CVPixelBufferGetHeightOfPlane(0) 1080
CVPixelBufferGetWidthOfPlane(0) 1440
CVPixelBufferGetBytesPerRowOfPlane(0) 46080

CVPixelBufferGetBaseAddressOfPlane(1) 0x10eb2b000
CVPixelBufferGetHeightOfPlane(1) 540
CVPixelBufferGetWidthOfPlane(1) 720
CVPixelBufferGetBytesPerRowOfPlane(1) 23040

If I use this value (46080) in initializing the vImage_Buffer's rowBytes field, vImageConvert_420Yp8_CbCr8ToARGB8888 crashes.

If I simply set rowBytes=width, the conversion is successful.

Has anyone seen this before?

Notice the value returned is 32 × width. Why?

Update: CVPixelBufferGetBytesPerRow() returns a much more reasonable value of 1536 (a multiple of 128, i.e. ceil(1440 / 128) × 128 = 1536).

Setting rowBytes=CVPixelBufferGetBytesPerRow() for the luma vImage_Buffer, and rowBytes=(CVPixelBufferGetBytesPerRow() / 2) for the chroma vImage_Buffer, vImageConvert_420Yp8_CbCr8ToARGB8888 is successful.

Update: Nevermind. This only happens with kCVPixelFormatType_Lossless_420YpCbCr8BiPlanarVideoRange. I had not set kCVPixelBufferPixelFormatTypeKey in the image buffer attributes dictionary argument to VTDecompressionSessionCreate, thinking it would choose the most reasonable pixel format... If I request kCVPixelFormatType_420YpCbCr8Planar or kCVPixelFormatType_420YpCbCr8BiPlanarVideoRange, CVPixelBufferGetBytesPerRowOfPlane() returns a good value (1472, i.e. ceil(1440 / 64) × 64).

CVPixelBufferGetBytesPerRowOfPlane strange result
 
 
Q