Jetson Linux Multimedia API Reference

32.4.3 Release

 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
05_jpeg_encode

Overview

This sample demonstrates how to:

  • Use the libv4l2 conversion component function to allocate buffer
  • Set up attributes
  • Use the JPEG encode component to encode YUV data to a file.

This sample does not require a camera.


Building and Running

Prerequisites

To build:

  • Enter:
     $ cd $HOME/tegra_multimedia_api/samples/05_jpeg_encode
     $ make
    

To run

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

Example

   $ ./jpeg_encode ../../data/Picture/nvidia-logo.yuv 1920 1080 test.jpg
Note
The jpeg_encode 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/tegra_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 this sample.

Additional Details

The output plane is used to receive input and the capture plane is used to produce output. The YUV data format prior to entering the JPEG encoder can be block, linear, or pitch linear. This results in 2 different encode processes: encodeFromFD and encodeFromBuffer. encodeFromFD allows JPEG encode hardware to process the data directly. encodeFromBuffer requires extra format conversion prior to writing to the JPEG file.


Key Structure and Classes

The struct context_t global structure manages all of the resources in the application.

NvVideoDecoder Description
class NvVideoConverterContains elements and functions regarding video format conversion.
class NvJpegEncoderContains elements and functions to encode JPEG images.

NvVideoConverter contains all video converting related elements and functions. Key members of NvVideoConverter used in the sample are:

NvVideoConverter MemberDescription
output_planeV4l2 output plane.
capture_planeV4l2 capture plane.
waitForIdleWait until all queued output plane buffers are processed and dequeued from the capture plane.
setOutputPlaneFormatSet output plane format.
setCapturePlaneFormatSet capture plane format.

The NvVideoConverter elements output_plane and capture_plane belong to the NvV4l2ElementPlane class. Key members of NvV4l2ElementPlane used in the sample are as follows:

ElementDescription
setupPlaneSetup the plane of V4l2 element.
deinitPlaneDestroy the plane of V4l2 element.
setStreamStatusStart/Stop the stream.
setDQThreadCallbackSet the callback function of the dqueue buffer thread.
startDQThreadStart the thread of the dqueue buffer.
stopDQThreadStop the thread of the dqueue buffer.
qBufferQueue the V4l2 buffer.
dqBufferDequeue the V4l2 buffer.
getNumBuffersGet the number of the V4l2 buffer.
getNumQueuedBuffers Get the number of the V4l2 buffer under queue.
getNthBufferGet the NvBuffer at Index N.

The NvJpegEncoder class contains all of the functions for JPEG encoding. Key members used are:

NvV4l2ElementPlaneDescription
encodeFromFdEncode from FD of buffer exported by V4L2 element.
encodeFromBufferEncode from pointers of buffer data.