Nvarguscamerasrc NV12 buffer size?

Hello,

I set up the following pipeline in gstreamer:

nvarguscamerasrc sensor_id=0 !
video/x-raw(memory:NVMM), width=3264, height=1848, framerate=10/1 !
nvvidconv output-buffers=1 !
video/x-raw, format=NV12 !
appsink max-buffers=1 drop=true name=appsink emit-signals=True

When I read the buffer from appsink I get an array with 9047808 bytes

sample = sink.emit(‘pull-sample’)
Get the actual data
buffer = sample.get_buffer()
Get read access to the buffer data
success, map_info = buffer.map(Gst.MapFlags.READ)
len(map_info.data)
9047808

From my research I was led to believe that the buffer should be 6036984 bytes according to the following calculation:

y = 3264 * 1848 //width * height
CbCr = (1848//2 + 3264//2)*2 // two bytes per every four pixels
y + CbCr
6036984

RGB

self.image = np.ndarray(
shape=(height, width, 3),
dtype=np.uint8,
buffer=map_info.data)

NV12

self.image = {}
self.image[‘Y’] = np.ndarray(
shape=(height, width),
dtype=np.uint8,
buffer=map_info.data[0:heightwidth])
self.image[‘CbCr’] = np.ndarray(
shape=(height//2, width//2, 2),
dtype=np.uint8,
buffer=map_info.data[height
width:])

The output image look almost normal, am I missing something?


Quick update, when I wrote those two images to disk on the NM12.jpg I had the red and blue channels flipped, this caused the images to look different color wise.

Still wondering what the remaining bits in the buffer are for.

For the size could be the alignment cause it. Looks like the VIC need 256 alignment.

Not sure what you mean could you please elaborate?

The width need alignment 256 that tell the Y size is 33281848 instead of 32641848
The same as CbCr

Ughh, facepalm it’s a math mistake…

The proper calculation is:
y = 3264 * 1848 //width * height
CbCr = ((1848//2) X (3264//2))*2 // two bytes per every four pixels
==============^===========================
y + CbCr
9047808
Which is exactly the size of the gstreamer buffer
Thank you for your time