Skip to content

Commit

Permalink
added nvidia variant template files
Browse files Browse the repository at this point in the history
  • Loading branch information
shaulfl committed Apr 28, 2019
1 parent 00f84d3 commit 4055dda
Show file tree
Hide file tree
Showing 3 changed files with 120 additions and 1 deletion.
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,18 @@ Thanks to [qmfrederik](https://github.com/qmfrederik) for the vaapi ubuntu based
- Run ffmpeg with the correct parameters, this is the same as when running [ffmpeg natively](https://trac.ffmpeg.org/wiki/Hardware/VAAPI).


#### Use nvidia hardware acceleration enabled build
Supports nvenc only on all ffmpeg versions, and hardware decoding and scaling on ffmpeg >= 4.0

- Install nvidia drivers on host machine.
- Install nvidia-docker (https://github.com/NVIDIA/nvidia-docker) on host machine.
- Run container using "--runtime=nvidia" flag and use supported ffmpegs hwaccel options (https://trac.ffmpeg.org/wiki/HWAccelIntro)

Hardware encoding only:
`docker run --runtime=nvidia jrottenberg/ffmpeg:nvidia-3.4 -i INPUT -c:v h264_nvenc -preset slow OUTPUT`
Full hardware acceleration:
`docker run --runtime=nvidia jrottenberg/ffmpeg:nvidia-4.1 -hwaccel cuvid -c:v h264_cuvid -i INPUT -vf scale_npp=-1:720 -c:v h264_nvenc -preset slow OUTPUT`

See what's inside the beast
---------------------------

Expand Down
95 changes: 95 additions & 0 deletions templates/Dockerfile-template.nvidia
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
# ffmpeg - http://ffmpeg.org/download.html
#
# From https://trac.ffmpeg.org/wiki/CompilationGuide/Ubuntu
#
# https://hub.docker.com/r/jrottenberg/ffmpeg/
#
#

FROM nvidia/cudagl:9.2-devel-ubuntu18.04 AS devel-base

ENV NVIDIA_DRIVER_CAPABILITIES compat32,compute,video
WORKDIR /tmp/workdir

RUN apt-get -yqq update && \
apt-get install -yq --no-install-recommends ca-certificates expat libgomp1 && \
apt-get autoremove -y && \
apt-get clean -y

FROM nvidia/cudagl:9.2-runtime-ubuntu18.04 AS runtime-base

ENV NVIDIA_DRIVER_CAPABILITIES compat32,compute,video
WORKDIR /tmp/workdir

RUN apt-get -yqq update && \
apt-get install -yq --no-install-recommends ca-certificates expat libgomp1 libxcb-shape0-dev && \
apt-get autoremove -y && \
apt-get clean -y


FROM devel-base as build

ENV NVIDIA_HEADERS_VERSION=8.1.24.9
ARG PKG_CONFIG_PATH=/opt/ffmpeg/lib/pkgconfig
ENV LD_LIBRARY_PATH="$LD_LIBRARY_PATH:/opt/ffmpeg/lib"
ARG PREFIX=/opt/ffmpeg
ARG MAKEFLAGS="-j12"

ENV %%ENV%%

RUN buildDeps="autoconf \
automake \
cmake \
curl \
bzip2 \
libexpat1-dev \
g++ \
gcc \
git \
gperf \
libtool \
make \
nasm \
perl \
pkg-config \
python \
libssl-dev \
yasm \
zlib1g-dev" && \
apt-get -yqq update && \
apt-get install -yq --no-install-recommends ${buildDeps}

RUN \
DIR=/tmp/nv-codec-headers && \
git clone https://git.videolan.org/git/ffmpeg/nv-codec-headers.git ${DIR} && \
cd ${DIR} && \
git checkout n${NVIDIA_HEADERS_VERSION} && \
sed -i 's@/usr/local@'"$PREFIX"'@' Makefile && \
make && \
make install && \
rm -rf ${DIR}

%%RUN%%
## cleanup
RUN \
ldd ${PREFIX}/bin/ffmpeg | grep opt/ffmpeg | cut -d ' ' -f 3 | xargs -i cp {} /usr/local/lib/ && \
cp ${PREFIX}/bin/* /usr/local/bin/ && \
cp -r ${PREFIX}/share/ffmpeg /usr/local/share/ && \
LD_LIBRARY_PATH=/usr/local/lib ffmpeg -buildconf



FROM runtime-base AS release
MAINTAINER Julien Rottenberg <julien@rottenberg.info>

CMD ["--help"]
ENTRYPOINT ["ffmpeg"]
ENV LD_LIBRARY_PATH="$LD_LIBRARY_PATH:/usr/local/lib"

COPY --from=build /usr/local/bin /usr/local/bin/
COPY --from=build /usr/local/share /usr/local/share/
COPY --from=build /usr/local/lib /usr/local/lib/

# Let's make sure the app built correctly
# Convenient to verify on https://hub.docker.com/r/jrottenberg/ffmpeg/builds/ console output

14 changes: 13 additions & 1 deletion update.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from distutils.version import StrictVersion

MIN_VERSION = '2.8'
VARIANTS = ['ubuntu', 'alpine', 'centos', 'scratch', 'vaapi']
VARIANTS = ['ubuntu', 'alpine', 'centos', 'scratch', 'vaapi', 'nvidia']
FFMPEG_RELEASES = 'https://ffmpeg.org/releases/'

travis = []
Expand Down Expand Up @@ -72,6 +72,18 @@
docker_content = re.sub(r"--enable-libaom [^\\]*", "", docker_content)
if (version == 'snapshot' or version[0] >= '3') and variant == 'vaapi':
docker_content = docker_content.replace('--disable-ffplay', '--disable-ffplay \\\n --enable-vaapi')

if variant == 'nvidia':
docker_content = docker_content.replace('--extra-cflags="-I${PREFIX}/include"', '--extra-cflags="-I${PREFIX}/include -I${PREFIX}/include/ffnvcodec -I/usr/local/cuda/include/ '")
docker_content = docker_content.replace('--extra-ldflags="-L${PREFIX}/lib"', '--extra-ldflags="-L${PREFIX}/lib -L/usr/local/cuda/lib64/ -L/usr/local/cuda/lib32/"')
if (version == 'snapshot' or version[0] >= '4') :
docker_content = docker_content.replace('--disable-ffplay', '--disable-ffplay \\\n --enable-cuda \\\n --enable-nvenc \\\n --enable-cuvid \\\n --enable-libnpp')
# Don't support hw scaling on older ffmpeg versions
if (version == version[0] < '4') :
docker_content = docker_content.replace('--disable-ffplay', '--disable-ffplay \\\n --enable-nvenc')
# FFmpeg 3.2 and earlier don't compile correctly on Ubuntu 18.04 due to openssl issues
if (version[0] < '3' or (version[0] == '3' and version[2] < '3')) :
docker_content = docker_content.replace('-ubuntu18.04', '-ubuntu16.04')

# FFmpeg 3.2 and earlier don't compile correctly on Ubuntu 18.04 due to openssl issues
if variant == 'vaapi' and (version[0] < '3' or (version[0] == '3' and version[2] < '3')):
Expand Down

0 comments on commit 4055dda

Please sign in to comment.