update to ffmpeg 8.0 - ditch jupyter notebooks

This commit is contained in:
Chelsea E. Manning committed 2025-12-02 17:14:38 -05:00
1 parent 5ebda23c93
commit 27d8bb2ff6
5 files changed
+410 -314

No files matched your search

+156 -58
View File
@@ -1,5 +1,5 @@
# NVIDIA/CUDA enabled FFmpeg Dockerfile for Anaconda
# Copyright (C) 2020-2022 Chelsea E. Manning
# NVIDIA/CUDA enabled FFmpeg Dockerfile
# Copyright (C) 2020-2025 Chelsea E. Manning
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
@@ -14,32 +14,33 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
FROM xychelsea/anaconda3:v0.5.1-gpu
LABEL description="FFmpeg GPU Container"
# $ docker build --network=host -t xychelsea/ffmpeg-nvidia:latest -f Dockerfile .
# $ docker run --gpus all --rm -it xychelsea/ffmpeg-nvidia:latest /bin/bash
# $ docker push xychelsea/ffmpeg-nvidia:latest
ARG FFMPEG_VERSION="5.0.1"
# Stage 1: Builder - Compile FFmpeg from source
FROM nvidia/cuda:12.5.1-devel-ubuntu22.04 AS builder
ARG FFMPEG_VERSION="8.0"
ENV FFMPEG_VERSION="${FFMPEG_VERSION}"
ENV DEBIAN_FRONTEND=noninteractive
# Start as root
USER root
# Update packages
RUN apt-get update --fix-missing \
&& apt-get -y upgrade \
&& apt-get -y dist-upgrade
# Install dependencies
RUN apt-get -y install \
# Install build dependencies in a single layer
RUN apt-get update --fix-missing && \
apt-get -y install --no-install-recommends \
autoconf \
automake \
build-essential \
ca-certificates \
cleancss \
doxygen \
cmake \
debhelper-compat \
doxygen \
flite1-dev \
frei0r-plugins-dev \
ladspa-sdk libaom-dev \
git \
ladspa-sdk \
libaom-dev \
libaribb24-dev \
libass-dev \
libbluray-dev \
@@ -49,7 +50,7 @@ RUN apt-get -y install \
libcdio-paranoia-dev \
libchromaprint-dev \
libcodec2-dev \
libdc1394-22-dev \
libdc1394-dev \
libdrm-dev \
libfdk-aac-dev \
libffmpeg-nvenc-dev \
@@ -68,9 +69,6 @@ RUN apt-get -y install \
liblzma-dev \
libmp3lame-dev \
libmysofa-dev \
libnvidia-compute-470-server \
libnvidia-decode-470-server \
libnvidia-encode-470-server \
libopenal-dev \
libomxil-bellagio-dev \
libopencore-amrnb-dev \
@@ -114,22 +112,40 @@ RUN apt-get -y install \
node-less \
ocl-icd-opencl-dev \
pkg-config \
tar \
texinfo \
tree \
wget \
zlib1g-dev
yasm \
zlib1g-dev && \
rm -rf /var/lib/apt/lists/*
# Switch to user "anaconda"
USER ${ANACONDA_UID}
WORKDIR ${HOME}
WORKDIR /tmp
# Build ffmpeg
RUN wget -O ${HOME}/ffmpeg-${FFMPEG_VERSION}.tar.gz https://ffmpeg.org/releases/ffmpeg-${FFMPEG_VERSION}.tar.gz \
&& tar -xvf ${HOME}/ffmpeg-${FFMPEG_VERSION}.tar.gz \
&& cd ${HOME}/ffmpeg-${FFMPEG_VERSION} \
&& ./configure --prefix=/usr/local/ffmpeg-nvidia \
--extra-cflags=-I/usr/local/cuda/include \
--extra-ldflags=-L/usr/local/cuda/lib64 \
# Download and extract FFmpeg source (try .tar.xz first, fallback to .tar.bz2)
RUN if wget -q --spider https://ffmpeg.org/releases/ffmpeg-${FFMPEG_VERSION}.tar.xz 2>/dev/null; then \
wget -q https://ffmpeg.org/releases/ffmpeg-${FFMPEG_VERSION}.tar.xz && \
tar -xJf ffmpeg-${FFMPEG_VERSION}.tar.xz && \
rm ffmpeg-${FFMPEG_VERSION}.tar.xz; \
else \
wget -q https://ffmpeg.org/releases/ffmpeg-${FFMPEG_VERSION}.tar.bz2 && \
tar -xjf ffmpeg-${FFMPEG_VERSION}.tar.bz2 && \
rm ffmpeg-${FFMPEG_VERSION}.tar.bz2; \
fi
# Install nv-codec-headers (required for cuvid)
RUN git clone https://git.videolan.org/git/ffmpeg/nv-codec-headers.git /tmp/nv-codec-headers && \
cd /tmp/nv-codec-headers && \
make && \
make install && \
rm -rf /tmp/nv-codec-headers
WORKDIR /tmp/ffmpeg-${FFMPEG_VERSION}
# Configure and build FFmpeg
RUN ./configure \
--prefix=/usr/local/ffmpeg-nvidia \
--extra-cflags="-I/usr/local/cuda/include" \
--extra-ldflags="-L/usr/local/cuda/lib64" \
--toolchain=hardened \
--enable-gpl \
--disable-stripping \
@@ -172,6 +188,7 @@ RUN wget -O ${HOME}/ffmpeg-${FFMPEG_VERSION}.tar.gz https://ffmpeg.org/releases/
--enable-libvidstab \
--enable-libvpx \
--enable-libwebp \
--enable-libx264 \
--enable-libx265 \
--enable-libxml2 \
--enable-libxvid \
@@ -184,36 +201,117 @@ RUN wget -O ${HOME}/ffmpeg-${FFMPEG_VERSION}.tar.gz https://ffmpeg.org/releases/
--enable-openal \
--enable-opencl \
--enable-opengl \
--enable-sdl2 \
&& make -j 8
--enable-sdl2 && \
make -j$(nproc) && \
make install
USER root
# Stage 2: Runtime - Minimal image with only FFmpeg binaries
FROM nvidia/cuda:12.5.1-base-ubuntu22.04
RUN cd ${HOME}/ffmpeg-${FFMPEG_VERSION} \
&& make install
ENV DEBIAN_FRONTEND=noninteractive
ENV PATH="/usr/local/ffmpeg-nvidia/bin:${PATH}"
ENV NVIDIA_VISIBLE_DEVICES=all
ENV NVIDIA_DRIVER_CAPABILITIES=compute,video,utility
USER $ANACONDA_UID
# Create non-root user
RUN groupadd -r ffmpeg && \
useradd -r -g ffmpeg -m -d /home/ffmpeg -s /bin/bash ffmpeg && \
mkdir -p /home/ffmpeg/workspace && \
chown -R ffmpeg:ffmpeg /home/ffmpeg
# Clean build files
RUN cd ${HOME} \
&& rm -rvf ${HOME}/ffmpeg-${FFMPEG_VERSION}.tar.gz ${HOME}/ffmpeg-${FFMPEG_VERSION}
# Install only runtime dependencies (use package names without version numbers for apt to resolve)
RUN apt-get update --fix-missing && \
apt-get -y install --no-install-recommends \
ca-certificates \
libaom3 \
libaribb24-0 \
libass9 \
libbluray2 \
libbs2b0 \
libbz2-1.0 \
libcaca0 \
libcdio19 \
libcdio-paranoia2 \
libchromaprint1 \
libcodec2-1.0 \
libdc1394-25 \
libdrm2 \
libfdk-aac2 \
libfontconfig1 \
libfreetype6 \
libfribidi0 \
libflite1 \
libgl1 \
libgme0 \
libgnutls30 \
libgsm1 \
libiec61883-0 \
libavc1394-0 \
libjack-jackd2-0 \
liblensfun1 \
liblilv-0-0 \
liblzma5 \
libmp3lame0 \
libmysofa1 \
libopenal1 \
libomxil-bellagio0 \
libopencore-amrnb0 \
libopencore-amrwb0 \
libopenjp2-7 \
libopenmpt0 \
libopus0 \
libpulse0 \
librubberband2 \
librsvg2-2 \
libsctp1 \
libsdl2-2.0-0 \
libshine3 \
libsnappy1v5 \
libsoxr0 \
libspeex1 \
libssh-gcrypt-4 \
libtesseract4 \
libtheora0 \
libtwolame0 \
libva2 \
libvdpau1 \
libvidstab1.1 \
libvo-amrwbenc0 \
libvorbis0a \
libvpx7 \
libwavpack1 \
libwebp7 \
libx264-163 \
libx265-199 \
libxcb-shape0 \
libxcb-shm0 \
libxcb-xfixes0 \
libxml2 \
libxv1 \
libxvidcore4 \
libxvmc1 \
libzmq5 \
libzvbi0 \
ocl-icd-libopencl1 && \
rm -rf /var/lib/apt/lists/* /var/cache/apt/archives/*
RUN echo 'PATH="/usr/local/ffmpeg-nvidia/bin:$PATH"' >> ${HOME}/.bashrc
# Copy FFmpeg binaries and libraries from builder
COPY --from=builder /usr/local/ffmpeg-nvidia /usr/local/ffmpeg-nvidia
# Switch back to root
USER root
# Copy required CUDA NPP libraries from builder (needed for --enable-libnpp)
COPY --from=builder /usr/local/cuda/lib64/libnpp*.so* /usr/local/cuda/lib64/
# Clean Anaconda
RUN conda clean -afy
# Update library cache
RUN ldconfig
# Clean packages and caches
RUN apt-get --purge -y autoremove \
wget \
&& rm -rf /var/lib/apt/lists/* /var/cache/apt/archives/* ${HOME}/FFmpeg* \
&& rm -rvf /home/${ANACONDA_PATH}/.cache/yarn \
&& fix-permissions ${HOME} \
&& fix-permissions ${ANACONDA_PATH}
# Verify FFmpeg installation (as root before switching users)
RUN /usr/local/ffmpeg-nvidia/bin/ffmpeg -version && \
/usr/local/ffmpeg-nvidia/bin/ffmpeg -codecs 2>/dev/null | grep -q cuvid && \
/usr/local/ffmpeg-nvidia/bin/ffmpeg -codecs 2>/dev/null | grep -q nvenc
# Re-activate user "anaconda"
USER $ANACONDA_UID
WORKDIR $HOME
# Switch to non-root user
USER ffmpeg
WORKDIR /home/ffmpeg
# Default command
CMD ["/bin/bash"]
-219
View File
@@ -1,219 +0,0 @@
# NVIDIA/CUDA enabled FFmpeg Dockerfile for Anaconda
# Copyright (C) 2020-2022 Chelsea E. Manning
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
FROM xychelsea/anaconda3:v0.5.1-gpu-jupyter
LABEL description="FFmpeg GPU Container w/ Jupyter Notebooks"
# $ docker build --network=host -t xychelsea/ffmpeg-nvidia:latest-jupyter -f Dockerfile.jupyter .
# # $ docker run --gpus all --rm -it -d -p 8888:8888 xychelsea/ffmpeg-nvidia:latest-jupyter
# # $ docker push xychelsea/ffmpeg-nvidia:latest-jupyter
ARG FFMPEG_VERSION="5.0.1"
ENV FFMPEG_VERSION="${FFMPEG_VERSION}"
# Start as root
USER root
# Update packages
RUN apt-get update --fix-missing \
&& apt-get -y upgrade \
&& apt-get -y dist-upgrade
# Install dependencies
RUN apt-get -y install \
cleancss \
doxygen \
debhelper-compat \
flite1-dev \
frei0r-plugins-dev \
ladspa-sdk libaom-dev \
libaribb24-dev \
libass-dev \
libbluray-dev \
libbs2b-dev \
libbz2-dev \
libcaca-dev \
libcdio-paranoia-dev \
libchromaprint-dev \
libcodec2-dev \
libdc1394-22-dev \
libdrm-dev \
libfdk-aac-dev \
libffmpeg-nvenc-dev \
libfontconfig1-dev \
libfreetype6-dev \
libfribidi-dev \
libgl1-mesa-dev \
libgme-dev \
libgnutls28-dev \
libgsm1-dev \
libiec61883-dev \
libavc1394-dev \
libjack-jackd2-dev \
liblensfun-dev \
liblilv-dev \
liblzma-dev \
libmp3lame-dev \
libmysofa-dev \
libnvidia-compute-470-server \
libnvidia-decode-470-server \
libnvidia-encode-470-server \
libopenal-dev \
libomxil-bellagio-dev \
libopencore-amrnb-dev \
libopencore-amrwb-dev \
libopenjp2-7-dev \
libopenmpt-dev \
libopus-dev \
libpulse-dev \
librubberband-dev \
librsvg2-dev \
libsctp-dev \
libsdl2-dev \
libshine-dev \
libsnappy-dev \
libsoxr-dev \
libspeex-dev \
libssh-gcrypt-dev \
libtesseract-dev \
libtheora-dev \
libtwolame-dev \
libva-dev \
libvdpau-dev \
libvidstab-dev \
libvo-amrwbenc-dev \
libvorbis-dev \
libvpx-dev \
libwavpack-dev \
libwebp-dev \
libx264-dev \
libx265-dev \
libxcb-shape0-dev \
libxcb-shm0-dev \
libxcb-xfixes0-dev \
libxml2-dev \
libxv-dev \
libxvidcore-dev \
libxvmc-dev \
libzmq3-dev \
libzvbi-dev \
nasm \
node-less \
ocl-icd-opencl-dev \
pkg-config \
texinfo \
tree \
wget \
zlib1g-dev
# Switch to user "anaconda"
USER ${ANACONDA_UID}
WORKDIR ${HOME}
# Build ffmpeg
RUN wget -O ${HOME}/ffmpeg-${FFMPEG_VERSION}.tar.gz https://ffmpeg.org/releases/ffmpeg-${FFMPEG_VERSION}.tar.gz \
&& tar -xvf ${HOME}/ffmpeg-${FFMPEG_VERSION}.tar.gz \
&& cd ${HOME}/ffmpeg-${FFMPEG_VERSION} \
&& ./configure --prefix=/usr/local/ffmpeg-nvidia \
--extra-cflags=-I/usr/local/cuda/include \
--extra-ldflags=-L/usr/local/cuda/lib64 \
--toolchain=hardened \
--enable-gpl \
--disable-stripping \
--disable-filter=resample \
--enable-cuvid \
--enable-gnutls \
--enable-ladspa \
--enable-libaom \
--enable-libass \
--enable-libbluray \
--enable-libbs2b \
--enable-libcaca \
--enable-libcdio \
--enable-libcodec2 \
--enable-libfdk-aac \
--enable-libflite \
--enable-libfontconfig \
--enable-libfreetype \
--enable-libfribidi \
--enable-libgme \
--enable-libgsm \
--enable-libjack \
--enable-libmp3lame \
--enable-libmysofa \
--enable-libnpp \
--enable-libopenjpeg \
--enable-libopenmpt \
--enable-libopus \
--enable-libpulse \
--enable-librsvg \
--enable-librubberband \
--enable-libshine \
--enable-libsnappy \
--enable-libsoxr \
--enable-libspeex \
--enable-libssh \
--enable-libtheora \
--enable-libtwolame \
--enable-libvorbis \
--enable-libvidstab \
--enable-libvpx \
--enable-libwebp \
--enable-libx265 \
--enable-libxml2 \
--enable-libxvid \
--enable-libzmq \
--enable-libzvbi \
--enable-lv2 \
--enable-nvenc \
--enable-nonfree \
--enable-omx \
--enable-openal \
--enable-opencl \
--enable-opengl \
--enable-sdl2 \
&& make -j 8
USER root
RUN cd ${HOME}/ffmpeg-${FFMPEG_VERSION} \
&& make install
USER $ANACONDA_UID
# Clean build files
RUN cd ${HOME} \
&& rm -rvf ${HOME}/ffmpeg-${FFMPEG_VERSION}.tar.gz ${HOME}/ffmpeg-${FFMPEG_VERSION}
RUN echo 'PATH="/usr/local/ffmpeg-nvidia/bin:$PATH"' >> ${HOME}/.bashrc
# Switch back to root
USER root
# Clean Anaconda
RUN conda clean -afy
# Clean packages and caches
RUN apt-get --purge -y autoremove \
wget \
&& rm -rf /var/lib/apt/lists/* /var/cache/apt/archives/* ${HOME}/FFmpeg* \
&& rm -rvf /home/${ANACONDA_PATH}/.cache/yarn \
&& fix-permissions ${HOME} \
&& fix-permissions ${ANACONDA_PATH}
# Re-activate user "anaconda"
USER $ANACONDA_UID
WORKDIR $HOME
+99 -36
View File
@@ -1,55 +1,112 @@
FFMPEG NVIDIA/CUDA GPU-enabled Docker Container
-----
Provides an [NVIDIA GPU-enabled](https://hub.docker.com/r/nvidia/cuda) container with [FFmpeg](https://ffmpeg.org/) pre-installed on an [Anaconda](https://www.anaconda.com/) container ```xychelsea/ffmpeg-nvidia:latest```, and optional [Jupyter Notebooks](https://jupyter.org/) container ```xychelsea/ffmpeg:latest-jupyter```.
Provides an [NVIDIA GPU-enabled](https://hub.docker.com/r/nvidia/cuda) container with [FFmpeg 8.0](https://ffmpeg.org/) pre-installed with full hardware acceleration support.
FFmpeg with NVIDIA/CUDA support
-----
FFmpeg is the leading multimedia framework, able to decode, encode, transcode, mux, demux, stream, filter and play pretty much anything that humans and machines have created. It supports the most obscure ancient formats up to the cutting edge. No matter if they were designed by some standards committee, the community or a corporation. It is also highly portable: FFmpeg compiles, runs, and passes our testing infrastructure FATE across Linux, Mac OS X, Microsoft Windows, the BSDs, Solaris, etc. under a wide variety of build environments, machine architectures, and configurations.
[Anaconda](https://anaconda.com/) is an open data science platform based on Python 3. This container allows you to create custom Anaconda environments through the ```conda``` command with a lightweight version of Anaconda (Miniconda) and the ```conda-forge``` [repository](https://conda-forge.org/) in the ```/usr/local/anaconda``` directory. The default user, ```anaconda``` runs a [Tini shell](https://github.com/krallin/tini/) ```/usr/bin/tini```, and comes preloaded with the ```conda``` command in the environment ```$PATH```. An additional flavor of this container provides [Jupyter Notebooks](https://jupyter.org/) tags.
This container is built using a lightweight [NVIDIA CUDA base image](https://hub.docker.com/r/nvidia/cuda) with Ubuntu 22.04, providing minimal overhead while maintaining full GPU acceleration capabilities. The container uses a multi-stage build process to optimize image size and build time.
### NVIDIA/CUDA GPU-enabled Containers
### NVIDIA/CUDA GPU-enabled Container
Two flavors provide an [NVIDIA GPU-enabled](https://hub.docker.com/r/nvidia/cuda) container with [TensorFlow](https://tensorflow.org) pre-installed through [Anaconda](https://anaconda.com/).
This container provides an [NVIDIA GPU-enabled](https://hub.docker.com/r/nvidia/cuda) environment with FFmpeg 8.0 compiled with full hardware acceleration support, including NVENC encoding and CUVID decoding.
## Getting the containers
## Getting the container
The base container, based on the ```xychelsea/anaconda3:latest-gpu``` from the [Anaconda 3 container stack](https://hub.docker.com/r/xychelsea/anaconda3) (```xychelsea/anaconda3:latest```) running Tini shell. For the container with a ```/usr/bin/tini``` entry point, use:
Pull the container from Docker Hub:
```bash
docker pull xychelsea/ffmpeg-nvidia:latest
```
With Jupyter Notebooks server pre-installed, pull with:
## Running the container
### Using Docker Run
To run the container with NVIDIA GPU support, use the ```docker run``` command with a bound volume directory ```workspace``` attached at mount point ```/home/ffmpeg/workspace```.
```bash
docker pull xychelsea/ffmpeg-nvidia:latest-jupyter
```
## Running the containers
To run the containers with the generic Docker application or NVIDIA enabled Docker, use the ```docker run``` command with a bound volume directory ```workspace``` attached at mount point ```/home/anaconda/workspace```.
```bash
docker run --gpus all --rm -it
-v workspace:/home/anaconda/workspace \
docker run --gpus all --rm -it \
-v workspace:/home/ffmpeg/workspace \
xychelsea/ffmpeg-nvidia:latest /bin/bash
```
With Jupyter Notebooks server pre-installed, run with:
### Using Docker Compose
A `docker-compose.yml` file is provided with multiple service configurations for different use cases. This is the recommended approach for easier management and configuration.
#### Prerequisites
- Docker Compose v1.28+ or Docker Compose v2.0+
- NVIDIA Container Toolkit installed on the host
- Create input and output directories (or customize paths in `.env`)
#### Quick Start
1. **Create directories** (or customize in `.env`):
```bash
mkdir -p input output scripts
```
2. **Interactive shell** - For manual FFmpeg operations:
```bash
docker-compose run --rm ffmpeg-interactive
```
3. **Transcode a file** - One-shot transcoding with GPU acceleration:
```bash
# Set input/output files via environment variables
INPUT_FILE=input.mp4 OUTPUT_FILE=output.mp4 docker-compose run --rm ffmpeg-transcode
```
4. **Batch processing** - Process multiple files:
```bash
# Create a batch script in ./scripts/batch-process.sh
docker-compose run --rm ffmpeg-batch
```
5. **Stream processing** - Real-time streaming:
```bash
RTMP_URL=rtmp://your-server/live/stream docker-compose up -d ffmpeg-stream
```
#### Available Services
- **`ffmpeg-interactive`**: Interactive shell for manual operations
- **`ffmpeg-transcode`**: One-shot transcoding job (H.264 to HEVC example)
- **`ffmpeg-batch`**: Batch processing service for multiple files
- **`ffmpeg-stream`**: Real-time streaming service with GPU encoding
#### Environment Variables
Create a `.env` file to customize configuration:
```bash
docker run --gpus all --rm -it -d
-v workspace:/home/anaconda/workspace \
-p 8888:8888 \
xychelsea/deepfacelab:latest-jupyter
# GPU Configuration
NVIDIA_VISIBLE_DEVICES=all
CUDA_VISIBLE_DEVICES=
# Directory paths (relative to docker-compose.yml)
INPUT_DIR=./input
OUTPUT_DIR=./output
SCRIPTS_DIR=./scripts
# File names (for transcode service)
INPUT_FILE=input.mp4
OUTPUT_FILE=output.mp4
# Streaming (for stream service)
RTMP_URL=rtmp://localhost/live/stream
```
See `docker-compose.yml` for detailed comments and additional configuration options.
## Using FFmpeg
Once inside the container, as the default user ```anaconda```, you can use the compiler to transcode using hardware acceleration.
Once inside the container, as the default user ```ffmpeg```, you can use FFmpeg to transcode using hardware acceleration.
First, however, enter ```nvidia-smi``` to see whether the container can see your NVIDIA devices. Second, check to ensure that directory of ```ffmpeg``` is ```/usr/local/ffmpeg-nvidia``` by entering ```which ffmpeg``` into a shell. Lastly, ensure that the compiled version of ```ffmpeg``` has access to both the hardware encoder and decoder using ```ffmpeg -codecs | grep -e cuvid``` and ```ffmpeg -codecs | grep -e nvenc``` respectively.
First, enter ```nvidia-smi``` to see whether the container can see your NVIDIA devices. Second, check to ensure that the directory of ```ffmpeg``` is ```/usr/local/ffmpeg-nvidia/bin``` by entering ```which ffmpeg``` into a shell. Lastly, ensure that the compiled version of ```ffmpeg``` has access to both the hardware encoder and decoder using ```ffmpeg -codecs | grep -e cuvid``` and ```ffmpeg -codecs | grep -e nvenc``` respectively.
In this example, we transcode an H.264/MPEG-4 AVC video file ```input.mp4``` into an H.265/MPEG-4 HEVC video file ```output.mp4``` using the ```cuvid``` decoder and ```nvenc``` encoder (see the [NVIDIA Transcoding Guide](https://developer.nvidia.com/blog/nvidia-ffmpeg-transcoding-guide/) for more details on hardware decoding and encoding)
@@ -64,29 +121,28 @@ ffmpeg \
output.mp4
```
## Building the containers
## Building the container
To build either the GPU-enabled container, use the [ffmpeg-docker](https://github.com/xychelsea/ffmpeg-docker) GitHub repository.
To build the GPU-enabled container, use the [ffmpeg-docker](https://github.com/xychelsea/ffmpeg-docker) GitHub repository.
```bash
git clone git://github.com/xychelsea/ffmpeg-docker.git
cd ffmpeg-docker
```
### Compiling FFmpeg with NVIDIA/CUDA GPU support
```bash
docker build -t ffmpeg-nvidia:latest -f Dockerfile .
docker build --network=host -t xychelsea/ffmpeg-nvidia:latest -f Dockerfile .
```
With Jupyter Notebooks server pre-installed, build with:
```
docker build -t ffmpeg-nvidia:latest-jupyter -f Dockerfile.jupyter .
```
The build process uses a multi-stage approach:
- **Builder stage**: Compiles FFmpeg 8.0 from source with all codecs and libraries
- **Runtime stage**: Creates a minimal image with only the compiled binaries and runtime dependencies
## Default Compiler Flags
The default compiler configuration file uses the following flags:
The default compiler configuration uses the following flags:
```
./configure
@@ -96,7 +152,7 @@ The default compiler configuration file uses the following flags:
--toolchain=hardened \
--enable-gpl \
--disable-stripping \
--enable-avresample --disable-filter=resample \
--disable-filter=resample \
--enable-cuvid \
--enable-gnutls \
--enable-ladspa \
@@ -150,9 +206,16 @@ The default compiler configuration file uses the following flags:
--enable-sdl2
```
## Base Image
This container is based on `nvidia/cuda:12.5.1-base-ubuntu22.04`, providing:
- CUDA 12.5.1 runtime support
- Ubuntu 22.04 LTS
- Minimal image size with only essential CUDA libraries
## References
- [FFmpeg](https://ffmpeg.org)
- [NVIDIA CUDA container](https://hub.docker.com/r/nvidia/cuda)
- [Anaconda 3](https://www.anaconda.com/blog/tensorflow-in-anaconda)
- [conda-forge](https://conda-forge.org/)
- [NVIDIA Container Toolkit](https://github.com/NVIDIA/nvidia-container-toolkit)
- [NVIDIA Transcoding Guide](https://developer.nvidia.com/blog/nvidia-ffmpeg-transcoding-guide/)
+154
View File
@@ -0,0 +1,154 @@
# Docker Compose configuration for FFmpeg 8.0 NVIDIA GPU container
# This file provides multiple service examples for different use cases:
# - Interactive shell access
# - One-shot transcoding jobs
# - Batch processing
#
# Prerequisites:
# - NVIDIA Container Toolkit installed on the host
# - Docker Compose v1.28+ or Docker Compose v2.0+
# - NVIDIA GPU with appropriate drivers
services:
# Interactive service - for manual FFmpeg operations and testing
# Usage: docker-compose run --rm ffmpeg-interactive
# docker-compose up -d ffmpeg-interactive (then: docker-compose exec ffmpeg-interactive bash)
ffmpeg-interactive:
image: xychelsea/ffmpeg-nvidia:latest
container_name: ffmpeg-interactive
environment:
# GPU visibility - set to 'all' or specific GPU IDs (e.g., '0,1')
- NVIDIA_VISIBLE_DEVICES=${NVIDIA_VISIBLE_DEVICES:-all}
# GPU capabilities required for Fmpeg (compute, video encoding/decoding, utility)
- NVIDIA_DRIVER_CAPABILITIES=compute,video,utility
# Optional: Limit CUDA to specific devices (overrides NVIDIA_VISIBLE_DEVICES)
- CUDA_VISIBLE_DEVICES=${CUDA_VISIBLE_DEVICES:-}
# Timezone for logging (optional)
- TZ=${TZ:-UTC}
volumes:
# Mount input directory
- ${INPUT_DIR:-./input}:/home/ffmpeg/workspace/input:ro
# Mount output directory (read-write)
- ${OUTPUT_DIR:-./output}:/home/ffmpeg/workspace/output:rw
# Optional: Mount for scripts or configuration files
- ${SCRIPTS_DIR:-./scripts}:/home/ffmpeg/workspace/scripts:ro
working_dir: /home/ffmpeg/workspace
stdin_open: true
tty: true
# Default command is /bin/bash (interactive shell)
# Override with: docker-compose run --rm ffmpeg-interactive <command>
command: /bin/bash
# Alternative GPU configuration using deploy (Docker Compose v3.8+)
# deploy:
# resources:
# reservations:
# devices:
# - driver: nvidia
# count: all
# capabilities: [gpu]
# Transcode service - one-shot transcoding job with GPU acceleration
# Usage: docker-compose run --rm ffmpeg-transcode
# Example: Transcodes H.264 input to HEVC using cuvid decoder and nvenc encoder
ffmpeg-transcode:
image: xychelsea/ffmpeg-nvidia:latest
container_name: ffmpeg-transcode
environment:
- NVIDIA_VISIBLE_DEVICES=${NVIDIA_VISIBLE_DEVICES:-all}
- NVIDIA_DRIVER_CAPABILITIES=compute,video,utility
- CUDA_VISIBLE_DEVICES=${CUDA_VISIBLE_DEVICES:-}
- TZ=${TZ:-UTC}
# Input and output filenames (can be overridden)
- INPUT_FILE=${INPUT_FILE:-input.mp4}
- OUTPUT_FILE=${OUTPUT_FILE:-output.mp4}
volumes:
- ${INPUT_DIR:-./input}:/home/ffmpeg/workspace/input:ro
- ${OUTPUT_DIR:-./output}:/home/ffmpeg/workspace/output:rw
working_dir: /home/ffmpeg/workspace
# Example FFmpeg 8.0 command with GPU acceleration:
# - h264_cuvid: Hardware-accelerated H.264 decoding
# - hevc_nvenc: Hardware-accelerated HEVC encoding
# - cq:v 23: Constant quality mode (lower = better quality, higher file size)
# Customize this command for your specific needs
command: >
ffmpeg -vsync 0 -hwaccel cuvid -c:v h264_cuvid -i input/${INPUT_FILE} -c:v hevc_nvenc -preset p4 -cq:v 23 -c:a copy output/${OUTPUT_FILE}
# Alternative GPU configuration
# deploy:
# resources:
# reservations:
# devices:
# - driver: nvidia
# count: all
# capabilities: [gpu]
# Batch processing service - processes multiple files
# Usage: docker-compose run --rm ffmpeg-batch
# Requires a script in the scripts directory to process multiple files
ffmpeg-batch:
image: xychelsea/ffmpeg-nvidia:latest
container_name: ffmpeg-batch
environment:
- NVIDIA_VISIBLE_DEVICES=${NVIDIA_VISIBLE_DEVICES:-all}
- NVIDIA_DRIVER_CAPABILITIES=compute,video,utility
- CUDA_VISIBLE_DEVICES=${CUDA_VISIBLE_DEVICES:-}
- TZ=${TZ:-UTC}
volumes:
- ${INPUT_DIR:-./input}:/home/ffmpeg/workspace/input:ro
- ${OUTPUT_DIR:-./output}:/home/ffmpeg/workspace/output:rw
- ${SCRIPTS_DIR:-./scripts}:/home/ffmpeg/workspace/scripts:ro
working_dir: /home/ffmpeg/workspace
# Example: Run a batch processing script
# Create a script in ./scripts/batch-process.sh that processes files
command: /bin/bash -c "chmod +x scripts/*.sh 2>/dev/null; scripts/batch-process.sh || echo 'No batch script found. Create scripts/batch-process.sh'"
# Alternative GPU configuration
# deploy:
# resources:
# reservations:
# devices:
# - driver: nvidia
# count: all
# capabilities: [gpu]
# Stream processing service - for real-time streaming scenarios
# Usage: docker-compose up -d ffmpeg-stream
# Example: Streams input to RTMP endpoint with GPU acceleration
ffmpeg-stream:
image: xychelsea/ffmpeg-nvidia:latest
container_name: ffmpeg-stream
environment:
- NVIDIA_VISIBLE_DEVICES=${NVIDIA_VISIBLE_DEVICES:-all}
- NVIDIA_DRIVER_CAPABILITIES=compute,video,utility
- CUDA_VISIBLE_DEVICES=${CUDA_VISIBLE_DEVICES:-}
- TZ=${TZ:-UTC}
# RTMP stream URL (override via environment)
- RTMP_URL=${RTMP_URL:-rtmp://localhost/live/stream}
volumes:
- ${INPUT_DIR:-./input}:/home/ffmpeg/workspace/input:ro
network_mode: host
working_dir: /home/ffmpeg/workspace
# Example: Stream with GPU encoding
# Adjust input source and RTMP URL as needed
command: >
ffmpeg -re -i input/${INPUT_FILE:-input.mp4} -c:v h264_nvenc -preset p4 -b:v 4M -maxrate 4M -bufsize 8M -g 50 -c:a aac -b:a 128k -f flv ${RTMP_URL}
restart: unless-stopped
# Alternative GPU configuration
# deploy:
# resources:
# reservations:
# devices:
# - driver: nvidia
# count: all
# capabilities: [gpu]
# Optional: Named volumes (uncomment if you prefer named volumes over bind mounts)
# volumes:
# ffmpeg-input:
# driver: local
# ffmpeg-output:
# driver: local
# Optional: Custom networks (uncomment if you need custom networking)
# networks:
# ffmpeg-network:
# driver: bridge
+1 -1
View File
@@ -1 +1 @@
v0.5.1
r8.0