Skip to content

Instantly share code, notes, and snippets.

@a-chernykh
Last active August 29, 2015 14:03
Show Gist options
  • Save a-chernykh/394fb8520feddfea979f to your computer and use it in GitHub Desktop.
Save a-chernykh/394fb8520feddfea979f to your computer and use it in GitHub Desktop.
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