Android实现 YUV I420 数据转 NV21数据。
public static byte[] I420Tonv21(byte[] i420bytes, int width, int height) {
byte[] nv21bytes = new byte[i420bytes.length];
int total = width * height; //Y数据的长度
int nLen = total / 4; //U、V数据的长度
System.arraycopy(i420bytes, 0, nv21bytes, 0, total);
for (int i = 0; i < nLen; i++) {
byte u = i420bytes[total + i];
byte v = i420bytes[total + nLen + i];
nv21bytes[total + i * 2] = v;
nv21bytes[total + i * 2 + 1] = u;
}
return nv21bytes;
}
参考文章https://blog.csdn.net/u012121105/article/details/79276856,此博客I420数据转NV21有问题。