# Nvarguscamerasrc NV12 buffer size?

**URL:** <https://forums.developer.nvidia.com/t/nvarguscamerasrc-nv12-buffer-size/228890>\
**Category:** Jetson Nano\
**Tags:** gstreamer, camera\
**Created:** [September 23, 2022, 6:07pm UTC](https://forums.developer.nvidia.com/t/nvarguscamerasrc-nv12-buffer-size/228890 "2022-09-23T18:07:05Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![klaskak](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@klaskak](https://forums.developer.nvidia.com/u/klaskak)\
**Post date:** [September 23, 2022, 6:07pm UTC](https://forums.developer.nvidia.com/t/nvarguscamerasrc-nv12-buffer-size/228890/1 "2022-09-23T18:07:05Z")

</div>

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:height_width])  
> 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?

 ![nv12](https://global.discourse-cdn.com/nvidia/original/3X/0/c/0c322247b620bbe20cb97ff109883b38a1e961e9.jpeg)  
 ![RGB](https://global.discourse-cdn.com/nvidia/original/3X/9/0/904175f6610fff83ef804bdab8a42843c23b2538.jpeg)

---

<div class="post-metadata">

**Author:** ![klaskak](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@klaskak](https://forums.developer.nvidia.com/u/klaskak)\
**Post date:** [September 23, 2022, 8:46pm UTC](https://forums.developer.nvidia.com/t/nvarguscamerasrc-nv12-buffer-size/228890/2 "2022-09-23T20:46:38Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![ShaneCCC](https://sea2.discourse-cdn.com/nvidia/user_avatar/forums.developer.nvidia.com/shaneccc/32/14043_2.png) [@ShaneCCC](https://forums.developer.nvidia.com/u/ShaneCCC)\
**Post date:** [September 26, 2022, 2:42am UTC](https://forums.developer.nvidia.com/t/nvarguscamerasrc-nv12-buffer-size/228890/4 "2022-09-26T02:42:18Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![klaskak](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@klaskak](https://forums.developer.nvidia.com/u/klaskak)\
**Post date:** [September 26, 2022, 2:51pm UTC](https://forums.developer.nvidia.com/t/nvarguscamerasrc-nv12-buffer-size/228890/5 "2022-09-26T14:51:39Z")

</div>

Not sure what you mean could you please elaborate?

---

<div class="post-metadata">

**Author:** ![ShaneCCC](https://sea2.discourse-cdn.com/nvidia/user_avatar/forums.developer.nvidia.com/shaneccc/32/14043_2.png) [@ShaneCCC](https://forums.developer.nvidia.com/u/ShaneCCC)\
**Post date:** [September 27, 2022, 6:18am UTC](https://forums.developer.nvidia.com/t/nvarguscamerasrc-nv12-buffer-size/228890/6 "2022-09-27T06:18:50Z")

</div>

The width need alignment 256 that tell the Y size is 3328_1848 instead of 3264_1848  
The same as CbCr

---

<div class="post-metadata">

**Author:** ![klaskak](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@klaskak](https://forums.developer.nvidia.com/u/klaskak)\
**Post date:** [September 29, 2022, 3:16pm UTC](https://forums.developer.nvidia.com/t/nvarguscamerasrc-nv12-buffer-size/228890/7 "2022-09-29T15:16:44Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![system](https://sea2.discourse-cdn.com/nvidia/user_avatar/forums.developer.nvidia.com/system/32/68080_2.png) [@system](https://forums.developer.nvidia.com/u/system)\
**Post date:** [October 19, 2022, 3:55am UTC](https://forums.developer.nvidia.com/t/nvarguscamerasrc-nv12-buffer-size/228890/9 "2022-10-19T03:55:15Z")

</div>

Closed on October 19, 2022, 3:55am UTC

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.
