nvJPEG, how to encode NV12

hi, there!

I’m trying to encode NV12 frame with nvjpeg without success. The closest thing I can get is to encode I420 frame, with code below:

	nv_image.channel[0] = (unsigned char*)dptr;
	nv_image.channel[1] = nv_image.channel[0] + 3840 * 2160;
	nv_image.channel[2] = nv_image.channel[1] + 1920 * 1080;
	nv_image.channel[3] = NULL;
	nv_image.pitch[0] = 3840;
	nv_image.pitch[1] = 1920;
	nv_image.pitch[2] = 1920;
	nv_image.pitch[3] = 0;
	ret = nvjpegEncodeYUV(nv_handle, nv_enc_state, nv_enc_params,
		&nv_image, NVJPEG_CSS_420, 3840, 2160, 0);

The result, of course, is a picture with wrong chroma.

Is there a way to encode NV12 directly? How? Or do I have to transform my NV12 frame to I420?

Thanks!

NV12 is an interleaved format (for the UV plane). nvjpegEncodeYUV requires planar data. See here. Convert your interleaved format to a supported planar format with separate Y,U, and V planes. This is a matter of copying/rearranging data. No I don’t have suggestions for APIs to convert NV12 to a planar format. They may exist, I just don’t know about them offhand. If it were me, I would just write a CUDA kernel to do it.