构建ffmpeg gpu版docker镜像 硬件加速处理视频流——筑梦之路

构建docker  ffmpeg gpu版  硬件加速处理视频流数据

编写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 -i
td ffmpeg-nvidia-gpu /bin/bash

扫描二维码关注公众号,回复: 12221793 查看本文章

进入容器测试

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,scale_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

#搜了很多资料,网上基本上都是处理视频,输出为视频,没找到输出为图片的,硬件加速需要编解码都开启,由于这里输出没指定硬件加速编码,所以解码参数-hwaccel cuvid 加上会报错

#经过ffmpeg -codecs | grep encode查询,发现图片没有支持的硬件加速编码器,只能使用cpu进行处理

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 -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

参考链接:

https://github.com/larry011/docker-ffmpeg-nvidia

https://www.jianshu.com/p/59da3d350488

https://www.jianshu.com/p/c3f4daf2aaa3

https://blog.csdn.net/weixin_34010566/article/details/88902875

https://blog.csdn.net/Q_AN1314/article/details/89435464

https://www.cnblogs.com/shenxingping/p/11387680.html

猜你喜欢

转载自blog.csdn.net/qq_34777982/article/details/107685970