Issue of jpegencoder jp5.1.1

I have to capture a rectangle from the source nv12 picture and save it named ''roi.jpg" and then save the source picture named “src.jpg”
I modify the sample 05 ,the roi.jpg is ok but the src.jpg is not ok. Here is my code and the pictures
./jpeg_encode ~/src.nv12 1920 1080 ~/roi.jpg -f 2
jpeg_encode.7z (938.4 KB)

My idea is like that

jpegenc = NvJPEGEncoder::createJPEGEncoder("jpenenc");
jpegenc->setCropRect(100,100,200,300); //crop a rect
jpegenc->encodeFromFd(dst_dma_fd, JCS_YCbCr, &out_buf, out_buf_size, ctx.quality);

jpegenc->setCropRect(0,0,1920,1080); //crop a rect
jpegenc->encodeFromFd(dst_dma_fd, JCS_YCbCr, &src_buf, src_size, ctx.quality);

I don’t know if I can use the jpeg encoder like this?

Hi,
This use-case may not be tested. We will check and suggest next.

Hi,
Please try like:

jpegenc = NvJPEGEncoder::createJPEGEncoder("jpenenc");

jpegenc->encodeFromFd(dst_dma_fd, JCS_YCbCr, &src_buf, src_size, ctx.quality);

jpegenc->setCropRect(100,100,200,300); //crop a rect
jpegenc->encodeFromFd(dst_dma_fd, JCS_YCbCr, &out_buf, out_buf_size, ctx.quality);

To encode the full frame first, and then set crop region to encode the ROI.

if the fd wiil be changed, I want to save the srcfdx and the roi ,can I do it like this

jpegenc = NvJPEGEncoder::createJPEGEncoder("jpenenc");

jpegenc->encodeFromFd(srcfd1, JCS_YCbCr, &src_buf, src_size, ctx.quality); // first picture
jpegenc->setCropRect(100,100,200,300); //crop a rect
jpegenc->encodeFromFd(srcfd1, JCS_YCbCr, &out_buf, out_buf_size, ctx.quality);

jpegenc->encodeFromFd(srcfd2, JCS_YCbCr, &src_buf, src_size, ctx.quality);// second picture
jpegenc->setCropRect(100,100,200,300); //crop a rect
jpegenc->encodeFromFd(srcfd2, JCS_YCbCr, &out_buf, out_buf_size, ctx.quality);

or I must create a new jpegenc?

Hi,
If the source resolution is identical(such as 1920x1080), you can create one NvJpegEncoder for encoding the source frames. And if cropped resolution is identical(such as 200x300), you can create the other NvJpegencoder to encode cropped frames. And please call NvBufferTransform() to crop ROI instead of calling setCropRect()

So that there are two NvJpegEncoders. One is for encoding 1920x1080 and the other is for encoding 200x300. And do cropping by calling NvBufferTransform()

Source frame’s resolution is identical but cropped resolution is not indentical. Can I do it like that

jpegenc = NvJPEGEncoder::createJPEGEncoder("jpenenc");

jpegenc->encodeFromFd(srcfd1, JCS_YCbCr, &src_buf, src_size, ctx.quality); // 1920x1080
jpegenc->setCropRect(100,100,200,300); //crop a rect
jpegenc->encodeFromFd(srcfd1, JCS_YCbCr, &out_buf, out_buf_size, ctx.quality);

jpegenc->encodeFromFd(srcfd2, JCS_YCbCr, &src_buf, src_size, ctx.quality);// 1920x1080
jpegenc->setCropRect(300,100,400,300); //crop a rect
jpegenc->encodeFromFd(srcfd2, JCS_YCbCr, &out_buf, out_buf_size, ctx.quality);

Hi,
This use-case does not work properly. Will check with our teams and see if we can support it in future release. On current releases, please re-create NvJpegEncoder once the resolution changes.

That means if the resolution is not identical, i’d better to delete old jpegenc and create a new one and use NvBufferTransform to instead of setcrop()?

Hi,
Please try the method and see if it works:

  1. Create one NvJpegEncoder for encoding full frames. This is for encoding 1920x1080 frames
  2. Create the other NvJpegEncoder for encoding cropped regions. Please run like:
// srdfd1
jpegenc->setCropRect(100,100,200,300); //crop a rect
jpegenc->encodeFromFd(srcfd1, JCS_YCbCr, &out_buf, out_buf_size, ctx.quality);
// srdfd2
jpegenc->setCropRect(300,100,400,300); //crop a rect
jpegenc->encodeFromFd(srcfd2, JCS_YCbCr, &out_buf, out_buf_size, ctx.quality);

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