Transcode HEVC Video with FFmpeg QSV on Linux

This article provides a step-by-step guide on how to leverage Intel Quick Sync Video (QSV) hardware acceleration to transcode HEVC (H.265) videos on Linux using FFmpeg. You will learn how to configure your Linux environment, verify Intel driver installations, and run optimized FFmpeg commands for hardware-accelerated decoding and encoding.

Prerequisites

Before starting, ensure your system has an Intel processor that supports Quick Sync Video (Skylake generation or newer is required for HEVC 8-bit/10-bit support).

1. Install Intel Media Drivers

You need the Intel media drivers and development libraries installed on your Linux system. On Ubuntu or Debian-based distributions, run:

sudo apt update
sudo apt install intel-media-va-driver-non-free libmfx1 libvpl2 VA-driver-all

2. Configure User Permissions

To access the GPU hardware interface without root privileges, add your user to the video and render groups:

sudo usermod -aG video,render $USER

Note: Log out and log back in for these changes to take effect.

3. Verify QSV Support in FFmpeg

Verify that your FFmpeg installation supports QSV decoding and encoding by running:

ffmpeg -decoders | grep qsv
ffmpeg -encoders | grep qsv

You should see hevc_qsv listed under both decoders and encoders.


Transcoding Commands

Scenario 1: Transcode HEVC to HEVC (Re-encoding/Compression)

To decode an incoming HEVC stream using the hardware decoder and encode it back to HEVC with a lower bitrate using the hardware encoder, use the following command:

ffmpeg -hwaccel qsv -c:v hevc_qsv -i input.mp4 -c:v hevc_qsv -b:v 4M -c:a copy output.mp4

Command Breakdown: * -hwaccel qsv: Enables Intel QSV hardware acceleration. * -c:v hevc_qsv (before -i): Forces FFmpeg to use the Intel hardware decoder to read the input HEVC file. * -i input.mp4: Specifies the input video file. * -c:v hevc_qsv (after -i): Uses the Intel hardware encoder to write the output HEVC file. * -b:v 4M: Sets the target video bitrate to 4 Mbps. * -c:a copy: Copies the audio stream without re-encoding to save CPU cycles.

Scenario 2: Transcode HEVC to H.264

If you need to transcode a HEVC video to a highly compatible H.264 (AVC) format using full hardware acceleration, run:

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

Command Breakdown: * -c:v h264_qsv: Uses the Intel H.264 QSV hardware encoder. * -global_quality 25: Enables ICQ (Intelligent Constant Quality) mode for dynamic bitrate distribution, where lower numbers represent higher quality (typically ranging from 1 to 51).


Troubleshooting