VP9 Hardware Decoding with VAAPI and FFmpeg on Linux

Hardware-accelerated video transcoding significantly reduces CPU usage and speeds up processing times. This guide demonstrates how to use the FFmpeg multimedia framework on Linux to decode VP9 video files using Intel or AMD graphics hardware via the Video Acceleration API (VAAPI) and transcode them efficiently.

Prerequisites

To use VAAPI hardware acceleration, your Linux system must have the correct drivers installed and a GPU that supports VP9 hardware decoding.

  1. Install VAAPI Drivers:

    • For Intel GPUs: Install the intel-media-driver (for Broadwell and newer) or libva-intel-driver (for older GPUs).
    • For AMD GPUs: Install the mesa-va-drivers.
  2. Verify Hardware Support: Run the vainfo command in your terminal. Look for the VP9 entry in the output profiles, such as:

    VAProfileVP9Profile0 : VAEntrypointVLD

    The VAEntrypointVLD indicates that your GPU supports hardware decoding for that profile.

The FFmpeg Transcoding Command

To perform full hardware-accelerated transcoding (where both decoding and encoding happen on the GPU without copying data back to the system RAM), use the following FFmpeg command structure. This example decodes an input VP9 video and encodes it to H.264 using VAAPI:

ffmpeg -hwaccel vaapi -hwaccel_device /dev/dri/renderD128 -hwaccel_output_format vaapi -i input_vp9.webm -c:v h264_vaapi -b:v 5M output.mp4

Command Breakdown

Hybrid Transcoding (Hardware Decoding to Software Encoding)

If you want to use the hardware decoder for VP9 but need the superior compression quality of a CPU-based software encoder (like libx264), omit the -hwaccel_output_format vaapi option. This allows the decoded frames to be copied back to the system memory for the CPU encoder:

ffmpeg -hwaccel vaapi -hwaccel_device /dev/dri/renderD128 -i input_vp9.webm -c:v libx264 -crf 20 output.mp4