- 依赖安装
apt-get update && apt-get -y install autoconf automake build-essential cmake libpcre3 libpcre3-dev openssl vim tree lrzsz iproute2 pcregrep procps dnsutils netcat git-core libass-dev libfreetype6-dev libgnutls28-dev libsdl2-dev libtool libva-dev libvdpau-dev libvorbis-dev libxcb1-dev libxcb-shm0-dev libxcb-xfixes0-dev pkg-config texinfo wget yasm zlib1g-dev checkinstall libfaac-dev libgpac-dev ladspa-sdk-dev libunistring-dev libbz2-dev libjack-jackd2-dev libmp3lame-dev libopencore-amrnb-dev libopencore-amrwb-dev libvpx-dev libx264-dev libx265-dev libxvidcore-dev libopenal-dev libopus-dev libsdl1.2-dev libtheora-dev libx11-dev libxfixes-dev texi2html libssl-dev libfdk-aac-dev
- nvidia-codec-headers(一定要注意版本对应问题,博主的显卡驱动是 510,不能安装版本大于510的版本,先择 n11.1.5.2 版本刚好合适)
# nvidia codec-headers
wget https://github.com/FFmpeg/nv-codec-headers/releases/download/n11.1.5.2/nv-codec-headers-11.1.5.2.tar.gz
cd nv-codec-headers
make && make install
-
其他编译安装(可选)
- x264
git clone https://code.videolan.org/videolan/x264.git cd x264 ./configure --enable-shared --disable-asm make && make install
tar zxvf fdk-aac-2.0.2.tar.gz cd fdk-aac-2.0.2 ./configure make && make install echo "/usr/local/lib" > /etc/ld.so.conf.d/aac.conf ldconfig
-
ffmpeg 安装
git clone https://git.ffmpeg.org/ffmpeg.git
cd ffmpeg
./configure --prefix=/usr/local/ffmpeg --enable-shared \
--enable-nonfree --enable-gpl --enable-version3 \
--enable-libmp3lame --enable-libvpx --enable-libopus \
--enable-opencl --enable-libxcb \
--enable-opengl --enable-nvenc --enable-vaapi \
--enable-vdpau --enable-ffplay --enable-ffprobe \
--enable-libxvid \
--enable-libnpp \
--enable-libx264 --enable-libx265 --enable-openal \
--enable-openssl --enable-cuda-nvcc --enable-cuvid --extra-cflags=-I/usr/local/cuda/include --extra-ldflags=-L/usr/local/cuda/lib64
make -j8 && make install
ln -s /usr/local/ffmpeg/bin/ffmpeg /usr/bin/ffmpeg
ln -s /usr/local/ffmpeg/bin/ffprobe /usr/bin/ffprobe
ln -s /usr/local/ffmpeg/bin/ffplay /usr/bin/ffplay
ln -s /usr/local/ffmpeg/bin/ffmpeg /usr/local/bin/ffmpeg
ln -s /usr/local/ffmpeg/bin/ffprobe /usr/local/bin/ffprobe
ln -s /usr/local/ffmpeg/bin/ffplay /usr/local/bin/ffplay
echo "/usr/local/ffmpeg/lib" >> /etc/ld.so.conf.d/ffmpeg.conf
#更新环境变量
ldconfig
- 查看版本
ffmpeg -version
- 查看硬件加速方式
ffmpeg -hwaccels
-
报错解决方法(容器内):
[h264_cuvid @ 0x55b5efb8d900] Cannot load libnvcuvid.so.1
[h264_cuvid @ 0x55b5efb8d900] Failed loading nvcuvid.
# 容器内没有这2个文件需要去宿主机拷贝到容器(宿主机执行)
cd /usr/lib/x86_64-linux-gnu/
# 宿主机文件夹下: /usr/lib/x86_64-linux-gnu/ {libnvcuvid.so.470.82.01, libnvidia-encode.so.470.82.01}
# 拷贝到容器/lib64/下(容器执行)
docker cp libnvcuvid.so.470.82.01 7286404e2f78:/lib64/
docker cp libnvidia-encode.so.470.82.01 7286404e2f78:/lib64/
# 容器内创建软连接(容器执行)
ln -s libnvcuvid.so.470.82.01 /lib64/libnvcuvid.so.1
ln -s libnvidia-encode.so.470.82.01 /lib64/libnvidia-encode.so.1
#如果依然报错,需要将 /lib64 export 到 LD_LIBRARY_PATH 环境变量中
- 容器内添加软连接路径
echo "/lib64" >> /etc/ld.so.conf
ldconfig
- 测试
ffmpeg -rtsp_transport tcp -hwaccel cuvid -hwaccel_device 2 -c:v h264_cuvid -i rtsp://admin:hh123456@192.168.110.64:554 -r 30 -t 100 -b:v 2048k -vf scale_npp=1280:-1 -y -c:v h264_nvenc tcp_gpu_output.mp4
ffmpeg -rtsp_transport tcp -hwaccel cuvid -c:v h264_cuvid -i rtsp://112.6.247.70:554/openUrl/itqsM4E -r 30 -t 100 -b:v 2048k -y -c:v h264_nvenc tcp_gpu_output.mp4