安装相关环境
硬件环境:
- nVidia 2060 2块
yum安装驱动
rpm --import https://www.elrepo.org/RPM-GPG-KEY-elrepo.orgrpm -Uvh http://www.elrepo.org/elrepo-release-7.0-2.el7.elrepo.noarch.rpmyum install yum-plugin-fastestmirrorsudo vim /lib/modprobe.d/dist-blacklist.conf
dist-blacklist.conf
#blacklist nvidiafbblacklist nouveauoptions nouveau modeset=0
mv /boot/initramfs-$(uname -r).img /boot/initramfs-$(uname -r).img.bakdracut /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 安装显卡驱动 这一步应该不需要
run脚本安装
参考:https://github.com/keylase/nvidia-patch
cd /opt/nvidiawget https://international.download.nvidia.com/XFree86/Linux-x86_64/430.40/NVIDIA-Linux-x86_64-430.40.runchmod +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 NVENCgit clone https://github.com/keylase/nvidia-patchcd nvidia-patchbash ./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.reposudo yum clean allsudo yum -y install nvidia-driver-latest-dkms cudanvidia-smi
编译支持
库说明
- 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
下载路径
mkdir ~/ffmpeg_sources
yasm
cd ~/ffmpeg_sourcescurl -L -O http://www.tortall.net/projects/yasm/releases/yasm-1.3.0.tar.gztar xvzf yasm-1.3.0.tar.gzcd yasm-1.3.0./configure --prefix=”/usr”makesudo make install
nasm
curl -L -O http://www.nasm.us/pub/nasm/releasebuilds/2.14.02/nasm-2.14.02.tar.xztar xf nasm-2.14.02.tar.xzcd nasm-2.14.02./configure --prefix=”/usr”makesudo make install
libfdk-aac
git clone --depth 1 git://git.code.sf.net/p/opencore-amr/fdk-aaccd fdk-aacsudo autoreconf -fiv./configure --prefix="/usr" --disable-sharedmakesudo make install
lame
curl -L -O http://downloads.sourceforge.net/project/lame/lame/3.99/lame-3.99.5.tar.gztar xzvf lame-3.99.5.tar.gzcd lame-3.99.5./configure --prefix="/usr" --disable-shared --enable-nasmmakesudo make install
libopus
curl -L -O https://archive.mozilla.org/pub/opus/opus-1.2.tar.gztar xvzf opus-1.2.tar.gzcd opus-1.2./configure --prefix="/usr" --disable-sharedmakesudo make install
libogg
curl -L -O http://downloads.xiph.org/releases/ogg/libogg-1.3.2.tar.gztar xzvf libogg-1.3.2.tar.gzcd libogg-1.3.2./configure --prefix="/usr" --disable-sharedmakesudo make install
libvorbis
curl -L -O http://downloads.xiph.org/releases/vorbis/libvorbis-1.3.4.tar.gztar xzvf libvorbis-1.3.4.tar.gzcd libvorbis-1.3.4./configure --prefix="/usr" --with-ogg="/usr" --disable-sharedmakesudo make install
libtheora
git clone git://git.xiph.org/mirrors/theora.git theora-gitcd theora-gitPKG_CONFIG_PATH=/usr/lib/pkgconfig ./autogen.sh --prefix=/usr --disable-examples --disable-shared --disable-sdltest --disable-vorbistest && make && make install
libx265
sudo yum install hg cmakehg clone http://hg.videolan.org/x265cd x265/build/linuxsudo cmake -G "Unix Makefiles" -DCMAKE_INSTALL_PREFIX="/usr" -DENABLE_SHARED:bool=off ../../sourcemakesudo make installvim /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.bz2tar xjvf last_x264.tar.bz2cd x264-snapshot-20170625-2245/./configure --prefix="/usr" --enable-staticmakesudo make install
disable-gpl
./configure --prefix="/usr" --enable-static --disable-gpl --disable-openclmakesudo make install
安装ffnvcodec
git clone https://git.videolan.org/git/ffmpeg/nv-codec-headers.gitcd nv-codec-headersmake && sudo make install
libvpx
VP8/VP9 video encoder.
git clone --depth 1 https://github.com/webmproject/libvpx.gitcd libvpx./configure --prefix="/usr" --disable-examples --disable-unit-tests --as=yasmmakesudo make install
https
wget http://mirrors.ibiblio.org/openssl/source/old/1.0.2/openssl-1.0.2k.tar.gztar -xvf openssl-1.0.2k.tar.gzcd openssl-1.0.2kmake clean./config shared --prefix="/usr"make -j32 && make install
配置ffmpeg, 编译安装
下载
git clone https://git.ffmpeg.org/ffmpeg.gitgit clone https://github.com/libav/libav
配置
PKG_CONFIG_PATH="/usr/lib/pkgconfig" export PKG_CONFIG_PATH=/usr/local/lib/pkgconfig:$PKG_CONFIG_PATHcd 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-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
我实际编译去掉了–enable-libfdk-aac enable-libxvid
编译
make -j 10
安装
make install
使用 测试转码推流
ffmpeg -hwaccel cuvid -c:v h264_cuvid -i "rtsp://aaa:bbb@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```