FFmpeg HEVC NVENC: How to Transcode Videos
This article provides a straightforward guide on how to transcode
videos using the hardware-accelerated HEVC encoder
(hevc_nvenc) in FFmpeg. You will learn the system
requirements, the basic command structure, and key configuration options
for controlling quality, speed, and bitrate using NVIDIA graphics
cards.
Prerequisites
To use NVIDIA’s hardware-accelerated HEVC encoder, you need: 1. An NVIDIA graphics card that supports NVENC HEVC encoding (Kepler generation or newer; GTX 960/980 Ti and newer for HEVC). 2. The latest NVIDIA graphics drivers installed. 3. A build of FFmpeg compiled with NVENC support. You can verify this by running the following command in your terminal:
ffmpeg -encoders | grep nvencIf hevc_nvenc appears in the output list, your FFmpeg
installation is ready.
Basic Transcoding Command
The simplest command to transcode an input video to HEVC (H.265) using your GPU is:
ffmpeg -i input.mp4 -c:v hevc_nvenc output.mp4-i input.mp4: Specifies the input file.-c:v hevc_nvenc: Selects the NVIDIA hardware-accelerated HEVC encoder.output.mp4: The resulting output file.
Controlling Quality and Bitrate
To optimize the output file size and visual quality, you should customize the bitrate or rate control mode.
Constant Quality (CQP)
Constant QP (CQP) is the recommended mode for one-pass file-based transcoding where file size is not a strict constraint. Lower values result in higher quality and larger file sizes. A range of 20 to 25 is ideal for most content.
ffmpeg -i input.mp4 -c:v hevc_nvenc -rc constqp -qp 23 output.mp4Constant Bitrate (CBR) and Variable Bitrate (VBR)
If you need to target a specific file size or bandwidth limit, use
the target bitrate option (-b:v).
To set a target bitrate with a maximum peak limit (VBR):
ffmpeg -i input.mp4 -c:v hevc_nvenc -b:v 5M -maxrate:v 8M -bufsize:v 16M output.mp4Adjusting Speed and Quality Presets
NVIDIA’s NVENC hardware offers presets ranging from p1
(fastest performance, lowest quality) to p7 (slowest
performance, highest quality). The default preset is
p4.
To transcode with high quality:
ffmpeg -i input.mp4 -c:v hevc_nvenc -preset p6 -qp 23 output.mp4Complete Practical Example
This command copies the original audio track without re-encoding to save time and preserve audio quality, while transcoding the video to HEVC using high-quality settings:
ffmpeg -i input.mp4 -c:v hevc_nvenc -preset p5 -rc constqp -qp 22 -c:a copy output.mp4