The video_encode sample application demonstrates how to encode H.264/H.265/AV1 video streams.
The application YUV reads input buffers from a file, performs video encoding, and saves the encoded bitstream to an elementary .264, .265, or av1 file.
The application runs on file source simulated input buffers, and so does not require a camera.
Supported video formats are:
Supported YUV formats are:
The application includes comprehensive CUDA support for GPU-accelerated encoding:
isGPUEnabled()On Thor platforms, the application utilizes GPU-accelerated encoding for:
$ cd /usr/src/jetson_multimedia_api/samples/01_video_encode $ make
$ video_encode <in-file> <in-width> <in-height> <encoder-type> <out-file> [OPTIONS]
The application supports several CUDA-related command-line options:
-alloc_type_oplane <num>: Allocation memory type for output plane buffer0: Default (system-managed allocation)1: CUDA Pinned (host memory accessible by GPU)2: CUDA Device (GPU memory)4: Surface ArrayEnter:
$ ./video_encode --help
$ ./video_encode ../../data/Video/sample_outdoor_car_1080p_10fps.yuv 1920 1080 H264 sample_outdoor_car_1080p_10fps.h264
$ ./video_encode input.yuv 1920 1080 H264 output.h264 -alloc_type_oplane 2
This example uses CUDA Device memory for optimal GPU performance.
The following diagram shows the flow through this sample.

When CUDA is enabled, the processing flow includes additional GPU-accelerated paths:
NvBufSurf APIsisGPUEnabled()setCudaMemType()On Thor platforms:
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 | Subscribe event. |
| setOutputPlaneFormat | Sets the output plane format. |
| setCapturePlaneFormat | Sets the capture plane format. |
| dqEvent | Dqueue the event which reports 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. |
The sample includes additional CUDA-specific functionality:
| API Function | Description |
|---|---|
| isGPUEnabled | Checks if GPU configuration is enabled for CUDA processing. |
| setCudaMemType | Sets CUDA memory type (Device/Pinned) when GPU is enabled. |
| setCUDASliceIntrarefresh | Sets CUDA-specific slice intra-refresh parameters. |
| setCudaConstantQp | Sets CUDA-specific constant QP values. |
| API | Description |
|---|---|
NvBufSurf::NvAllocate | Allocates buffer surfaces with CUDA memory type support. |
NVBUF_MEM_CUDA_DEVICE | Enum for CUDA device memory allocation. |
NVBUF_MEM_CUDA_PINNED | Enum for CUDA pinned (host) memory allocation. |
V4L2_CUDA_MEM_TYPE_* | V4L2 controls for CUDA memory type configuration. |
The GPU acceleration provides enhanced capabilities:
| Platform Feature | Thor (T264) | Other Platforms |
|---|---|---|
| CUDA Support | GPU-accelerated | Direct CUDA API |
| Memory Types | GPU-managed | Standard allocation |
| Multi-stream | GPU-scheduled | Application managed |
| Resource limits | Dynamic GPU allocation | Static configuration |