L4T Multimedia API Reference

27.1 Release

 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Image Encoder Sample

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.

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.
getNumQueuedBuffersGet 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.