Compile FFmpeg with Vulkan Video Encoding Support
This guide provides a step-by-step walkthrough for building FFmpeg from source with Vulkan video encoding support. By enabling the Vulkan API, FFmpeg can leverage modern cross-vendor GPU hardware acceleration for codecs such as H.264 and HEVC/H.265. Below, you will find the necessary hardware and driver prerequisites, library dependencies, configuration flags, and test commands to ensure your custom build functions properly.
Prerequisites
Before compiling, verify that your environment meets the minimum hardware and software requirements:
- Compatible GPU & Drivers: An AMD, Intel, or
NVIDIA graphics card with drivers supporting Vulkan Video extensions
(
VK_KHR_video_queue,VK_KHR_video_encode_queue,VK_KHR_video_encode_h264, andVK_KHR_video_encode_h265). - Vulkan SDK / Headers: Vulkan headers version 1.3.275 or newer are required to expose the necessary encoding interfaces.
- FFmpeg Source: FFmpeg version 6.1 or later (the master branch is recommended for the latest Vulkan fixes).
Step 1: Install Build Tools and Dependencies
On a Debian/Ubuntu-based distribution, install the essential compilation tools and general dependencies:
sudo apt update
sudo apt install -y \
build-essential \
git \
pkg-config \
nasm \
yasm \
libdrm-dev \
libvulkan-dev \
glslang-toolsNote for Fedora users: Use
sudo dnf install gcc git make pkgconfig nasm yasm vulkan-headers vulkan-loader-devel libdrm-devel glslang.
Step 2: Ensure Modern Vulkan Headers Are Present
Standard distribution packages may contain older Vulkan headers lacking the finalized video encode extensions. If your distribution's packages are out of date, clone and install the official Khronos Vulkan headers locally:
git clone https://github.com/KhronosGroup/Vulkan-Headers.git
cd Vulkan-Headers
cmake -B build -DCMAKE_INSTALL_PREFIX=/usr/local
sudo cmake --install build
cd ..Ensure /usr/local/lib/pkgconfig is included in your
PKG_CONFIG_PATH:
export PKG_CONFIG_PATH="/usr/local/lib/pkgconfig:$PKG_CONFIG_PATH"Step 3: Clone the FFmpeg Source Code
Clone the official FFmpeg git repository:
git clone https://git.ffmpeg.org/ffmpeg.git ffmpeg
cd ffmpegStep 4: Configure the Build
Run the configure script with --enable-vulkan enabled.
You can add other standard codecs and libraries depending on your
requirements.
./configure \
--prefix=/usr/local \
--enable-gpl \
--enable-nonfree \
--enable-vulkan \
--enable-libdrm \
--disable-shared \
--enable-staticReview the configuration summary output at the end of the script
execution. Confirm that vulkan is listed under enabled
features. If the configuration fails, inspect
ffbuild/config.log to determine missing headers or
dependencies.
Step 5: Compile and Install
Compile FFmpeg using all available CPU threads:
make -j$(nproc)
sudo make installStep 6: Verify Vulkan Video Encoding
Check that the Vulkan encoders are registered in your newly compiled binary:
ffmpeg -encoders | grep -i vulkanYou should see output similar to:
h264_vulkan(H.264/AVC via Vulkan)hevc_vulkan(HEVC/H.265 via Vulkan)
To test hardware encoding on a video file, execute:
ffmpeg -hwaccel vulkan -hwaccel_output_format vulkan -i input.mp4 -c:v h264_vulkan output.mp4