About 06_jpeg_decode

hi ,now i test the 06_jpeg_decode to decode jpeg ,i found when i decode the same jpeg file,the decode-fd decode result is not different with the decode-buffer,use the decode-buffer the yuv color is not normal ,i read the source code ,found maybe the decode-buffer have some bugs about the V4L2_PIX_FMT_YUV422M,because my test jpeg use the decoe-fd result is yuv422640-480_0

so how can i fix the problem,thanks for your help!!!

Please add the lines to decodeToFd():

    fd = cinfo.fd;

    COMP_DEBUG_MSG("Succesfully decoded Buffer fd=" << fd);
+NvBufferParams par;
+NvBufferGetParams (fd, &par);
+printf("pixfmt = %d, YUV420M is %d \n", par.pixel_format, NvBufferColorFormat_YUV420);
    profiler.finishProcessing(buffer_id, false);

And share the prints. Would like to get information of the JPEGs.

hi ,thanks for your help ,i test fount that decodeToFd() decode normal ,that decodeToBuffer way is not normal

root@ubuntu-desktop:/nfsroot/pd/jetson_multimedia_api/samples/06_jpeg_decode_ori# ./jpeg_decode num_files 1 640-480_0.jpg 640x480.yuv --decode-fd
Premature end of JPEG file
pixfmt = 0, YUV420M is 0
Image Resolution - 640 x 480
libv4l2_nvvidconv (0):(802) (INFO) : Allocating (1) OUTPUT PLANE BUFFERS Layout=0
libv4l2_nvvidconv (0):(818) (INFO) : Allocating (1) CAPTURE PLANE BUFFERS Layout=0

Please set pixel format to V4L2_PIX_FMT_YUV420M and try again:

      /* Set conv output plane format */
      ret =
        ctx.conv->setOutputPlaneFormat(V4L2_PIX_FMT_YUV420M, width,
            height, V4L2_NV_BUFFER_LAYOUT_PITCH);
      TEST_ERROR(ret < 0, "Could not set output plane format for conv", cleanup);

      /* Set conv capture plane format */
      ret =
        ctx.conv->setCapturePlaneFormat(V4L2_PIX_FMT_YUV420M, width,
      TEST_ERROR(ret < 0, "Could not set capture plane format for conv", cleanup);

hi DaneLLL,thanks for your help,i use the option --decode-buffer,that way do not use the convert ,so i think you say that will be not usefully ,now i can tell you again is that my jpeg file use the decodeToBuffer to decode not normal,but use the decodeToFd way is normal ,but you tell me to test way is the decodeToFd

that following is my use the decode-buffer decode yuv file ,you can see it

hi DaneLLL,when i modify the function NvJPEGDecoder::decodeToBuffer like following that can decode normally ,so i want to know that whether will have some effections for the V4L2_PIX_FMT_YUV422M
if (cinfo.comp_info[0].h_samp_factor == 2)
if (cinfo.comp_info[0].v_samp_factor == 2)
pixel_format = V4L2_PIX_FMT_YUV420M;
pixel_format = V4L2_PIX_FMT_YUV420M;

The decoded buffer are in V4L2_PIX_FMT_YUV420M although the source is in YUV422. It looks good to do the modification.

hi DaneLLL,thanks for your help ,another question is that when i want to save the decode yuv data for twice in the --decode-fd way,so i add the modify the source code
ret = ctx.conv->output_plane.setupPlane(V4L2_MEMORY_MMAP, 2, true, false);
TEST_ERROR(ret < 0, “Error while setting up output plane for conv”,

 * REQBUF and EXPORT conv capture plane buffers
 * No need to MAP since buffer will be shared to next component
 * and not read in application
ret =
    ctx.conv->capture_plane.setupPlane(V4L2_MEMORY_MMAP, 2,
                                        !ctx.use_fd, false);

Then i qBuffer twice the jpeg decode to output_plane like the following code
just call the following twice,buf i found that write dec yuv file still only have decode once data ,so how can i do can get the twice yuv data?
struct v4l2_buffer v4l2_buf;
struct v4l2_plane planes[MAX_PLANES];

    memset(&v4l2_buf, 0, sizeof(v4l2_buf));
    memset(planes, 0, MAX_PLANES * sizeof(struct v4l2_plane));

    v4l2_buf.index = 0;
    v4l2_buf.m.planes = planes;
    planes[0].m.fd = fd;
    planes[0].bytesused = 1234;

    ret = ctx.conv->output_plane.qBuffer(v4l2_buf, NULL);
    if (ret < 0)
      cerr << "Error while queueing buffer at conv output plane" << endl;
      goto cleanup;

You may not need to use NvVideoConverter. It should work if you call dump_dmabuf() twice right after decodeToFd().

hi DaneLLL ,because i want to decode from the camara cap jpeg ,so if i want to use the decodeToFd way,so i want to sent the jpeg data to decode ,so i want to how to do like the h264 decode to send the data Continuously

For continuous JPEG decoding, you may also refer to 12_camera_v4l2_cuda. please take a look.

hi DaneLLL,thanks for your help ,now i refer the 12_camera_v4l2_cuda,i decode the jpeg file ,and then use the NvBufferTransform to convert the decode data ,then i call the write_video_frame of the 07_video_convert to write the yuv to file ,but i found at the last yuv file have some mosaic ,but the file size is right ,so why?my jpeg file resolution is 1920*1080,and i test some other resolution jpeg file ,i found some is normal ,some is not normal ,so i do not know how to fix it

above is the 800x600 decode yuv file

Looks like the decoded YUVs are in 1920x1088 and with 8 garbage lines at bottom. You may refer to the patch:

to crop the frames into 1920x1080.