Transcoding Video with FFmpeg h264_qsv
This guide explains how to use the Intel Quick Sync Video (QSV)
hardware-accelerated H.264 encoder, h264_qsv, in FFmpeg. It
covers the prerequisites, basic and advanced command-line syntax, and
how to configure quality and performance settings to achieve fast,
high-quality video transcodes using your Intel CPU or GPU.
Prerequisites
To use Intel QSV hardware acceleration in FFmpeg, your system must meet the following requirements:
- Hardware: An Intel processor with Integrated Graphics (HD, UHD, or Iris Xe) or a dedicated Intel Arc GPU.
- Drivers: Installed Intel Graphics Drivers (Windows) or the Intel Media Driver/oneVPL runtime (Linux).
- FFmpeg Build: A version of FFmpeg compiled with QSV
support (configured with
--enable-libmfxor--enable-libvpl). You can verify support by runningffmpeg -encoders | grep qsvin your terminal.
Basic Transcoding Command
To perform a basic transcode using the h264_qsv encoder,
use the following syntax:
ffmpeg -i input.mp4 -c:v h264_qsv -c:a copy output.mp4-i input.mp4: Specifies the input video file.-c:v h264_qsv: Selects the Intel QSV H.264 hardware encoder for the video stream.-c:a copy: Copies the audio stream without re-encoding to save time and CPU resources.
Controlling Quality and Bitrate
Like software encoders, h264_qsv supports different rate
control methods to balance file size and video quality.
1. Intelligent Constant Quality (ICQ)
This is the recommended mode for general transcoding, as it targets a specific quality level while optimizing the bitrate. Lower values produce higher quality but larger files (typical range is 15 to 30).
ffmpeg -i input.mp4 -c:v h264_qsv -global_quality 20 output.mp42. Constant Bitrate (CBR) and Variable Bitrate (VBR)
To target a specific file size or bandwidth limit, use the standard bitrate flags.
Variable Bitrate (VBR):
ffmpeg -i input.mp4 -c:v h264_qsv -b:v 5M -maxrate 8M -bufsize 16M output.mp4Constant Bitrate (CBR):
ffmpeg -i input.mp4 -c:v h264_qsv -b:v 5M -maxrate 5M -bufsize 10M output.mp4Adjusting Encoding Speed and Quality Presets
The h264_qsv encoder supports speed presets ranging from
veryfast (fastest encoding, lowest quality per bitrate) to
veryslow (slowest encoding, best quality per bitrate). The
default is medium.
ffmpeg -i input.mp4 -c:v h264_qsv -preset slow output.mp4Available presets include: veryfast,
faster, fast, medium,
slow, slower, and veryslow.
Full Hardware Pipeline (Hardware Decoding and Encoding)
To achieve maximum performance, you can offload both the decoding of the input video and the encoding of the output video to the Intel GPU. This minimizes CPU usage and memory copy overhead.
ffmpeg -hwaccel qsv -c:v h264_qsv -i input.mp4 -c:v h264_qsv -global_quality 20 output.mp4-hwaccel qsv: Enables Intel QSV hardware acceleration for decoding.-c:v h264_qsv(before-i): Specifies that the input stream (assuming H.264) should be decoded using QSV.