L4T Multimedia API Reference

32.3.1 Release

 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
07_video_convert

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.


Building and Running

Prerequisites

To build:

  • Enter:
     $ cd $HOME/tegra_multimedia_api/samples/07_video_convert
     $ make
    

To run

  • Enter:
     $ ./video_convert <in-file> <in-width> <in-height> <in-format> <out-file> <out-width> <out-height> <out-format> [OPTIONS]
    

Example

   $ ./video_convert ../../data/Picture/nvidia-logo.yuv 1920 1080 YUV420M test.yuv 1920 1080 YUYV
Note
The video_convert sample consumes a YUV file. If you do not already have a YUV file, you can use the jpeg_decode sample to generate one. For example:
 $ cd $HOME/multimedia_api/samples/06_jpeg_decode/
 $ ./jpeg_decode num_files 1 ../../data/Picture/nvidia-logo.jpg ../../data/Picture/nvidia-logo.yuv

Flow

The following diagram shows the flow of data through the sample.

The video_convert sample converts 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. For example, for YV12 to RGB conversion, set the format argument to YV12.

ret = ctx.conv0->setOutputPlaneFormat(ctx.in_pixfmt, \
            ctx.in_width, \
            ctx.in_height, \
            V4L2_NV_BUFFER_LAYOUT_PITCH);

The above call in the sample sets up a libv4l2 output plane, i.e., receiving input YUV data reading from file, as a pitch-linear memory format. For example, for YV12 to RGB conversion, set the format argument to RGB.

ret = ctx.conv0->setCapturePlaneFormat(ctx.out_pixfmt, \
            ctx.out_width, \
            ctx.out_height, \
            V4L2_NV_BUFFER_LAYOUT_PITCH);

The above call in the sample sets up a libv4l2 capture plane. In this case, it specifies that the libv4l2 capture plane must have pitch-linear memory format, the most common one. Therefore, if the command line indicates the capture plane is instead block-linear (via the --input-nvbl option), the sample adapts to this request by initializing two NvVideoConverter objects, where:

  • First object converts pitch-linear memory format to block-linear memory format. Because the input buffer is block-linear, this object is effectively blocked and the block-linear input buffers are diverted to the second converter.
     ret = ctx.conv0->setCapturePlaneFormat(ctx.in_pixfmt, \
              ctx.in_width, \
              ctx.in_height, \
              V4L2_NV_BUFFER_LAYOUT_BLOCKLINEAR);
    
  • Second object (the main one) converts block-linear memory format to pitch-linear memory format. This allows the pitch-linear output buffer to be dumped to a file.
    ret = ctx.conv1->setOutputPlaneFormat(ctx.in_pixfmt, \
            ctx.in_width, \
            ctx.in_height, \
            V4L2_NV_BUFFER_LAYOUT_BLOCKLINEAR);
    ret = ctx.conv1->setCapturePlaneFormat(ctx.out_pixfmt, \
            ctx.out_width, \
            ctx.out_height, \
            V4L2_NV_BUFFER_LAYOUT_PITCH);
    

The block-linear memory format complies with Tegra hardware.


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.