How to Use Vulkan Hardware Decoding in FFmpeg

This guide explains how to enable and utilize Vulkan-based hardware acceleration for video decoding in FFmpeg. You will learn the system prerequisites, how to verify hardware and software compatibility, the exact command-line syntax for basic and advanced decoding pipelines, and how to target specific graphics devices using standard Vulkan Video API extensions.


Prerequisites

To decode video using Vulkan in FFmpeg, ensure your system meets the following requirements:

  1. FFmpeg 6.1 or Later: Vulkan Video decoding APIs were stabilized and integrated into FFmpeg starting with version 6.1.
  2. Compatible Hardware and Drivers: A GPU and driver supporting the Vulkan 1.3 standard alongside the official Vulkan Video decoding extensions:
    • VK_KHR_video_queue
    • VK_KHR_video_decode_queue
    • VK_KHR_video_decode_h264
    • VK_KHR_video_decode_h265
    • VK_KHR_video_decode_av1 (for AV1 playback)
    • NVIDIA: Driver 525+ or newer.
    • AMD/Intel on Linux: Mesa 23.1+ (built with video codec support enabled).

Step 1: Verify Hardware and Build Support

Verify that your installed build of FFmpeg was compiled with Vulkan support:

ffmpeg -hwaccels

Look for vulkan in the printed list. If it is missing, install an FFmpeg build configured with --enable-vulkan and --enable-libdrm (on Linux).

Next, confirm your graphics driver exposes the required Vulkan Video extensions:

vulkaninfo | grep VK_KHR_video_decode

If no output appears, update your graphics drivers or check distribution-specific codec enablement flags (e.g., Mesa codec flags on Fedora/openSUSE).


Step 2: Basic Video Decoding

To decode a video using the Vulkan hardware accelerator and re-encode it in software, use the -hwaccel vulkan flag:

ffmpeg -hwaccel vulkan -i input.mp4 -c:v libx264 -crf 20 output.mp4

In this command:

  • -hwaccel vulkan forces FFmpeg to decode the stream on the GPU via Vulkan.
  • The decoded frames are automatically copied back to system memory (RAM) for the software encoder (libx264).

Step 3: High-Performance Decoding (Benchmark or Discard)

To test decoding performance without the bottleneck of writing an output file to disk or copying frames back to CPU memory, output directly to null:

ffmpeg -hwaccel vulkan -hwaccel_output_format vulkan -i input.mp4 -f null -
  • -hwaccel_output_format vulkan keeps the decoded frames inside GPU video memory (VRAM) as Vulkan textures, eliminating the CPU copy overhead.

Step 4: Device Selection in Multi-GPU Systems

If your system contains multiple GPUs (such as an integrated GPU and a dedicated card), explicitly declare which device FFmpeg should initialize:

ffmpeg -init_hw_device vulkan=vk:0 -hwaccel vulkan -hwaccel_device vk -i input.mp4 output.mkv

To list device indices or target a device via index, change 0 to the target GPU index (0, 1, etc.) as reported by vulkaninfo.

On Linux, you can also select the render node directly:

ffmpeg -init_hw_device vulkan=vk:/dev/dri/renderD128 -hwaccel vulkan -hwaccel_device vk -i input.mp4 output.mkv

Step 5: Applying Vulkan GPU Filters

To decode the video, apply hardware-accelerated processing (such as scaling), and keep the data in VRAM, use Vulkan filter graphs:

ffmpeg -hwaccel vulkan -hwaccel_output_format vulkan -i input.mp4 \
-vf "scale_vulkan=1920:1080,hwdownload,format=nv12" \
-c:v libx264 output.mp4
  • scale_vulkan=1920:1080: Scales the frame directly within the Vulkan hardware context.
  • hwdownload,format=nv12: Copies the processed frame back to system memory in the nv12 pixel format for final encoding.