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-all2. 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 $USERNote: 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 qsvYou 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.mp4Command 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.mp4Command 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
- Error: “Device creation failed”: Ensure your Intel
GPU is recognized by the system by running
ls -l /dev/dri. You should seecard0andrenderD128. - Error: “Permission denied”: Double-check that your
user account has been successfully added to the
rendergroup using thegroupscommand. - Performance bottleneck: Ensure you are not applying
software filters (like software-based scaling) in your FFmpeg pipeline,
as transferring frames back to the CPU memory degrades performance. For
hardware-accelerated scaling, use the QSV filter:
-vf "vpp_qsv=w=1920:h=1080".