How to Compile FFmpeg with Vulkan Support
This guide provides a straightforward walkthrough on how to compile FFmpeg from source with Vulkan support enabled. By integrating Vulkan, you can leverage high-performance, hardware-accelerated video filters and processing pipelines directly on your GPU. This article covers the necessary system prerequisites, the required configuration flags, and the compilation steps to get FFmpeg running with Vulkan hardware acceleration.
Step 1: Install Dependencies and Vulkan SDK
To compile FFmpeg with Vulkan support, you need the Vulkan headers,
the loader, and a shader compiler (like libshaderc or
glslang) because Vulkan filters in FFmpeg rely on compiling
shaders at runtime.
On Ubuntu/Debian-based systems, install the required development packages by running:
sudo apt update
sudo apt install -y build-essential yasm nasm cmake git pkg-config \
libvulkan-dev vulkan-tools libshaderc-dev libglslang-devFor macOS (using Homebrew):
brew install cmake nasm pkg-config vulkan-headers molten-vk shadercFor Windows, it is recommended to use MSYS2 or cross-compile using a Linux environment, ensuring the Vulkan SDK from LunarG is installed and mapped in your environment variables.
Step 2: Clone the FFmpeg Source Code
Clone the official FFmpeg git repository to your local machine and navigate into the directory:
git clone https://git.ffmpeg.org/ffmpeg.git ffmpeg
cd ffmpegStep 3: Configure the Build with Vulkan Flags
To enable Vulkan, you must explicitly pass the
--enable-vulkan flag to the configure script. You must also
enable a shader compiler, with --enable-libshaderc being
the preferred choice for FFmpeg’s Vulkan filters.
Run the configure command:
./configure \
--enable-nonfree \
--enable-gpl \
--enable-vulkan \
--enable-libshaderc \
--enable-sharedNote: You can add other flags like --enable-libx264
or --enable-libx265 depending on your specific codec
requirements.
If the configuration completes without errors, your build environment
is ready. If it fails, verify that pkg-config can locate
vulkan and shaderc using:
pkg-config --modversion vulkan shadercStep 4: Compile and Install FFmpeg
Compile the binary using multiple CPU cores to speed up the process, then install it to your system:
make -j$(nproc)
sudo make installStep 5: Verify Vulkan Support
After the installation is complete, verify that FFmpeg has been compiled with Vulkan hardware acceleration enabled:
ffmpeg -hwaccelsLook for vulkan in the output list.
To test if the Vulkan filters are working, you can run a test command that uploads a video to the GPU, applies a Vulkan scale filter, and downloads it back to the CPU:
ffmpeg -init_hw_device vulkan=vk -i input.mp4 -filter_hw_device vk -vf "hwupload,scale_vulkan=1920:1080,hwdownload,format=yuv420p" output.mp4