This is my take on it. This is still untested but here it goes:
YV12
8 bit Y plane followed by 8 bit 2x2 subsampled V and U planes. So a single frame will have a full size Y plane followed 1/4th size V and U planes.
NV21
8-bit Y plane followed by an interleaved V/U plane with 2x2 subsampling. So a single frame will have a full size Y plane followed V and U in a 8 bit by bit blocks.
So here goes the code
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;
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…