FFmpeg H.264 QSV Hardware Transcoding on Linux

This article provides a step-by-step guide on how to perform hardware-accelerated H.264 video decoding and transcoding using Intel Quick Sync Video (QSV) and FFmpeg on Linux. You will learn how to set up the necessary drivers, verify your system configuration, and execute the exact FFmpeg commands needed to offload the video processing workload from your CPU to your Intel GPU.

Prerequisites and Driver Setup

To utilize QSV hardware acceleration on Linux, you need an Intel processor with integrated graphics (HD Graphics, UHD Graphics, Iris Xe) or a discrete Intel Arc GPU. You must also install the appropriate Intel media drivers and an FFmpeg binary compiled with QSV support.

  1. Install the Intel Media Driver: On Ubuntu/Debian-based systems, install the Intel media driver and VA-API runtimes:

    sudo apt update
    sudo apt install intel-media-va-driver-non-free libmfx1-va-gl libmfx-gen1-va-gl non-free-libs
  2. Verify GPU Access: Ensure your user account belongs to the video and render groups to access the hardware acceleration devices:

    sudo usermod -aG video,render $USER

    (Note: You may need to log out and log back in for these group changes to apply).

  3. Verify FFmpeg QSV Support: Check if your FFmpeg installation supports the h264_qsv decoder and encoder:

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

    Look for h264_qsv in both outputs to confirm compatibility.

The FFmpeg QSV Transcoding Command

To decode an input H.264 video using the hardware-accelerated QSV decoder and transcode it to an H.264 output using the QSV encoder, use the following FFmpeg syntax. This command keeps the video frames entirely in GPU memory (VRAM) during the transcoding process to prevent performance bottlenecks:

ffmpeg -hwaccel qsv -hwaccel_output_format qsv -c:v h264_qsv -i input.mp4 -c:v h264_qsv -b:v 5M output.mp4

Explanation of the Parameters:

Advanced Transcoding with Scaling

If you want to resize (scale) the video while keeping the processing inside the GPU hardware, you must use QSV-specific hardware filters rather than standard software filters. Use the following command to downscale a video to 1080p during the transcoding process:

ffmpeg -hwaccel qsv -hwaccel_output_format qsv -c:v h264_qsv -i input.mp4 -vf "vpp_qsv=w=1920:h=1080" -c:v h264_qsv -b:v 4M output_1080p.mp4