This container builds FFmpeg with Nvidia GPU acceleration support. Many Nvidia GPUs have hardware based decoders and encoders for commonly used video codecs. Using them can significantly accelerate encoding and decoding of videos. For more information about the Nvidia technology and hardware acceleration for FFmpeg, please see this blog post and the FFmpeg hardware acceleration wiki.
The container is based off of the nvidia/cuda base image and uses the latest commit from the ffmpeg git repository. The Dockerfile follows build instructions included in the Video Codec SDK Documentation.
The container require CUDA, Docker and Nvidia-Docker to be installed on the host computer. It has been tested to work on Ubuntu 21.10, CUDA 11.4 and Docker 20.10.7.
You can build the containers by checking out the source code and running:
docker build . -t nvffmpeg
To invoke the ffmpeg, run:
docker run --gpus all -e VIDIA_DRIVER_CAPABILITIES=video,compute,utility nvffmpeg
Note: we're passing the driver capabilities flag -e VIDIA_DRIVER_CAPABILITIES=video,compute,utility
because by default GPU video capabilities are not exposed to the container. See Nvidoa Docker user guide for more details.
To transcode an mp4 video using hardware acceleration run:
docker run --gpus all -v "$PWD:$PWD" -w "$PWD" -e NVIDIA_DRIVER_CAPABILITIES=video,compute,utility nvffmpeg -hwaccel cuda -hwaccel_output_format cuda -i input.mp4 -c:v h264_nvenc output.mp4
Note: we're passing -v "$PWD:$PWD" -w "$PWD"
to docker to make the current working directory available within the running container.