Jetson Linux API Reference

35.4.1 Release
05_jpeg_encode (JPEG encode)

Overview

This sample demonstrates how to:

  • Use the NvBufSurf::NvTransform to convert video 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 /usr/src/jetson_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 /usr/src/jetson_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 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.

NvJPEGEncoder Description
class NvJPEGEncoder Contains the elements and functions to encode JPEG images.

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

NvJPEGEncoder Description
encodeFromFd Encode from FD of buffer exported by V4L2 element.
encodeFromBuffer Encode from pointers of buffer data.