How to Use Intel QSV for H.264 in FFmpeg

Intel Quick Sync Video (QSV) utilizes dedicated media processing hardware inside Intel CPUs to deliver fast, power-efficient video encoding and decoding while freeing up the main processor. This guide covers how to set up and execute hardware-accelerated H.264 video encoding using the h264_qsv encoder in FFmpeg, including basic commands, quality control methods, and hardware decoding acceleration.

Prerequisites and Verification

Before running QSV commands, ensure your system meets the following requirements:

  1. Hardware: An Intel processor with integrated graphics supporting Quick Sync Video (Haswell or newer recommended).
  2. Drivers: Up-to-date Intel graphics drivers installed on Windows, or the intel-media-va-driver-non-free package (along with proper permissions to /dev/dri/renderD128) on Linux.
  3. FFmpeg Support: A build of FFmpeg compiled with --enable-libmfx or modern oneVPL support.

To confirm your FFmpeg binary supports the QSV H.264 encoder, run:

ffmpeg -encoders | grep h264_qsv

If configured correctly, the terminal will display h264_qsv in the list of available encoders.

Basic H.264 QSV Encoding

The simplest command decodes the source video via CPU and encodes it using the Intel QSV hardware encoder:

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

In this command:

  • -i input.mp4 specifies the source file.
  • -c:v h264_qsv instructs FFmpeg to use the Intel hardware H.264 encoder.
  • -c:a copy copies the audio stream without re-encoding to save processing time.

Quality and Rate Control Modes

QSV supports several rate control methods to balance visual quality and file size.

1. Intelligent Constant Quality (ICQ)

ICQ is the recommended mode for standard encoding, functioning similarly to x264's CRF mode. It optimizes bitrate according to scene complexity.

ffmpeg -i input.mp4 -c:v h264_qsv -global_quality 23 -c:a copy output.mp4
  • The -global_quality parameter accepts values typically from 1 to 51, where lower values result in higher quality and larger file sizes (20–25 is standard).

2. Variable Bitrate (VBR)

Use VBR when targeting a specific average bitrate:

ffmpeg -i input.mp4 -c:v h264_qsv -b:v 4M -maxrate 6M -c:a copy output.mp4
  • -b:v 4M sets the average target bitrate to 4 Mbps.
  • -maxrate 6M sets the maximum allowable bitrate spike.

3. Constant Bitrate (CBR)

Use CBR for live streaming where bandwidth is strictly limited:

ffmpeg -i input.mp4 -c:v h264_qsv -b:v 4M -maxrate 4M -minrate 4M -bufsize 8M -c:a copy output.mp4

Speed vs. Quality Presets

The h264_qsv encoder includes performance presets: veryfast, faster, fast, medium, slow, and veryslow.

ffmpeg -i input.mp4 -c:v h264_qsv -preset slow -global_quality 22 -c:a copy output.mp4
  • veryfast minimizes hardware usage and maximizes frames per second.
  • veryslow provides the best compression density at the expense of processing speed.

Full Hardware Pipeline (Decode and Encode)

Passing frames between the CPU and GPU introduces a performance bottleneck. To achieve maximum throughput, offload both decoding and encoding to the Intel GPU:

ffmpeg -hwaccel qsv -c:v h264_qsv -i input.mp4 -c:v h264_qsv -global_quality 23 -c:a copy output.mp4

If running on Linux, explicitly define the hardware device to avoid initialization errors:

ffmpeg -init_hw_device qsv=hw -filter_hw_device hw -hwaccel qsv -c:v h264_qsv -i input.mp4 -c:v h264_qsv -global_quality 23 -c:a copy output.mp4