CentOS 7 安装nVidia、Cuda
- 一、安装相关环境
- 1. yum安装驱动
- 2. run脚本安装
- 二、安装Cuda
- 三、编译支持
- 1. 库说明
- 2. 下载路径
- yasm
- nasm
- libfdk-aac
- lame
- libopus
- libogg
- libvorbis
- libtheora
- libx265
- x264
- disable-gpl
- 安装ffnvcodec
- libvpx
- openssl
- libav(不用安装)
- 3. 配置ffmpeg, 编译安装
- 下载
- 配置
- 编译
- 安装
- 使用
- 4. 使用问题处理
- (1) 找不到libpostproc.so
- (2) 找不到 libavdevice.so
- (3) 找不到x264_encoder_open_157
- 四、备注一下ubuntu安装ffmpeg开发版本命令
一、安装相关环境
硬件环境:
- nVidia 2060 2块
1. yum安装驱动
rpm --import https://www.elrepo.org/RPM-GPG-KEY-elrepo.org
rpm -Uvh http://www.elrepo.org/elrepo-release-7.0-2.el7.elrepo.noarch.rpm
yum install yum-plugin-fastestmirror
sudo vim /lib/modprobe.d/dist-blacklist.conf
dist-blacklist.conf
#blacklist nvidiafb
blacklist nouveau
options nouveau modeset=0
mv /boot/initramfs-$(uname -r).img /boot/initramfs-$(uname -r).img.bak
dracut /boot/initramfs-$(uname -r).img $(uname -r)
lspci | grep nouveau
没有输出,说明屏蔽默认带有的nouveau成功。
一些命令:
sudo yum install nvidia-detect nvidia显卡检测
nvidia-detect -v 检测结果
# yum -y install kmod-nvidia 安装显卡驱动 这一步应该不需要
2. run脚本安装
参考:https://github.com/keylase/nvidia-patch
cd /opt/nvidia
wget https://international.download.nvidia.com/XFree86/Linux-x86_64/430.40/NVIDIA-Linux-x86_64-430.40.run
chmod +x NVIDIA-Linux-x86_64-430.40.run
./NVIDIA-Linux-x86_64-430.40.run --kernel-source-path=/usr/src/kernels/3.10.0-957.27.2.el7.x86_64
# 下面是移除NVENC同时运行最大数量的限制 restriction on maximum number of simultaneous NVENC
git clone https://github.com/keylase/nvidia-patch
cd nvidia-patch
bash ./patch.sh
如果需要卸载,使用命令:
./NVIDIA-Linux-x86_64-430.40.run --uninstall
二、安装Cuda
参考
sudo yum-config-manager --add-repo http://developer.download.nvidia.com/compute/cuda/repos/rhel7/x86_64/cuda-rhel7.repo
sudo yum clean all
sudo yum -y install nvidia-driver-latest-dkms cuda
nvidia-smi
三、编译支持
1. 库说明
- x264 编码H.264视频,编译参数–enable-gpl --enable-libx264
- fdk-aac 编码AAC音频,编译参数–enable-libfdk-aac
- libvpx VP8/VP9视频编码器,编译参数–enable-libvpx
- libvorbis 编码Vorbis音频,需要libogg。编译参数–enable-libvorbis
- libopus 编码Opus音频。
- LAME 编码MP3音频,编译参数–enable-libmp3lame
- libass 字幕渲染器,编译参数–enable-libass
2. 下载路径
mkdir ~/ffmpeg_sources
yasm
cd ~/ffmpeg_sources
curl -L -O http://www.tortall.net/projects/yasm/releases/yasm-1.3.0.tar.gz
tar xvzf yasm-1.3.0.tar.gz
cd yasm-1.3.0
./configure --prefix=”/usr”
make
sudo make install
nasm
curl -L -O http://www.nasm.us/pub/nasm/releasebuilds/2.14.02/nasm-2.14.02.tar.xz
tar xf nasm-2.14.02.tar.xz
cd nasm-2.14.02
./configure --prefix=”/usr”
make
sudo make install
libfdk-aac
git clone --depth 1 git://git.code.sf.net/p/opencore-amr/fdk-aac
cd fdk-aac
sudo autoreconf -fiv
./configure --prefix="/usr" --disable-shared
make
sudo make install
lame
curl -L -O http://downloads.sourceforge.net/project/lame/lame/3.99/lame-3.99.5.tar.gz
tar xzvf lame-3.99.5.tar.gz
cd lame-3.99.5
./configure --prefix="/usr" --disable-shared --enable-nasm
make
sudo make install
libopus
curl -L -O https://archive.mozilla.org/pub/opus/opus-1.2.tar.gz
tar xvzf opus-1.2.tar.gz
cd opus-1.2
./configure --prefix="/usr" --disable-shared
make
sudo make install
libogg
curl -L -O http://downloads.xiph.org/releases/ogg/libogg-1.3.2.tar.gz
tar xzvf libogg-1.3.2.tar.gz
cd libogg-1.3.2
./configure --prefix="/usr" --disable-shared
make
sudo make install
libvorbis
curl -L -O http://downloads.xiph.org/releases/vorbis/libvorbis-1.3.4.tar.gz
tar xzvf libvorbis-1.3.4.tar.gz
cd libvorbis-1.3.4
./configure --prefix="/usr" --with-ogg="/usr" --disable-shared
make
sudo make install
libtheora
wget http://downloads.xiph.org/releases/theora/libtheora-1.1.1.tar.bz2
tar xjf libtheora-1.1.1.tar.bz2
cd libtheora-1.1.1/
PKG_CONFIG_PATH=/usr/lib/pkgconfig
./autogen.sh --prefix=/usr --disable-examples --disable-shared --disable-sdltest --disable-vorbistest
make
sudo make install
libx265
sudo yum install hg cmake
hg clone http://hg.videolan.org/x265
cd x265/build/linux
sudo cmake -G "Unix Makefiles" -DCMAKE_INSTALL_PREFIX="/usr" -DENABLE_SHARED:bool=on ../../source
sh make-Makefiles.bash
make
sudo make install
# 留意输出的路径
vim /usr/lib/pkgconfig/x265.pc
加上:在Libs.private: -lstdc++ -lm -lrt -ldl
后面加上-lpthread
x264
curl -L -O http://download.videolan.org/pub/x264/snapshots/last_x264.tar.bz2
curl -L -O http://download.videolan.org/pub/x264/snapshots/x264-snapshot-20191217-2245.tar.bz2
# 可以 git clone https://code.videolan.org/videolan/x264.git
tar xjvf x264-snapshot-20191217-2245.tar.bz2
cd x264-snapshot-20191217-2245/
./configure --prefix="/usr" --enable-static --enable-shared
make
sudo make install
disable-gpl
./configure --prefix="/usr" --enable-static --disable-gpl --disable-opencl
make
sudo make install
安装ffnvcodec
git clone https://git.videolan.org/git/ffmpeg/nv-codec-headers.git
cd nv-codec-headers
make && sudo make install
libvpx
VP8/VP9 video encoder.
git clone --depth 1 https://github.com/webmproject/libvpx.git
cd libvpx
./configure --prefix="/usr" --disable-examples --disable-unit-tests --as=yasm
make
sudo make install
openssl
wget http://mirrors.ibiblio.org/openssl/source/old/1.0.2/openssl-1.0.2k.tar.gz
tar -xvf openssl-1.0.2k.tar.gz
cd openssl-1.0.2k
make clean
./config shared --prefix="/usr"
make -j32 && make install
libav(不用安装)
git clone https://github.com/libav/libav
cd libav
./configure \
--prefix='/usr' \
--enable-shared \
--enable-libx264 --enable-gpl
make
make install
3. 配置ffmpeg, 编译安装
下载
git clone https://git.ffmpeg.org/ffmpeg.git
配置
PKG_CONFIG_PATH="/usr/lib/pkgconfig"
export PKG_CONFIG_PATH=/usr/local/lib/pkgconfig:$PKG_CONFIG_PATH
cd ffmpeg
./configure --prefix="/usr" --pkg-config-flags="--static" --enable-gpl --enable-libfdk-aac --enable-libfreetype --enable-libmp3lame --enable-libopus --enable-libtheora --enable-libxvid --enable-libvorbis --enable-libvpx --enable-libx264 --enable-decoder=h264 --enable-libx265 --enable-nonfree --extra-cflags="-I/usr/local/cuda/include/" --extra-ldflags=-L/usr/local/cuda/lib64 --disable-shared --enable-nvenc --enable-cuda --enable-cuvid --enable-libnpp --enable-pthreads --enable-openssl --pkg-config="pkg-config --static"
*我实际编译去掉了–enable-libfdk-aac
enable-libxvid
*
这里–pkg-config不一定要设置,但如果提示pkgconfig问题,可以加上试试
如果不需要支持 nvidia,编译:
./configure --prefix=/usr --bindir=/usr/bin --datadir=/usr/share/ffmpeg --incdir=/usr/include/ffmpeg --libdir=/usr/lib64 --mandir=/usr/share/man --arch=x86_64 --optflags='-O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -m64 -mtune=generic' --extra-ldflags='-Wl,-z,relro ' --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libvo-amrwbenc --enable-version3 --enable-bzlib --disable-crystalhd --enable-gnutls --enable-ladspa --enable-libass --enable-libcdio --enable-libdc1394 --enable-libfdk-aac --enable-nonfree --disable-indev=jack --enable-libfreetype --enable-libgsm --enable-libmp3lame --enable-openal --enable-libopenjpeg --enable-libopus --enable-libpulse --enable-libschroedinger --enable-libsoxr --enable-libspeex --enable-libtheora --enable-libvorbis --enable-libv4l2 --enable-libx264 --enable-libx265 --enable-libxvid --enable-x11grab --enable-avfilter --enable-avresample --enable-postproc --enable-pthreads --disable-static --enable-shared --enable-gpl --disable-debug --disable-stripping --shlibdir=/usr/lib64 --enable-runtime-cpudetect
# 也可以视需要编译较少选项
./configure --prefix=/usr --disable-static --enable-shared --enable-gpl --disable-debug --enable-nonfree --enable-libx264 --enable-libx265 --enable-postproc
编译
make -j 10
编译问题处理:
# matroskadec.c:843: undefined reference to ‘ff_log2_tab’
处理:在libavformat/matroskadec.c文件开头加上 ==> #include "libavutil/log2_tab.c"
# asvdec.c:74: undefined reference to ‘ff_reverse’
处理:在libavcodec/asvdec.c文件开头加上 ==> #include "libavutil/reverse.c"
# 更好的做法是=编译加上 `--enable-postproc`就不会有这个提示。
#fPIC问题 ffmpeg4.4环境,使用--enable-pic
# libavcodec/mqcdec.o: relocation R_X86_64_32S
CFLAGS="-O3 -fPIC" ./configure --prefix="/usr/" --enable-shared --disable-asm --enable-gpl --enable-libx264 --enable-nonfree --disable-libfdk-aac --disable-ffplay --enable-pthreads --enable-pic
安装
make install
使用
ffmpeg -hwaccel cuvid -c:v h264_cuvid -i "rtsp://admin:adminpassword@ip:554/cam/realmonitor?channel=1&subtype=0&unicast=true&proto=Onvif" -c:v h264_nvenc -an -preset slow -tune film -f flv rtmp://rtmpip:port/live/v_test
4. 使用问题处理
(1) 找不到libpostproc.so
ffmpeg: error while loading shared libraries: libpostproc.so.55: cannot open shared object file: No such file or directory
# whereis libpostproc.so.55
libpostproc.so: /usr/lib64/libpostproc.so.53
cat /etc/ld.so.conf
# 显示内容
include ld.so.conf.d/*.conf
/usr/local/lib
# 发现没有/usr/lib64,到最后添加一行,把/usr/lib也加进去:
include ld.so.conf.d/*.conf
/usr/local/lib
/usr/lib
/usr/lib64
# 然后执行:
sudo ldconfig
(2) 找不到 libavdevice.so
./ffmpeg: error while loading shared libraries: libavdevice.so.58: cannot open shared object file: No such file or directory
#系统提示找不到动态库,可以用
export LD_LIBRARY_PATH=/usr/lib #通过whereis libavdevice.so.58可以看到路径
ldd ffmpeg
(3) 找不到x264_encoder_open_157
FFMPEG undefined reference to `x264_encoder_open_157'
在debian系统遇到,删除apt-get安装的x264后,重新编译安装x264
sudo apt remove libx264-dev
四、备注一下ubuntu安装ffmpeg开发版本命令
sudo apt-get install -y autoconf automake build-essential git libass-dev libfreetype6-dev libsdl2-dev libtheora-dev libtool libva-dev libvdpau-dev libvorbis-dev libxcb1-dev libxcb-shm0-dev libxcb-xfixes0-dev pkg-config texinfo wget zlib1g-dev
apt install libavformat-dev
apt install libavcodec-dev
apt install libswresample-dev
apt install libswscale-dev
apt install libavutil-dev
apt install libsdl1.2-dev