Installing FFmpeg on Nvidia CUDA container
This documentation describes to install FFmpeg on nvidia/cuda container to use the Nvidia GPU to accelerate encoding.
If you want to know how to install FFmpeg with NVIDIA GPU on Linux, go to see that.
FFmpeg can support hardware-based decoding and encoding for Nvidia GPU card. With the help of Nvidia GPU, h264_nvenc can lead encoding speed with 5x faster than libx264 in GTX1080 card.
Let's see how to install everything one by one on the Nvidia CUDA Docker container nvidia/cuda:12.2.0-devel-ubuntu20.04, in which CUDA toolkit and GPU driver are already included.
It must use
nvidia/cuda:xxx-devel-xxximage to buildFFmpeg, because thedevimage contain all the necessary libraries.
Prerequisites
Make sure Nvidia GPU Driver is installed in your host machine! As it will be mounted into the container.
Use ldconfig to check if the required Nvidia GPU driver libraries are available inside the container. Such as,
ldconfig -p | grep libcuda
When running in the
nvidia/cudaDocker container, what Nvidia libraries(from the host machine) should be mounted inside the container are specified by theNVIDIA_DRIVER_CAPABILITIESenv variable, see driver-capabilities. Here forFFmpegto employ GPU, it should be included at least asNVIDIA_DRIVER_CAPABILITIES=video,utility.
Step by Step
docker run --rm --runtime=nvidia \
-e NVIDIA_VISIBLE_DEVICES=all \
-e NVIDIA_DRIVER_CAPABILITIES=compute,utility \
nvidia/cuda nvidia-smi
docker run --rm --runtime=nvidia \
-e NVIDIA_VISIBLE_DEVICES=all \
-e NVIDIA_DRIVER_CAPABILITIES=compute,utility \
nvidia/cuda bash
Complete Dockerfile
loading...
Known issues
Nvidia Docker encoding stops after long running time with such error message: CUDA_ERROR_NO_DEVICE: no CUDA-capable device is detected.
Possible solution:
Edit /etc/defautls/grub,
GRUB_CMDLINE_LINUX_DEFAULT="quiet splash systemd.unified_cgroup_hierarchy=0"
Then run update-grub and reboot.
References
Using FFmpeg with NVIDIA GPU Hardware Acceleration - NVIDIA Docs
NVIDIA FFmpeg Transcoding Guide | NVIDIA Technical Blog
