Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

What's the function of variables "nu" and "nv" in method saveYuvDataToJPEG? #50

Open
mizhoux opened this issue Mar 11, 2019 · 1 comment

Comments

@mizhoux
Copy link

mizhoux commented Mar 11, 2019

byte[] y = new byte[width * height];
byte[] u = new byte[width * height / 4];
byte[] v = new byte[width * height / 4];
byte[] nu = new byte[width * height / 4]; //
byte[] nv = new byte[width * height / 4];

System.arraycopy(yuvFrame, 0, y, 0, y.length);
for (int i = 0; i < u.length; i++) {
      v[i] = yuvFrame[y.length + 2 * i];
      u[i] = yuvFrame[y.length + 2 * i + 1];
}

The code above seems that the YUV data received from the UVA is already encoded by NV21, the array u and array v represent the data U and V respectively. So I'm confused about the function of the following code due to I don't know what the variables "nu" and "nv" are for.

int uvWidth = width / 2;
int uvHeight = height / 2;
for (int j = 0; j < uvWidth / 2; j++) {
	for (int i = 0; i < uvHeight / 2; i++) {
		byte uSample1 = u[i * uvWidth + j];
		byte uSample2 = u[i * uvWidth + j + uvWidth / 2];
		byte vSample1 = v[(i + uvHeight / 2) * uvWidth + j];
		byte vSample2 = v[(i + uvHeight / 2) * uvWidth + j + uvWidth / 2];
		nu[2 * (i * uvWidth + j)] = uSample1;
		nu[2 * (i * uvWidth + j) + 1] = uSample1;
		nu[2 * (i * uvWidth + j) + uvWidth] = uSample2;
		nu[2 * (i * uvWidth + j) + 1 + uvWidth] = uSample2;
		nv[2 * (i * uvWidth + j)] = vSample1;
		nv[2 * (i * uvWidth + j) + 1] = vSample1;
		nv[2 * (i * uvWidth + j) + uvWidth] = vSample2;
		nv[2 * (i * uvWidth + j) + 1 + uvWidth] = vSample2;
	}
}

//nv21test
byte[] bytes = new byte[yuvFrame.length];
System.arraycopy(y, 0, bytes, 0, y.length);
for (int i = 0; i < u.length; i++) {
	bytes[y.length + (i * 2)] = nv[i];
	bytes[y.length + (i * 2) + 1] = nu[i];
}
@neilyoung
Copy link

did you ever get an answer somehow?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants