ffmpeg gpu版编译安装
需求说明:
ffmpeg cpu版拉流对处理器的消耗比较大,因此需要调用gpu来拉流,提高效率
环境说明:
操作系统:ubuntu 16.04 server lts
显卡:gtx 1060
cuda:10.1
物理机环境:
1.更新
sudo apt-get update
2.安装基础依赖:
sudo apt-get -y install autoconf automake build-essential 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 zlib1g-dev
3.安装yasm
sudo apt-get install yasm
4.安装libx264
sudo apt-get install libx264-dev
5.安装libx265
sudo apt-get install libx265-dev
6.安装libvpx
sudo apt-get install libvpx-dev
7.安装libfdk-aac
sudo apt-get install libfdk-aac-dev
8.安装libmp3lam
sudo apt-get install libmp3lame-dev
9. 安装libopus
sudo apt-get install libopus-dev
10.安装nvenc
安装依赖:
sudo apt-get -y install glew-utils libglew-dbg libglew-dev libglew1.13 \
libglewmx-dev libglewmx-dbg freeglut3 freeglut3-dev freeglut3-dbg libghc-glut-dev \
libghc-glut-doc libghc-glut-prof libalut-dev libxmu-dev libxmu-headers libxmu6 \
libxmu6-dbg libxmuu-dev libxmuu1 libxmuu1-dbg
11.下载ffmpeg源码:
git clone https://git.ffmpeg.org/ffmpeg.git ffmpeg/
驱动版本兼容性 有要求 需要切换到支持的版本 具体可查看说明文件
https://github.com/FFmpeg/nv-codec-headers
sudo make install && cd -
sudo apt-get install build-essential yasm cmake libtool libc6 libc6-dev unzip wget libnuma1 libnuma-dev
12.编译安装ffmpeg:
./configure \
--enable-gpl \
--enable-libass \
--enable-libfdk-aac \
--enable-libfreetype \
--enable-libmp3lame \
--enable-libopus \
--enable-libtheora \
--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
13.编译:make -j4
14.安装: make install
15.检查:ffmpeg -version
查看ffmpeg硬件加速项:
ffmpeg -hwaccels
查看ffmpeg GPU编解码器:
ffmpeg -codecs | grep cuvid
测试视频转码:
ffmpeg -hwaccel cuvid -c:v h264_cuvid -i <input> -c:v h264_nvenc -b:v 2048k -vf scale_npp=1280:-1 -y <output>
测试视频流拆图:
ffmpeg -c:v h264_cuvid -i rtsp://admin:[email protected]:554/streaming/channels/1 -q:v 2 -f image2 -t 01:00:00 -r 5 ./1/%08d.jpg
ffmpeg -c:v h264_cuvid -rtsp_transport tcp -i rtsp://admin:[email protected]:554/streaming/channels/1 -q:v 2 -f image2 -t 01:00:00 -r 5 ./%08d.jpg
ffmpeg -c:v h264_cuvid -rtsp_transport tcp -i rtsp://admin:[email protected]:554/streaming/channels/1 -y -qscale 5 -f image2 -r 1 -t 0:5:0 ./%5d.jpg
----------------------------------------------------------------------------------------------
Docker版:
编写Dockerfile,内容如下:
FROM nvidia/cuda:10.1-devel-ubuntu16.04
WORKDIR /tmp
ADD build-ffmpeg.sh build-ffmpeg.sh
#此步骤主要是拉取官方的源码比较慢的时候 采取在外面拉取了添加目录进去
#ADD ffmpeg ffmpeg
RUN chmod +x build-ffmpeg.sh
RUN apt-get update -y && apt-get install -y git build-essential yasm cmake libtool libc6 libc6-dev unzip wget libnuma1 libnuma-dev frei0r-plugins-dev libgnutls28-dev libass-dev \
libmp3lame-dev libopencore-amrnb-dev libopencore-amrwb-dev libopus-dev librtmp-dev libsoxr-dev libspeex-dev libtheora-dev libvo-amrwbenc-dev libvorbis-dev libvpx-dev libwebp-dev \
libx264-dev libx265-dev libxvidcore-dev libopenjpeg-dev
RUN ./build-ffmpeg.sh
编写构建脚本,内容如下:
build-ffmpeg.sh
#!/bin/bash
#git clone https://github.com/ffmpeg/ffmpeg.git
#国内源
git clone https://gitee.com/mirrors/ffmpeg.git
cd ffmpeg
git checkout release/3.4
./configure --enable-nonfree --disable-shared --enable-nvenc --enable-cuda --enable-cuvid --enable-libnpp --extra-cflags=-Ilocal/include --enable-gpl --enable-version3 --disable-debug --dis
able-ffplay --disable-indev=sndio --disable-outdev=sndio --enable-fontconfig --enable-frei0r --enable-gnutls --enable-gray --enable-libass --enable-libfreetype --enable-libfribidi --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopus --enable-libopenjpeg --enable-librtmp --enable-libsoxr --enable-libspeex --enable-libtheora --enable-libvo-amrwbenc --enable-libvorbis --enable-libvpx --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxvid --extra-cflags=-I/usr/local/cuda/include --extra-ldflags=-L/usr/local/cuda/lib64
make -j 8
make install
构建镜像:
docker build . -t ffmpeg-nvidia-gpu
创建容器
docker run --name ffmpeg-gpu --runtime=nvidia -e NVIDIA_DRIVER_CAPABILITIES=compute,utility,video -v $(pwd):/data --net=host -itd ffmpeg-nvidia-gpu /bin/bash
进入容器测试
docker exec -it ffmpeg-gpu /bin/bash
测试命令:
ffmpeg -y -vsync 0 -hwaccel cuvid -i "/tmp/content/input.mp4" -filter:v hwupload_cuda,scale_npp=w=576:h=480:format=yuv420p:interp_algo=lanczos,hwdownload,format=yuv420p -c:a copy -c:v h264_nvenc -b:v 5M /tmp/content/output.mp4
ffmpeg -y -vsync 0 -hwaccel cuvid -rtsp_transport tcp -i "rtsp://admin:[email protected]:554/streaming/channels/1" -filter:v hwupload_cuda,s
cale_npp=w=576:h=480:format=yuv420p:interp_algo=lanczos,hwdownload,format=yuv420p -c:a copy -c:v h264_nvenc -b:v 5M output.mp4
ffmpeg -c:v h264_cuvid -rtsp_transport tcp -i rtsp://admin:[email protected]:554/streaming/channels/1 -q:v 2 -f image2 -t 01:00:00 -r 5 ./1/%08d.jpg
ffmpeg -y -i example.mp4 -c:v h264_nvenc -c:a aac -hls_list_size 0 -hls_time 10 -hls_flags single_file -f hls 1.m3u8
#下面是移除NVENC同时运行最大数量的限制 restriction on maximum number of simultaneous NVENC
git clone https://github.com/keylase/nvidia-patch
cd nvidia-patch
bash ./patch.sh
原文链接:https://blog.csdn.net/xundh/article/details/100760114
参考资料:
https://developer.nvidia.com/video-encode-decode-gpu-support-matrix
参考链接:
https://github.com/larry011/docker-ffmpeg-nvidia
https://www.cnblogs.com/shenxingping/p/11387680.html
https://www.jianshu.com/p/59da3d350488
ubuntu server lts ffmpeg gpu版编译构建过程——筑梦之路
猜你喜欢
转载自blog.csdn.net/qq_34777982/article/details/107790198
今日推荐
周排行