How to Use Intel QSV for HEVC Encoding in FFmpeg

This article provides a practical guide on how to leverage Intel Quick Sync Video (QSV) hardware acceleration for HEVC (H.265) video encoding using FFmpeg. You will learn how to verify your system compatibility, construct basic and advanced FFmpeg commands, and configure rate control settings to achieve high-speed, high-quality video transcodes with minimal CPU usage.

Prerequisites and System Verification

To use Intel QSV for HEVC encoding, your system must meet the following requirements: * An Intel processor with integrated graphics (Gen 6 Skylake or newer for 8-bit HEVC; Gen 7 Kaby Lake or newer for 10-bit HEVC) or a dedicated Intel Arc GPU. * Up-to-date Intel graphics drivers installed on your operating system. * A build of FFmpeg compiled with QSV support. You can check if your FFmpeg installation supports the QSV HEVC encoder by running the following command in your terminal:

ffmpeg -encoders | grep hevc_qsv

If the command returns a line containing hevc_qsv (codec hevc), your FFmpeg build is ready for Intel QSV HEVC encoding.

Basic QSV HEVC Encoding Command

To encode a video to HEVC using Intel QSV hardware acceleration, specify hevc_qsv as the video encoder utilizing the -c:v flag.

ffmpeg -i input.mp4 -c:v hevc_qsv -c:a copy output.mp4

In this command: * -i input.mp4: Specifies the input video file. * -c:v hevc_qsv: Uses the Intel QSV HEVC hardware encoder for the video stream. * -c:a copy: Copies the audio stream without re-encoding to save processing time. * output.mp4: The resulting hardware-accelerated HEVC video file.

Advanced Encoding and Quality Control

To optimize your output, you can control the bitrate, quality, and speed of the encoding process using specific QSV parameters.

Intelligent Constant Quality (ICQ)

For most encoding tasks, Intelligent Constant Quality (ICQ) is the recommended rate control method. It acts like CRF (Constant Rate Factor) in x264/x265, adjusting the bitrate dynamically to maintain consistent visual quality.

ffmpeg -i input.mp4 -c:v hevc_qsv -global_quality 20 -preset slow output.mp4

Constant Bitrate (CBR) and Variable Bitrate (VBR)

If you require a specific file size or streaming bandwidth, you can use VBR or CBR.

For Variable Bitrate (VBR):

ffmpeg -i input.mp4 -c:v hevc_qsv -b:v 5M -maxrate 8M -bufsize 16M output.mp4

For Constant Bitrate (CBR):

ffmpeg -i input.mp4 -c:v hevc_qsv -b:v 5M -maxrate 5M -bufsize 10M output.mp4

Full Hardware Pipeline (Decoding and Encoding)

For maximum performance, you can offload both the decoding of the input file and the encoding of the output file to the Intel GPU. This prevents bottlenecks caused by transferring video frames back and forth between system RAM and GPU memory.

If your input file is an H.264 video, use the following command to enable a full hardware pipeline:

ffmpeg -hwaccel qsv -c:v h264_qsv -i input.mp4 -c:v hevc_qsv -global_quality 20 output.mp4