【问题标题】:Combining two YV12 image buffers into a single side-by-side image将两个 YV12 图像缓冲区组合成一个并排图像
【发布时间】:2016-07-15 20:06:10
【问题描述】:

我有两个 YV12 格式的图像缓冲区,我需要将它们合并成一个并排的图像。

(1920x1080) + (1920x1080) = (3840*1080)

YV12 被分成 3 个独立的平面。

YYYYYYYY VV UU

像素格式为每像素 12 位。

我创建了一个方法,将memcpys 一个缓冲区 (1920x1080) 转换为一个更大的缓冲区 (3840x1080),但它不起作用。

这是我的 c++。

BYTE* source = buffer;
BYTE* destination = convertBuffer3D;

// copy over the Y
for (int x = 0; x < height; x++)
{
    memcpy(destination, source, width);
    destination += width * 2;
    source += width;
}

// copy over the V
for (int x = 0; x < (height / 2); x++)
{
    memcpy(destination, source, width / 2);
    destination += width;
    source += width / 2;
}

// copy over the U
for (int x = 0; x < (height / 2); x++)
{
    memcpy(destination, source, width / 2);
    destination += width;
    source += width / 2;
}

我预料到了:

相反,我得到了这个结果:

我错过了什么?

【问题讨论】:

  • 代码看起来差不多。您可能还遗漏了其他东西(任一图像上的步幅都延长了?底部填充?)。
  • 没有扩展步幅我们的填充。我的 1920x1080 图像的总缓冲区大小是 3110400 (1920x1080x1.5),所以没有额外的数据。
  • 另外我想如果它是 NV12 而不是 YV12 也会有类似的效果。然后,您需要在循环之后简单地检查源和目标。如果它们是正确的,那么问题不在于循环,而在于图像结构与您期望的不同。
  • @RomanR,正确。 NV12 与 YV12 相同,只是 U/V 数据是交错的,而不是在不同的平面上。
  • 不仅是交错的,在 NV12 中 Y 是相同的(与您的情况一样),并且 UV 被复制到不同的块中(可能会导致图像上出现的内容)。

标签: c++ yuv color-space


【解决方案1】:

你想要的是这个:

Y1 Y1 Y1 Y1 Y2 Y2 Y2 Y2
Y1 Y1 Y1 Y1 Y2 Y2 Y2 Y2
Y1 Y1 Y1 Y1 Y2 Y2 Y2 Y2
Y1 Y1 Y1 Y1 Y2 Y2 Y2 Y2
U1 U1 U2 U2 V1 V1 V2 V2
U1 U1 U2 U2 V1 V1 V2 V2

但您的代码实际上是这样做的:

Y1 Y1 Y1 Y1 Y2 Y2 Y2 Y2
Y1 Y1 Y1 Y1 Y2 Y2 Y2 Y2
Y1 Y1 Y1 Y1 Y2 Y2 Y2 Y2
Y1 Y1 Y1 Y1 Y2 Y2 Y2 Y2
U1 U1 V1 V1 U2 U2 V2 V2
U1 U1 V1 V1 U2 U2 V2 V2

这是更正后的代码(未经测试)

BYTE* source = buffer;
BYTE* destination = convertBuffer3D;

// copy over the Y
for (int x = 0; x < height; x++)
{
    memcpy(destination, source, width);
    destination += width * 2;
    source += width;
}

for (int x = 0; x < (height / 2); x++)
{
    // copy over the V
    memcpy(destination, source, width / 2);
    destination += width;
    source += width / 2;

    // copy over the U
    memcpy(destination, source, width / 2);
    destination += width;
    source += width / 2;
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-04-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多