L4T Multimedia API Reference

31.1 Release

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

Requirements

  • Camera
  • Display


Overview

This sample demonstrates video capture for four video streams coming directly from camera sensors, where the streams have different resolutions. Three of the streams go through the encoding process and are saved as H.264 or H.265 files. The fourth stream provides full resolution and uses NVIDIA® TensorRT to perform object detection. If target object is detected, it will draw a bounding box around the object on the frame. Finally, the frame with the bounding box is rendered on the display and simultaneously encoded as an H.264 or H.265 file.


Building and Running

Prerequisites

To build

  1. Ensure the following variable is set to 1 by making the following change in the Makefile:
      ENABLE_TRT := 1
    
  2. Enter:
    $ cd frontend
    $ make
    

To run

  • Enter:
     $ ./frontend --deploy ../../data/Model/GoogleNet_three_class/GoogleNet_modified_threeClass_VGA.prototxt \
         --model ../../data/Model/GoogleNet_three_class/GoogleNet_modified_threeClass_VGA.caffemodel \
         --no-preview
    

To quit

  • Enter q.

To view command-line options:

  • Enter:
     $ cd frontend
     $ ./frontend -h
    


Flow

The following diagrams illustrate the flow of data through this sample.

Detailed Buffer Management

Detailed Buffer Management

Buffer Flow of the Frontend Using TensorRT

Buffer Flow of the Frontend Using TensorRT
   $ ./frontend --deploy ../../data/Model/GoogleNet_three_class/GoogleNet_modified_threeClass_VGA.prototxt \
       --model ../../data/Model/GoogleNet_three_class/GoogleNet_modified_threeClass_VGA.caffemodel


Key Classes and Methods

For information on libargus, see Libargus Camera API. For information on EGLStream, see documentation on the Khronos web site.

StreamConsumer Class

The sample defines StreamConsumer as an abstracted class. It is not imported from other libraries.

ClassDescription
StreamConsumerA base class of the libargus OutputStream consumer. It contains a dedicated thread to poll frames from Argus::OutputStream.

The following table describes key StreamConsumer members.

MembersDescription
setOutputStreamSets OutputStream which be used to create the FrameConsumer.
getSizeGets stream resolution.
threadInitializeVirtual method that initializes the consumer thread.
threadExecuteVirtual method that manages the thread loop.
threadShutdownVirtual method that destroys the consumer thread.
processFrameVirtual method that handles one frame.

VideoEncoder Class

The sample defines VideoEncoder as an abstracted class. It is not imported from other libraries.

ClassDescription
VideoEncoderThis is a utility class to simplify the use of V4L2 video encoder.

The following table describes key VideoEncoder members.

MembersDescription
VideoEncoderConstructor in which to specify resolution, output video filename, and select encoding format.
initializeInitialize video encoder and stream consumer.
shutdownDestroy resources.
setBufferDoneCallbackSet callback to return buffer to caller.
encodeFromFdFeed the encoder with a new buffer.

VideoStreamConsumer Class

The sample defines VideoStreamConsumer as an abstracted class. It is not imported from other libraries.

ClassDescription
VideoStreamConsumerThis class is a derived class of StreamConsumer to support video encoding. It reuses the VideoEncoder object for video encoding.

The following table describes key VideoStreamConsumer members.

MembersDescription
VideoEncodeStreamConsumerConstructor in which to specify the name of the consumer, output video filename and select encoding format.
threadInitializeInitializes the video encoder and stream consumer.
threadShutdownDestroys resources.
processFrameReceives frames and pushes them to the encoder.

TRTStreamConsumer Class

The sample defines TRTStreamConsumer as an abstracted class. It is not imported from other libraries.

ClassDescription
TRTStreamConsumerThis class is a derived class of StreamConsumer to support TensorRT (GIE) inference. It also has a VideoEncoder object to support video encoding.

The following table describes key TRTStreamConsumer members.

MembersDescription
TRTStreamConsumerConstructor in which to specify the name of the consumer, output video filename and select encoding format.
threadInitializeInitializes TensorRT context, video encoder and stream consumer.
threadShutdownDestroys resources.
processFrameReceives frames and prepares them for the TensorRT inference.
setDeployFileSets the deploy file for building the TensorRT context.
setModelFileSets the model file for building the TensorRT context.
RenderThreadProcLoops to draw the bounding box, render the frame, and encode the video.
TRTThreadProcLoops to do the TensorRT inference.