Jetson Linux API Reference

32.7.1 Release
16_multivideo_encode (multi video transcode)


The multivideo_transcode sample program demonstrates how to transcode multiple video streams in parallel.

The application reads input buffers from a bitstream file, performs decoding, and generates a YUV file, it passes the YUV file to the encoder to encode it back to the desired codec format. It can do transcoding for multipe input streams and generate multiple output, each independent of other.

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


To build

  • Enter:
     $ cd /usr/src/jetson_multimedia_api/samples/16_multivideo_transcode
     $ make

To run

  • Enter:
    $ ./multivideo_transcode num_files <number_of_files> <in-file1> <in-pixfmt1> <out-file1> <out-pixfmt1> <in-file2> <in-pixfmt2> <out-file2> <out-pixfmt2> ... [OPTIONS]

To view supported options


   $ ./multivideo_transcode --help


   $ ./multivideo_transcode num_files 2 ../../data/Video/sample_outdoor_car_1080p_10fps.h264 H264 sample_outdoor_car_1080p_10fps.h265 H265 ../../data/Video/sample_outdoor_car_1080p_10fps.h264 H264 sample_outdoor_car_1080p_10fps_second.vp9 VP9


The following diagram shows the flow through this sample.

  1. The Output Plane of the Decoder receives input in bitstream format and delivers it to the Decoder for decoding.
  2. The Capture Plane of the Decoder transfers decoded YUV frames to the Output Plane of the Encoder to encode.
  3. The Capture Plane of the Encoder transfers encoded frames to the application in bitstream format.
  4. The encoded bitstream is written to a file.
  5. For the Decoder the application supports MMAP at Output Plane and DMABUF at Capture Plane.
  6. For the Encoder the application supports DMABUF at Output Plane and MMAP at Capture Plane.

Key Structure and Classes

The sample uses the following key structures and classes.

Element Description
NvVideoEncoder Contains all video encoding-related elements and functions.
NvVideoDecoder Contains all video decoding-related elements and functions.
encoder_capture_plane_dq_callback A pointer to the thread handler for the encoding capture loop.
dec_capture_loop A pointer to the thread handler for the decoding capture loop as well as encoding output loop.

The NvVideoEncoder class and the NvVideoDecoder class packages all video encoding and decoding 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.
createVideoDecoder Static function to create video decode object.
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.

Classes NvVideoEncoder and NvVideoDecoder contain two key elements each: 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.