Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
public static byte[] NV21toYUV420Planar(byte[] input, byte[] output, int width, int height) {
final int frameSize = width * height;
final int qFrameSize = frameSize/4;
System.arraycopy(input, 0, output, 0, frameSize); // Y
byte v, u;
for (int i = 0; i < qFrameSize; i++) {
v = input[frameSize + i*2];
u = input[frameSize + i*2 + 1];
output[frameSize + i + qFrameSize] = v;
output[frameSize + i] = u;
}
return output;
}
public static byte[] NV21toYUV420SemiPlanar(byte[] input, byte[] output, int width, int height) {
final int frameSize = width * height;
final int qFrameSize = frameSize/4;
System.arraycopy(input, 0, output, 0, frameSize); // Y
byte v, u;
for (int i = 0; i < qFrameSize; i++) {
v = input[frameSize + i*2];
u = input[frameSize + i*2 + 1];
output[frameSize + i*2] = u;
output[frameSize + i*2 + 1] = v;
}
return output;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment