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:

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

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.mp4

2. 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.mp4

Constant Bitrate (CBR):

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

Adjusting 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.mp4

Available 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