How to install FFmpeg with CUDA on Fedora?
- User
How to install FFmpeg with CUDA on Fedora?
- Assistant
How to install FFmpeg with CUDA on Fedora?
Installing FFmpeg with CUDA on Fedora involves several steps, mainly ensuring that your system meets all the necessary requirements, installing CUDA itself, and then compiling FFmpeg with CUDA support. This process requires a Nvidia GPU that supports CUDA, the Nvidia drivers for your GPU, and patience during the compilation process. Here is a step-by-step guide:
First, you need to install the proprietary Nvidia drivers since the open-source Nouveau drivers do not support CUDA:
Disable Nouveau drivers: Edit /etc/default/grub and add rd.driver.blacklist=nouveau nouveau.modeset=0 to the GRUB_CMDLINE_LINUX line. Then, regenerate your Grub configuration:
sudo grub2-mkconfig -o /boot/efi/EFI/fedora/grub.cfg # For UEFI Systems
sudo grub2-mkconfig -o /boot/grub2/grub.cfg # For BIOS Systems
Install Nvidia drivers: The easiest way to install Nvidia drivers on Fedora is using the RPM Fusion repository. Enable it and install the drivers:
sudo dnf install https://download1.rpmfusion.org/free/fedora/rpmfusion-free-release-$(rpm -E %fedora).noarch.rpm
sudo dnf install https://download1.rpmfusion.org/nonfree/fedora/rpmfusion-nonfree-release-$(rpm -E %fedora).noarch.rpm
sudo dnf update -y
sudo dnf install akmod-nvidia
sudo dnf install xorg-x11-drv-nvidia-cuda
Reboot your system.
Download CUDA: Visit the NVIDIA CUDA Downloads page and select the distribution based download options suitable for Fedora. Download the runfile (local) installer for the version that matches your Fedora version.
Install CUDA Toolkit: Change the permissions of the downloaded runfile and execute it:
chmod +x cuda_<version>_linux.run
sudo ./cuda_<version>_linux.run --override
Follow the on-screen instructions to complete the installation. Be sure to select the option to install the CUDA Toolkit and the samples when you get to that step. It's best to accept the default installation locations.
Update your PATH: Add the CUDA binaries to your PATH. Edit ~/.bashrc or ~/.bash_profile (depending on your shell configuration) and append:
export PATH=/usr/local/cuda/bin:$PATH
export LD_LIBRARY_PATH=/usr/local/cuda/lib64:$LD_LIBRARY_PATH
Then, source your ~/.bashrc or ~/.bash_profile:
source ~/.bashrc # or source ~/.bash_profile
Install dependencies: Install the required dependencies for compiling FFmpeg:
sudo dnf groupinstall "Development Tools"
sudo dnf install yasm nasm make automake gcc gcc-c++ kernel-devel cmake git
# FFmpeg dependencies
sudo dnf install libass-devel freetype-devel libvorbis-devel libx264-devel libx265-devel libfdk-aac-devel
Clone FFmpeg: Clone the FFmpeg source code:
git clone https://git.ffmpeg.org/ffmpeg.git ffmpeg
cd ffmpeg
Configure FFmpeg: Run the configure script with --enable-cuda, --enable-cuvid, --enable-nvenc and specify the CUDA toolkit path if it is not in the default location:
./configure --enable-cuda-nvcc --enable-cuvid --enable-nvenc --enable-nonfree --enable-libnpp --extra-cflags=-I/usr/local/cuda/include --extra-ldflags=-L/usr/local/cuda/lib64
Compile and install FFmpeg:
make -j$(nproc)
sudo make install
Verify FFmpeg with CUDA support:
ffmpeg -encoders | grep nvenc
This should list the NVENC-based encoders available in your FFmpeg installation.
Congratulations! You've successfully installed FFmpeg with CUDA support on Fedora. This will enable hardware-accelerated encoding and decoding, enhancing performance for video processing tasks that can utilize the GPU.