环境准备
debian
sudo apt-get install libtool automake autoconf nasm yasm //nasm yasm注意版本
sudo apt-get install libx264-dev
sudo apt-get install libx265-dev
sudo apt-get install libmp3lame-dev
sudo apt-get install libvpx-dev
sudo apt-get install libfaac-dev
centos7
#安装基本开发工具
yum groupinstall "Development Tools"
#安装RPM Fusion存储库
sudo yum install -y https://download1.rpmfusion.org/free/el/rpmfusion-free-release-7.noarch.rpm
sudo yum install -y https://download1.rpmfusion.org/nonfree/el/rpmfusion-nonfree-release-7.noarch.rpm
#安装编解码库和依赖
sudo yum install fdk-aac-devel
sudo yum install x264-devel
sudo yum install yasm
sudo yum install libass-devel harfbuzz-devel freetype-devel
安装nvidia显卡驱动官网
https://www.nvidia.com
https://www.nvidia.cn
安装cuda工具包
#官网
https://developer.nvidia.com/cuda-downloads
#历史版本
https://developer.nvidia.com/cuda-toolkit-archive
#安装
wget https://developer.download.nvidia.com/compute/cuda/12.4.0/local_installers/cuda-repo-rhel7-12-4-local-12.4.0_550.54.14-1.x86_64.rpm
sudo rpm -i cuda-repo-rhel7-12-4-local-12.4.0_550.54.14-1.x86_64.rpm
sudo yum clean all
sudo yum -y install cuda-toolkit-12-4
vim /etc/profile
export PKG_CONFIG_PATH=/usr/local/lib/pkgconfig
export PATH=/usr/local/cuda/bin:$PATH
export LD_LIBRARY_PATH=/usr/local/cuda/lib64:$LD_LIBRARY_PATH
安装CUDNN
官网:https://developer.nvidia.com/rdp/cudnn-archive
tar -xvf cudnn-linux-x86_64-8.9.2.26_cuda12-archive.tar.xz
cd cudnn-linux-x86_64-8.9.2.26_cuda12-archive
cp lib/* /usr/local/cuda/lib64/
cp include/* /usr/local/cuda/include/
安装nv-codec-headers
#下载源码
git clone https://git.videolan.org/git/ffmpeg/nv-codec-headers.git
#进入目录
cd nv-codec-headers/
#查看README文件,里面记录了所对应的版本号
cat README
FFmpeg version of headers required to interface with Nvidias codec APIs.
Corresponds to Video Codec SDK version 12.0.16.
Minimum required driver versions:
Linux: 550.54.14 or newer
Windows: 551.76 or newer
#查看本机的版本号
nvidia-smi
Wed Apr 3 14:09:26 2024
+---------------------------------------------------------------------------------------+
| NVIDIA-SMI 535.154.05 Driver Version: 535.154.05 CUDA Version: 12.2 |
|-----------------------------------------+----------------------+----------------------+
| GPU Name Persistence-M | Bus-Id Disp.A | Volatile Uncorr. ECC |
| Fan Temp Perf Pwr:Usage/Cap | Memory-Usage | GPU-Util Compute M. |
| | | MIG M. |
|=========================================+======================+======================|
| 0 NVIDIA GeForce RTX 3070 Off | 00000000:03:00.0 Off | N/A |
| 32% 32C P0 43W / 240W | 0MiB / 8192MiB | 0% Default |
| | | N/A |
+-----------------------------------------+----------------------+----------------------+
+---------------------------------------------------------------------------------------+
| Processes: |
| GPU GI CI PID Type Process name GPU Memory |
| ID ID Usage |
|=======================================================================================|
| No running processes found |
+---------------------------------------------------------------------------------------+
#本机版本号比较低需要切换版本
#查看所有分支
git branch --all
#切换分支
git checkout remotes/origin/sdk/12.1
cat README
FFmpeg version of headers required to interface with Nvidias codec APIs.
Corresponds to Video Codec SDK version 12.0.16.
Minimum required driver versions:
Linux: 530.41.03 or newer
Windows: 531.61 or newer
-----只要大于530.41.03就可以
#开始编译安装
make && make install
安装ffmpeg
#下载源码
git clone https://git.videolan.org/git/ffmpeg.git
#进入目录
cd ffmpeg/
#编译安装
./configure --enable-gpl --enable-version3 --enable-nonfree --enable-shared --enable-ffmpeg --enable-ffplay --enable-ffprobe --enable-libx264 --enable-libfreetype --enable-libharfbuzz --enable-filter=drawtext --enable-fontconfig --enable-gray --enable-libass --enable-libopenjpeg --enable-nvenc --enable-cuda --enable-cuvid --enable-libnpp --extra-cflags=-I/usr/local/cuda/include --extra-ldflags=-L/usr/local/cuda/lib64
make
sudo make install
#更新库文件
vim /etc/ld.so.conf
/usr/local/lib
#刷新配置
ldconfig
#查看是否安装成功
ffmpeg -hwaccels
#测试使用
ffmpeg -i input.mp4 -vf scale=1920:1080 -c:v h264_nvenc output.mp4
如果有问题清除编译配置
make distclean