How to compile FFmpeg with Cuda hardware accelerator?
How to compile FFmpeg with Cuda hardware accelerator.
STEPS:
1. system required: you must have a nvidia gpu. based on https://developer.nvidia.com/nvidia-video-codec-sdk/download. System Requirements for Video Codec SDK 11
NVIDIA Windows display driver 456.71 or newer
NVIDIA Linux display driver 455.28 or newer
so, if you want to install Video Codec SDK 11, then you should install CUDA-toolkit 11.3.
if you don't know how to install cuda-toolkit, you can check this article.
2. Compiling for Linux
Compiling for Linux
FFmpeg with NVIDIA GPU acceleration is supported on all Linux platforms.
To compile FFmpeg on Linux, do the following:
- Clone ffnvcodec
git clone https://git.videolan.org/git/ffmpeg/nv-codec-headers.git
- Install ffnvcodec
cd nv-codec-headers && sudo make install && cd ~
- Clone FFmpeg's public GIT repository.
git clone https://git.ffmpeg.org/ffmpeg.git ffmpeg/
- Install necessary packages.
sudo apt-get install build-essential yasm cmake libtool libc6 libc6-dev unzip wget libnuma1 libnuma-dev
- Configure
./configure --enable-nonfree --enable-cuda-sdk --enable-libnpp --extra-cflags=-I/usr/local/cuda/include --extra-ldflags=-L/usr/local/cuda/lib64
if this step happen error, looking ffbuild/config.log
may have compute_30 not support your GPU, then you need to change configure file:
using text file editor to edit this document:
maybe in line 4382
if enabled cuda_nvcc; then
nvcc_default="nvcc"
nvccflags_default="-gencode arch=compute_30,code=sm_30 -O2"
else
nvcc_default="clang"
nvccflags_default="--cuda-gpu-arch=sm_30 -O2"
NVCC_C=""
fi
you have to change it to your GPU's compute_xx and sm_xx.
in my case, my GPU is GTX-1070-ti, so it should be =compute_61, =sm_61.
after the change and save filed. then do the above command again.==> ./configure ......
this time should be no error.
===============================================================
if you need mp3 codec:
Over Ubuntu 16.04
sudo apt-get install yasm libmp3lame-dev
Then configure ffmpeg to build from source with libmp3lame:
add this text in the end of th Configure:
--enable-gpl --enable-version3 --enable-postproc --enable-libfdk_aac --enable-libmp3lame
so the total Configure is:
./configure --enable-nonfree --enable-cuda-nvcc --enable-libnpp --extra-cflags=-I/usr/local/cuda/include --extra-ldflags=-L/usr/local/cuda/lib64 --enable-gpl --enable-version3 --enable-postproc --enable-libfdk_aac --enable-libmp3lame
===========================================================
- Compile
make -j 8
- Install the libraries.
sudo make install
then the apps using FFMPEG should be using hardware NVENC codec.
留言
張貼留言