Different outputs from decodeToFd when decoding JPEG image using JetPack 5.1.2 vs 5.0.1

I’m currently working on an application that involves the use of the Jetson Multimedia API for JPEG image decoding. To implement this, I’ve been following the sample provided in this documentation link.

In my application, I need to decode the JPEG images and then convert the resulting decoded images into OpenCV Mats. To achieve this, I’ve opted to use the the decodeToFd function with NvBufSurfaceFromFd and mmap. I chose to use this approach instead of decodeToBuffer, as based on my observations this combination offers better performance and memory utilization.

Here’s a snippet of the code illustrating the approach I’m taking:

/* unchanged code above */
ret = NvBufSurf::NvAllocate(&params, 1, &dst_dma_fd);
/* unchanged code below */

if (ctx.out_file)
    int index = ctx.current_file++;
    // /* Dumping two planes for NV12, NV16, NV24 and three for I420 */
    // dump_dmabuf(dst_dma_fd, 0, ctx.out_file[index]);
    // dump_dmabuf(dst_dma_fd, 1, ctx.out_file[index]);
    // if (out_pixfmt == 2)
    // {
    //     dump_dmabuf(dst_dma_fd, 2, ctx.out_file[index]);
    // }
    NvBufSurface *nvbuf_surf = 0;
    NvBufSurfaceFromFd(dst_dma_fd, (void**)(&nvbuf_surf));

    void *start = mmap(NULL, nvbuf_surf->surfaceList->planeParams.psize[0], PROT_READ | PROT_WRITE, MAP_SHARED, 
      dst_dma_fd, nvbuf_surf->surfaceList->planeParams.offset[0]);

    cv::Mat d_img(height, width, CV_8UC4, (uint8_t*)start, nvbuf_surf->surfaceList->planeParams.pitch[0]);
    cv::cvtColor(d_img, d_img, cv::COLOR_BGRA2BGR);

    cv::imwrite(ctx.out_file_path[index], d_img); //just for verification

The above implementation was producing the expected output on JetPack 5.0.1. However, upon transitioning to the latest JetPack version, 5.1.2, I encountered an issue. While the first decoded image appears as expected, subsequent images are showing the content of the first image instead of their own content.

I’m reaching out to seek assistance in determining whether there might be a bug in the implementation or if I might be misusing the API in some manner. I’ve attached the Makefile Makefile (2.1 KB) and the modified code jpeg_decode_main.cpp (8.8 KB) for your reference.

If you could kindly review the provided information and offer any insights or suggestions, I would greatly appreciate it.

Thank you for your time and assistance.

Best regards,
Romil Aggarwal

This looks same as
NvJPEGDecoder generates the same output if called twice with different input buffer

We are investigating it. Will update when there is further progress.

1 Like

Are there any updates on this? We are running into the same issue and it is a major blocker for us.

We are checking the issue. As a quick solution, you can use software decoding such as
OpenCV: Image file reading and writing

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.

Please try
NvJPEGDecoder generates the same output if called twice with different input buffer - #7 by DaneLLL