TJCUT
October 19, 2022, 12:58am
1
Hello
Our development environment is as follows:
NANO custmize board
Jetpack 4.5.1
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.
Hi Allen,
In the pre-release sample, you can see the camera frame is sent to renderer via Fd:
// Render the frame into display
if (v4l2_buf->m.planes[0].bytesused)
ctx->renderer->render(buffer->planes[0].fd);
And you should replace it with the code in 09_camera_jpeg_capture
{
unsigned long size = JPEG_BUFFER_SIZE;
unsigned char *buffer = m_OutputBuffer;
m_JpegEncoder->encodeFromFd(fd, JCS_YCbCr, &buffer, size);
outputFile->write((char *)buffer, siz…
The 12_camera_v4l2_cuda sources for combining jpeg encoding refer to the following.
Hi Allen,
Please follow the steps to complete the JPEG encoding function.
1 Run the command
$ gst-launch-1.0 v4l2src device=/dev/video0 num-buffers=300 ! ‘video/x-raw,width=1920,height=1080,format=(string)UYVY’ ! nvvidconv ! ‘video/x-raw(memory:NVMM),format=(string)NV12’ ! nvoverlaysink
With output format being set, it should work fine.
2 Try the pre-release sample attached. You should see preview by running
$ ./camera_v4l2_cuda -d /dev/video0 -s 1920x1080 -f UYVY -n 30
3 Refer to 09_came…
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.
TJCUT
October 19, 2022, 8:18am
4
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()
TJCUT
October 20, 2022, 2:16am
6
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
TJCUT
October 20, 2022, 5:19am
8
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.
system
Closed
November 9, 2022, 5:18am
10
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.