L4T Multimedia API Reference

27.1 Release

 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Video Scaling and Color Format Conversion Sample

Overview

The video scaling and color format conversion sample demonstrates how to use the libv4l2 video conversion component for image color formatting and buffer layout conversion.

This sample does not require a camera.

Prerequisites

Before running the sample, you must have the following:

  • README that provides details on the environment requirements to build and run the sample

Additional Details

This sample can be used to convert color format from YV12 to RGB or NV12 to YV12 etc. NVIDIA® Tegra® provides pitch linear and block linear memory format support on input and output. Input and output memory formats do not need to match.

ret = ctx->conv->setOutputPlaneFormat(format.fmt.pix_mp.pixelformat,
                                  format.fmt.pix_mp.width,
                                  format.fmt.pix_mp.height,
                                  NvVideoConverter::LAYOUT_BLOCK);

This call is to set up libv4l2 output plane, i.e., receiving input YUV data for decoder, as a block linear memory format. This is the format that complies with Tegra hardware.

ret = ctx->conv->setCapturePlaneFormat(format.fmt.pix_mp.pixelformat,
                                   format.fmt.pix_mp.width,
                                   format.fmt.pix_mp.height,
                                   NvVideoConverter::LAYOUT_PITCH);

This call sets up libv4l2 capture plane to be pitch linear format. This is the format that is common to software implementation.


Key Structure and Classes

v412_videoconvert_test.h exposes the context_t global structure to manage all the resources in the application. The key fields in that structure are:

  • NvVideoConverter *conv. Performs video format conversion.
  • std::queue < \c NvBuffer * > *conv_output_plane_buf_queue. Holds an output plane queue for the second video converter.

NvVideoDecoder

The NvVideoDecoder class creates a new V4L2 Video Decoder. The following table describes the key NvVideoDecoder members that this sample uses.

MethodDescription
setCapturePlaneFormatSets the format on the decoder capture plane.
setOutputPlaneFormat Sets the format on the decoder output plane.

NvVideoConverter

The NvVideoConverter class packages all video converting related elements and functions. It performs color space conversion, scaling and conversion between hardware buffer memory and software buffer memory. The following table describes the key NvVideoConverter members that this sample uses.

MemberDescription
output_plane Holds the output plane.
capture_planeHolds the capture plane.
waitForIdle Waits until all the buffers queued on the output plane are converted and dequeued from the capture plane. This is a blocking method.
setCapturePlaneFormatSets the format on the converter capture plane.
setOutputPlaneFormat Sets the format on the converter output plane.

NvV4l2ElementPlane

NvV4l2ElementPlane creates an NVv4l2Element plane. The following table describes the key NvV4l2ElementPlane members used in this sample.

Member Description
setupPlane Sets up the plane of V4l2 element.
deinitPlane Destroys the plane of V4l2 element.
setStreamStatus Starts/Stops the stream.
setDQThreadCallbackSets the callback function of the dqueue buffer thread.
startDQThread Starts the thread of the dqueue buffer.
stopDQThread Stops the thread of the dqueue buffer.
qBuffer Queues a V4l2 buffer from the plane.
dqBuffer Dequeues a V4l2 buffer from the plane.
getNumBuffers Gets the number of the V4l2 buffer.
getNumQueuedBuffers Gets the number of the V4l2 buffer in the queue.
getNthBuffer Gets the NvBuffer queue object at index N.