Transcode Video with HEVC QSV in FFmpeg
This article provides a quick and practical guide on how to leverage Intel Quick Sync Video (QSV) hardware acceleration to transcode videos to the HEVC (H.265) format using FFmpeg. You will learn the basic command syntax, key parameters for controlling quality and speed, and how to configure your command for optimal hardware-accelerated performance.
To transcode a video using Intel’s hardware-accelerated HEVC encoder
(hevc_qsv), your system must have an Intel processor that
supports Quick Sync Video (Skylake generation or newer for HEVC
encoding), up-to-date graphics drivers, and a version of FFmpeg compiled
with QSV support (configured with --enable-libmfx or
--enable-libvpl).
Basic Transcoding Command
To perform a basic transcode using hardware acceleration for both decoding and encoding, use the following command structure:
ffmpeg -hwaccel qsv -c:v h264_qsv -i input.mp4 -c:v hevc_qsv -c:a copy output.mp4-hwaccel qsv: Enables Intel QSV hardware acceleration for the transcoding pipeline.-c:v h264_qsv: Decodes the input H.264 video using QSV (change this based on your source codec, e.g.,hevc_qsvormpeg2_qsv).-i input.mp4: Specifies the input video file.-c:v hevc_qsv: Selects the Intel QSV HEVC hardware encoder for the output.-c:a copy: Copies the audio stream without re-encoding to save time and CPU resources.
Controlling Quality and Bitrate
Using the default settings may not yield the best balance between file size and quality. You can control the output using different rate control methods:
1. Intelligent Constant Quality (ICQ)
ICQ is the recommended rate control method for QSV. It acts like CRF (Constant Rate Factor) in software encoders, adjusting bitrate to maintain a consistent quality level. Lower values result in better quality and larger file sizes.
ffmpeg -hwaccel qsv -i input.mp4 -c:v hevc_qsv -global_quality 20 output.mp4-global_quality: Set this between 1 (highest quality) and 51 (lowest quality). A value of 20 to 23 is generally optimal for 1080p video.
2. Variable Bitrate (VBR)
If you need to target a specific average bitrate while allowing spikes for complex scenes, use VBR:
ffmpeg -hwaccel qsv -i input.mp4 -c:v hevc_qsv -b:v 5M -maxrate 8M output.mp4-b:v 5M: Sets the target average bitrate to 5 Mbps.-maxrate 8M: Sets the maximum peak bitrate to 8 Mbps.
Preset and Speed Settings
You can adjust the encoding speed and compression efficiency
trade-off using the -preset option. QSV supports presets
ranging from 1 (best quality, slowest) to 7 (fastest, lowest quality).
The default preset is 4 (medium).
ffmpeg -hwaccel qsv -i input.mp4 -c:v hevc_qsv -preset 2 -global_quality 20 output.mp4Verifying QSV Support
If you encounter errors, verify that your FFmpeg build supports the QSV HEVC encoder by running the following command in your terminal:
ffmpeg -encoders | grep qsvLook for hevc_qsv in the output list. If it is missing,
you will need to reinstall or recompile FFmpeg with Intel QSV
enablement.