这是我的看法。这仍然未经测试,但在这里:
YV12
8 位 Y 平面,后跟 8 位 2x2 二次采样 V 和 U 平面。所以单帧将有一个全尺寸的 Y 平面,然后是 1/4 尺寸的 V 和 U 平面。
NV21
8 位 Y 平面,后跟具有 2x2 子采样的交错 V/U 平面。因此,单个帧将有一个完整大小的 Y 平面,然后是 8 位块中的 V 和 U。
所以这里是代码
public static byte[] YV12toNV21(final byte[] input,
final byte[] output, final int width, final int height) {
final int size = width * height;
final int quarter = size / 4;
final int vPosition = size; // This is where V starts
final int uPosition = size + quarter; // This is where U starts
System.arraycopy(input, 0, output, 0, size); // Y is same
for (int i = 0; i < quarter; i++) {
output[size + i*2 ] = input[vPosition + i]; // For NV21, V first
output[size + i*2 + 1] = input[uPosition + i]; // For Nv21, U second
}
return output;
}