分离视频帧的 Y 和 UV C++

Separate Y and UV of a video frame C++

我正在接收一个用 C++ 编写的 gstreamer 元素的 GstVideoFrame 结构中的视频帧。

帧为YUV420 NV12格式

在这个 gstreamer 元素中,我试图在单独的缓冲区中复制 y 帧和 uv 帧。

根据videolan.org,YUV420 NV12 数据在传入帧缓冲区中存储如下:(从网站复制的信息)

NV12:

Related to I420, NV12 has one luma "luminance" plane Y and one plane with U and V values interleaved.

In NV12, chroma planes (blue and red) are subsampled in both the horizontal and vertical dimensions by a factor of 2.

For a 2×2 group of pixels, you have 4 Y samples and 1 U and 1 V sample.

It can be helpful to think of NV12 as I420 with the U and V planes interleaved.

Here is a graphical representation of NV12. Each letter represents one bit:

    For 1 NV12 pixel: YYYYYYYY UVUV
    For a 2-pixel NV12 frame: YYYYYYYYYYYYYYYY UVUVUVUV
    For a 50-pixel NV12 frame: Y×8×50 (UV)×2×50
    For a n-pixel NV12 frame: Y×8×n (UV)×2×n

但我似乎无法计算缓冲区中 y 数据和 uv 数据的偏移量。


Update_1 :我有框架的高度和宽度来计算 y 数据和 uv 数据的大小:
y_size = width * height;
uv_size = y_size / 2;

对此有任何帮助或意见,我们将不胜感激。

谢谢

感谢@Ext3h,这就是我能够从传入的 YUV 帧中分离出 y-data 和 uv-data 的方法。

y_data = (u8 *)GST_VIDEO_FRAME_PLANE_DATA (in_frame, 0);
uv_data =(u8 *)GST_VIDEO_FRAME_PLANE_DATA (in_frame, 1);