A misunderstanding of V4L2

2019-07-21 11:21发布

问题:

I have a small problem with the size of my buffers in a C++ program. I grab YUYV images from a camera using V4L2 (an example is available here )

I want to take one image and put it into a my own image structure. Here is the buffer given by the V4L2 structure and its size

(uchar*)buffers_[buf.index].start, buf.bytesused

In my structure, I create a new buffer (mybuffer) with a size of width*height*bitSize (byte size is 4 since I grab YUYV or YUV422 images).

The problem is that I was expecting the buffer buf to be the same size as the one that I created. But this is not the case, for example when I grab a 640*480 image buf=614400 and mybuffer=1228800 (twice as big).

Does anyone have any idea why this is the case ?

回答1:

YUV422 uses 4 bytes per 2 pixels

In YUV422 mode the U ans V values are shared between two pixels. The bytes in the Image are ordered like U0 Y0 V0 Y1 U2 Y2 V2 Y3 etc.

Giving pixels like:

pixel 0   U0Y0V0
pixel 1   U0Y1V0
pixel 2   U2Y2V2
pixel 3   U2Y3V2


标签: c++ linux v4l2