Jetson Linux API Reference

32.7.5 Release
15_multivideo_encode (multi video encode)

Overview

The multivideo_encode sample application demonstrates how to encode multiple video streams in parallel.

The application reads input buffers from a YUV file, performs H.264, H.265, VP8 or VP9 video encoding, and saves the encoded bitstream to an elementary file. It can do this in parallel for multiple inputs and corresponding outputs.

The application runs on file source simulated input buffers, and so does not require a camera.

Supported video formats are:

  • H.264
  • H.265
  • VP8
  • VP9


Building and Running

Prerequisites

To build

  • Enter:
     $ cd /usr/src/jetson_multimedia_api/samples/15_multivideo_encode
     $ make
    

To run

  • Enter:
    $ multivideo_encode num_files <number_of_files> <in-file1> <in-width1> <in-height1> <encoder-type1> <out-file1> <in-file2> <in-width2> <in-height2> <encoder-type2> <out-file2> [OPTIONS]
    

To view supported options

Enter:

   $ ./multivideo_encode --help

Example

   $ ./multivideo_encode num_files 2 ../../data/Video/sample_outdoor_car_1080p_10fps.yuv 1920 1080 H264 sample_outdoor_car_1080p_10fps.h264 ../../data/Video/sample_outdoor_car_1080p_10fps.yuv 1920 1080 H264 sample_outdoor_car_1080p_10fps_second.h264


Flow

The following diagram shows the flow through this sample.

  • The Output Plane receives input in YUV frame format and delivers it to the Encoder for encoding.
  • The Capture Plane transfers encoded frames to the application in bitstream format.
  • The encoded bitstream is written to a file.
  • For the Output Plane the application supports MMAP, DMABUF, and USRPTR memory types. For the Capture Plane, it supports MMAP memory type.


Key Structure and Classes

The sample uses the following key structures and classes.

Element Description
NvVideoEncoder Contains all video encoding-related elements and functions.
Enc_pollthread A pointer to the thread handler for the encoding capture loop.

The NvVideoEncoder class packages all video encoding-related elements and functions. Key members used in the sample are:

Member Description
output_plane Specifies the V4L2 output plane.
capture_plane Specifies the V4L2 capture plane.
createVideoEncoder Static function to create video encode object.
subscribeEvent Subscribes to event.
setOutputPlaneFormat Set output plane format.
setCapturePlaneFormat Set capture plane format.
dqEvent Dequeues the event reported by the V4L2 device.
isInError Checks if under error state.

Class NvVideoEncoder contains two key elements: output_plane and capture_plane. These objects are derived from class type NvV4l2ElementPlane. The sample uses the following key members:

Element Description
setupPlane Sets up the plane of V4L2 element.
deinitPlane Destroys the plane of the V4L2 element.
setStreamStatus Starts/stops the stream.
setDQThreadCallback Sets 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 the V4L2 buffer.
dqBuffer Dequeues the V4L2 buffer.
getNumBuffers Gets the number of V4L2 buffers.
getNumQueuedBuffers Gets the number of buffers currently queued on the plane.