Some Questions on video_encode from Multimedia API


I’m learning the source code of the example video_encode from Multimedia API, and found the following statements.

// It is necessary that Capture Plane format be set before Output Plane
    // format.
    // Set encoder capture plane format. It is necessary to set width and
    // height on thr capture plane as well
    ret =
        ctx.enc->setCapturePlaneFormat(ctx.encoder_pixfmt, ctx.width,
                                      ctx.height, 2 * 1024 * 1024);
    TEST_ERROR(ret < 0, "Could not set output plane format", cleanup);

Since this video_encode command line accept the width and height, and usually even 4K YUV Raw video doesn’t generate a 2M packet, here the 2 * 1024 * 1024 is just a assumption right ?

Another question is that does this video_encode example only accept a YUV420 raw video file ? Does it write out the H264 JAL stream from the function ?

static int
write_encoder_output_frame(ofstream * stream, NvBuffer * buffer)
    stream->write((char *) buffer->planes[0].data, buffer->planes[0].bytesused);
    return 0;

A bit confused here that the programs set V4L2_PIX_FMT_YUV420M as the output plane, so I assume it means the encoded packet contains the YUV420 pixels.

ret =
        ctx.enc->setOutputPlaneFormat(V4L2_PIX_FMT_YUV420M, ctx.width,
    TEST_ERROR(ret < 0, "Could not set output plane format", cleanup);

Sorry just started to use the TX2 board, not sure a lot of details.

Thank you very much.


If you mean H264 NAL stream, Yes.

I guess you get confused about output plane and capture plane of v4l2.
You may check

Hi zhoub,

It’s better to look through the documents about nVIDIA MultimediaAPI and Video for Linux 2.

“OUTPUT” is not the output from the encoder, but it’s the input for YUV420 images into the encoder.
“CAPTURE” is the output from the encoder for H.264 or H.265 encoded data.
These words are in the V4L2 world.

If you use the 4K resolution, the size of capture plane buffer is set more than 2MB,
because sometimes H.264 data from the TX2 encoder becomes about 3MB.

Best Regards

Appreciated your definitely answers ! Thank you very much guys ! I’d continue to investigate !