How to populate nvjpegImage_t

I have a GPU buffer (input_frame) with a YUV420 image that has been populated by the Nvidia Decoder. The decoder chroma subsampling is set to cudaVideoChromaFormat_420.

I’m trying to store a JPG from this YUV420 buffer. Thus I’m calling nvjpegEncodeYUV to create the JPEG.

nvjpegEncodeYUV requieres nvjpegImage_t to be populated but I’m very confused how to do it.

According to the documentation:

The source argument should be filled with the corresponding YUV planar data. The chroma_subsampling argument should have the chroma subsampling of the input data. Input data should be provided with respect to the subsampling factors. That is, the chrominance image planes should have sizes aligned to the corresponding subsamplings.

My GPU buffer is pitched thus, I’m populating nvjpegImage_t the following:

  nvjpegImage_t imgdesc = {
      input_frame + pitch * height,
      input_frame + pitch * height,

The Y plane seems to be working fine because the resulting image the Y plane looks good. Although I’m struggling with th UV.

Any help how shall I populate this values?