NVIDIA H265 Encoding Configurations

From RidgeRun Developer Wiki


Problems running the pipelines shown on this page? Please see our GStreamer Debugging guide for help.


Introduction to NVIDIA H265 Encoding Configurations

This wiki is intended to show some common configurations used to tune the H265 encoding that NVIDIA provides using the V4L2 controls. You can visit the NVIDIA V4L2 Video Encoder official documentation for more details.

H265 Controls Mapping

NVIDIA provides different ways to control and use the H265 encoder through V4l2 controls. Some of them are the NvVideoEncoder class from the Video API, and the Accelerated GStreamer Video Encoder feature elements. To show how to modify the different H265 controls we have created the following table containing a mapping between these two options and the actual control.


V4L2 Control Description Gstreamer nvv4l2h265enc Property NvVideoEncoder Class Method (Video API)
Profile H265 encoder profile profile setProfile
I-frame Interval or GOP Size Interval between two I-frames, in number of frames iframeinterval setIFrameInterval
IDR Interval Encoder IDR frame interval idrinterval setIDRInterval
Number of B-frames Number of B-frames between P-frames num-B-frames setNumBFrames
Bitrate Bits per second of the encoded stream bitrate setBitrate
Maximum Bitrate Peak bitrate of the encoded stream in bits per second peak-bitrate setPeakBitrate
Rate Mode Type of rate control (constant or variable) control-rate setRateControlMode
Intra Refresh Slice Interval Slice intra refresh interval, in number of slices SliceIntraRefreshInterval setSliceIntrarefresh
Quantization Parameters Quantization parameter for constant QP mode quant-i*, quant-p*, quant-b* setConstantQp
Quantization Range Minimum and maximum for each frame quantization parameter qp-range setQpRange
Virtual Buffer Size Virtual buffer size in bits vbv-size setVirtualBufferSize
Number of Reference Frames Maximum number of reference frames that can be used num-Ref-Frames setNumReferenceFrames
Insert SPS and PPS at IDR Interval Configuration to enable/disable inserting SPS and PPS explicitly at IDR interval insert-sps-pps setInsertSpsPpsAtIdrEnabled
Insert VUI Enable or disable inserting video usability information in SPS. insert-vui setInsertVuiEnabled
Insert AUD Enable or disable inserting access unit delimiter. insert-aud setInsertAudEnabled
Enable Motion Vector Metadata Enable or disable encoder motion vector reporting EnableMVBufferMeta enableMotionVectorReporting
Hardware Preset Hardware encoder preset type preset-level setHWPresetType
Temporal Trade-off Level Encoder level to drop frames while encoding N/A setTemporalTradeoff
Slice Length Slice length either in terms of MBs or bits N/A setSliceLength
Reconstructed CBR Configure Reconstructed CRC for a session N/A enableReconCRC
ROI Encoding Configure ROI encoding for a session N/A enableROI
ROI Params Configuration to encode a particular region of a frame in high quality N/A setROIParams
Metadata Get encoder output metadata N/A getMetadata
Motion Vector Metadata Get encoder output motion vector metadata N/A getMotionVectors
Input Metadata Provide input metadata for the encoder buffer N/A SetInputMetaParams
External RPS Configure encoder for external RPS control N/A enableExternalRPS
External Rate Control Configure encoder for external rate control N/A enableExternalRC
Extended Color Format Enable or disable setting for extended color format N/A setExtendedColorFormat
All I-frame Encoding Enable or disable all I-Frame encoding N/A setAlliFramesEncode
All I-frame Encoding Enable or disable all I-Frame encoding N/A setAlliFramesEncode
H265 Level Set the H265 encoding level N/A setLevel
Slice Level Encode Enable or disable slice level encoding N/A setSliceLevelEncode

Common Rate Control Modes

The rate control option shown above only allows the constant or variable bitrate options, however, with certain combinations of properties other modes can be achieved, for example:

Mode Required Properties
Constant QP ratecontrol-enable=0, preset-level=0, quant-i-frames, quant-p-frames, quant-b-frames
CBR Single-Pass control-rate=constant_bitrate, bitrate
VBR control-rate=variable_bitrate, bitrate, peak-bitrate
VBR with Minimum QP control-rate=variable_bitrate, ratecontrol-enable=1, bitrate, peak-bitrate, qp-range

NVIDIA H265 Encoding GStreamer Examples

Camera Capture + UDP Streaming

For this example we are using OV5693 Xavier AGX camera at 120 FPS, however, we want our stream to be at 60 FPS, so we use a videorate to drop frames.

IP=127.0.0.1
PORT=12345
gst-launch-1.0 nvarguscamerasrc ! "video/x-raw(memory:NVMM),width=1280,height=720,framerate=120/1" ! videorate max-rate=60 drop-only=true ! queue max-size-buffers=3 leaky=downstream ! nvv4l2h265enc bitrate=2000000 iframeinterval=300 vbv-size=33333 insert-sps-pps=true control-rate=constant_bitrate profile=Main num-B-Frames=0 ratecontrol-enable=true preset-level=UltraFastPreset EnableTwopassCBR=false maxperf-enable=true ! h265parse ! mpegtsmux alignment=7 ! queue ! udpsink clients="${IP}:${PORT}"

This is an optimized pipeline with a maximum latency (from nvarguscamerasrc to udpsink) of 8 ms, as shown in the following diagram created with GstShark.

'Example of encoder latency from video source to UDP sink


To receive the streaming on the client-side you may use the following pipeline:

PORT=12345
gst-launch-1.0 udpsrc port=${PORT} ! tsdemux latency=0 ! h265parse ! avdec_h265 ! queue ! videoconvert ! autovideosink sync=false


For direct inquiries, please refer to the contact information available on our Contact page. Alternatively, you may complete and submit the form provided at the same link. We will respond to your request at our earliest opportunity.


Links to RidgeRun Resources and RidgeRun Artificial Intelligence Solutions can be found in the footer below.