Drive5's NvMedia documentation vs reality

In the documentation of the NvMedia JPEG encoder it states it supports encoding from YUV or RGB sources.

http://docs.nvidia.com/drive/nvvib_docs/index.html#page/NVIDIA%2520DRIVE%2520Linux%2520SDK%2520Development%2520Guide%2FMultimedia%2Fmultimedia_guide.html%23wwpID0E0NB0HA

However I am not able to use NvMediaIJPECreate with RGB formats. Only YUV is accepted.
The format enumerations I was able to use with NvMediaIJPECreate: [23, 34, 40, 62, 68, 78, 90, 110, 112, 1014, 1015, 1016]

Can I use RGB inputs into the JPEG encoder?

Also, in http://docs.nvidia.com/drive/nvvib_docs/index.html#page/NVIDIA%2520DRIVE%2520Linux%2520SDK%2520Development%2520Guide%2FMultimedia%2Fmultimedia_guide.html%23wwpID0E0PB0HA, it’s stated that “The NvMedia Image 2D component supports image surface processing (…) It also performs format conversion to/from YUV to RGB (…)”

Where can I find these functions to convert YUV to RGB, or RGB to YUV?

Dear vmatos2,

Regarding question 1, could you let me know the command you used?

Regarding question 2, please refer to below link.
http://docs.nvidia.com/drive/nvvib_docs/index.html#page/NVIDIA%20DRIVE%20Linux%20SDK%20Development%20Guide%2FMultimedia%2Fmultimedia_guide.html%23wwpID0E03E0HA

This is how I am creating my surface and jpeg encoder.

NvMediaSurfAllocAttr surface_alloc_attr[8];
  uint32_t num_surface_alloc_attr = 0;
  surface_alloc_attr[0].type  = NVM_SURF_ATTR_WIDTH;
  surface_alloc_attr[0].value = width;
  surface_alloc_attr[1].type  = NVM_SURF_ATTR_HEIGHT;
  surface_alloc_attr[1].value = height;
  surface_alloc_attr[2].type  = NVM_SURF_ATTR_CPU_ACCESS;
  surface_alloc_attr[2].value = NVM_SURF_ATTR_CPU_ACCESS_UNCACHED;
  num_surface_alloc_attr = 3;
  
  // Surface type
  NVM_SURF_FMT_DEFINE_ATTR(surface_format_attr);
  NVM_SURF_FMT_SET_ATTR_RGBA(surface_format_attr,RGBA,UINT,8,PL);
  NvMediaSurfaceType surface_type = NvMediaSurfaceFormatGetType(surface_format_attr, NVM_SURF_FMT_ATTR_MAX);
  
  // Create new image
  image_frame = NvMediaImageCreateNew(nvmedia_device_,
                                       surface_type,
                                       surface_alloc_attr,
                                       num_surface_alloc_attr,
                                       0);
  jpeg_encoder = NvMediaIJPECreate(nvmedia_device_,
                                       surface_type,
                                       MAX_OUTPUT_BUFFERING,
                                       MAX_BITSTREAM_SIZE);

I get the error:
“Invalid input format specified”

To find out which surface types JPEGCreate would allow, I cycled through:

for (int i=0; i < 2000; i++)
{
 jpeg_encoder = NvMediaIJPECreate(nvmedia_device_, i,MAX_OUTPUT_BUFFERING, MAX_BITSTREAM_SIZE);
 if (jpeg_encoder)
 {
   // print i
   // NvMediaIPEGDestroy
 }
}

Further question.

Does JPEG converter work with yuv422 in Planar configuration? I get an Error 7 when I use the function NvMediaIJPEFeedFrame.

If I use NvMediaIJPEFeedFrame with yuv420 it works.

Edit:
Answering my own question:
“Image Encode Processing provides the ability to encode processed YUV 420/RGB surface inputs to H.264, H.265, and JPEG formats.” From http://docs.nvidia.com/drive/nvvib_docs/index.html#page/NVIDIA%2520DRIVE%2520Linux%2520SDK%2520Development%2520Guide%2FMultimedia%2Fmultimedia_guide.html%23wwpID0E0RG0HA

So my first question remains. Why I get an error on the RGBA types I try?

From my understanding regarding your provided link, these functions operate only on NvMediaVideoSurface.

I am working with NvMediaImageSurfaces. And my question is regarding the “NvMedia Image Domain” documentation.

Do we have conversion from/to YUV-RGB in NvMedia library for NvMediaImage?

Answering my own question again.

It appears the function is NvMedia2DBlitEx:
http://docs.nvidia.com/drive/nvvib_docs/NVIDIA%20DRIVE%20Linux%20SDK%20Development%20Guide/baggage/group__blit.html#ga2248b8312152b4f88f7ef2462032833a

"A straight pixel copy between surfaces of the same dimensions (but not necessary the same bit depth or even color format) is issued by:
NvMedia2DBlitEx(i2d, dst, NULL, src, NULL, NULL, NULL);
"

sorry, wrong posting. Trying to delete it.

sorry, wrong posting. Trying to delete it.

Hello

I am trying to do dwImageNvMedia (its .img NvMediaImage) jpeg compression on both formats RGBA and YUV420.
I have managed to compress YUV420 format with:

jpegEncoder = NvMediaIJPECreate(device, NvMediaSurfaceType_Image_YUV_420 ,   (uint8_t) 1,   (10 * 1024 * 1024) );
// In loop
dwSensorCamera_readFrame(&frameHandle, sibling, 300000, cameraSensor);
dwSensorCamera_getImageNvMedia(&frameNVMyuv, DW_CAMERA_PROCESSED_IMAGE, frameHandle);
dwImageFormatConverter_copyConvertNvMedia(frameNVMrgba, frameNVMyuv, yuv2rgba);
dwSensorCamera_returnFrame(&frameHandle);
// outside the loop:
NvMediaIJPEFeedFrame(jpegEncoder, frameNVMyuv->img, 75);

but I get a dark green image when I decode that jpeg. So: am I compressing it wrong? Why I cannot compress the YUV directly?

On the other hand, when trying to comrpees RGBA with:

jpegEncoder = NvMediaIJPECreate(device, NvMediaSurfaceType_Image_YUV_420 ,   (uint8_t) 1,   (10 * 1024 * 1024) );
// .....
NvMediaIJPEFeedFrame(jpegEncoder, frameNVMrgba->img, 75);

It gives and error. And this leaves me with NO OPTIONS to generate camera dwImageNvMedia jpeg compressions.
Why is not RGBA jpeg compression supported if the flags are there to be used?

How could I do most efficiently dwImageNvMedia images compression? Please some help here.

Could you check the compression workflow in NVMedia JPEG encoder sample(https://docs.nvidia.com/drive/nvvib_docs/index.html#page/NVIDIA%20DRIVE%20Linux%20SDK%20Development%20Guide%2FMultimedia%2Fnvmedia_nvmimg_jpgenc.html%23)

@SivaRamaKrishna

Of course, I already have. As you can infer from my comment I am already capable of performing NVMedia JPEG encoding of YUV NvMediaImages, but with the wrong output.
The point is, I am not able of:

  • Performing encoding of RGBA NvMediaImage(s)
  • When coupled with a camera reading thread, I can encode YUV frames coming out of dwSensorCamera_getImageNvMedia but it does encode nothing (green image output) if encoding after dwSensorCamera_returnFrame.

Please, indicate how to:

Are the questions clear?

Regards