JPEG encoding is not continuous

Hello

Our development environment is as follows:

  1. NANO custmize board
  2. Jetpack 4.5.1
  3. Carmera Input : Pixel format - YUV422, resolution -1920x1080, frame - 30

I am trying to do JPEG encoding using the 12_camera_v4l2_cuda source of Jetson Multimedia api.
Jpeg encoding binding source refer to the following.

The 12_camera_v4l2_cuda sources for combining jpeg encoding refer to the following.

However, JPEG encoding is not continuous as shown below.

-rw-rw-r-- 1 nvidia nvidia 134364 Oct 18 07:34 output001.jpg
-rw-rw-r-- 1 nvidia nvidia      0 Oct 18 07:34 output002.jpg
-rw-rw-r-- 1 nvidia nvidia      0 Oct 18 07:34 output003.jpg
-rw-rw-r-- 1 nvidia nvidia      0 Oct 18 07:34 output004.jpg

camera_v4l2_cuda.cpp (24.5 KB)
camera_v4l2_cuda.h (3.5 KB)

Should encoding take care of the synchronization?
Is there a function about that?

Hi,
The patch is for r28 releases. For r32(Jetpack 4) releases, please call NvBufferTransform() to convert YUV422 to I420 and then encode to JPEG.

Thank you for your reply.

The attached source(r32(Jetpack 4)) does Jpeg encoding after NvBufferTransform(YUV422 to YUV420P).
camera_v4l2_cuda.cpp (27.0 KB)
camera_v4l2_cuda.h (3.5 KB)

                /*  Convert the camera buffer from YUV422 to YUV420P */
                if (-1 == NvBufferTransform(ctx->g_buff[v4l2_buf.index].dmabuff_fd, ctx->render_dmabuf_fd,
                            &transParams))
                    ERROR_RETURN("Failed to convert the buffer");
...
            /* Preview */
            // ctx->renderer->render(ctx->render_dmabuf_fd);
            write_jpeg(ctx->render_dmabuf_fd, ctx->frame);

It’s still not continuous.

-rw-r--r--  1 nvidia nvidia  123275 Oct 19 08:09 output001.jpg
-rw-r--r--  1 nvidia nvidia  123212 Oct 19 08:09 output002.jpg
-rw-r--r--  1 nvidia nvidia       0 Oct 19 08:09 output003.jpg
-rw-r--r--  1 nvidia nvidia       0 Oct 19 08:09 output004.jpg
-rw-r--r--  1 nvidia nvidia       0 Oct 19 08:09 output005.jpg
-rw-r--r--  1 nvidia nvidia       0 Oct 19 08:09 output006.jpg

Is there a way to synchronize it?

Hi,
Please reset m_Size to width * height * 1.5, after saving the JPEG file, and call next encodeFromFd()

Result is the same

    // m_Size = (ctx->cam_w * ctx->cam_h) * 3 / 2;
    m_Size = (ctx->cam_w * ctx->cam_h) * 1.5;
-rw-rw-r-- 1 nvidia nvidia 122665 Oct 20 02:09 output001.jpg
-rw-rw-r-- 1 nvidia nvidia 122488 Oct 20 02:09 output002.jpg
-rw-rw-r-- 1 nvidia nvidia      0 Oct 20 02:09 output003.jpg
-rw-rw-r-- 1 nvidia nvidia      0 Oct 20 02:09 output004.jpg

Is there no API waiting for JPEG encoding to finish?

Hi,
Please new/delete NvJpegEncoder in each JPEG encode. The class is demonstrated in 05_jpeg_encode sample and as you have tried, it supports single JPEG encoding.

1 Like

Hello,
Jpeg encoding was checked normally with the following source.

    char filename[256];
    sprintf(filename, "output%03u.jpg", (unsigned) frame);

    std::ofstream *outputFile = new std::ofstream(filename);
    if (outputFile)
    {
        NvJPEGEncoder *jpegEncoder;
        unsigned char *outputBuffer;
        unsigned long size = (1920 * 1080) * 1.5;

        outputBuffer = new unsigned char[size];
        unsigned char *buffer = outputBuffer;

        jpegEncoder = NvJPEGEncoder::createJPEGEncoder("jpenenc");
        jpegEncoder->encodeFromFd(dest_dma_fd, JCS_YCbCr, &buffer, size);
        outputFile->write((char *)buffer, size);
        delete jpegEncoder;
        delete outputFile;
        delete outputBuffer;
    }
    else ERROR_RETURN("Failed to initialize camera device");

Thank you for your help.

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