예전에도 언급한 것이지만 ffmpeg를 컨테이너에서 컴파일해서 사용하고 싶었다. CUDA와 관련되어 어려번 삽질한 경험이 있어서 한 번에 할 수 있는 방법을 찾아 보았다. 예전보다 AI가 응답을 잘 해주기 때문에 개발자용 컨테이너가 있는 것을 알게 되었다. 그래서 다음과 같은 방법을 시도했다.
호스트에 CUDA 최신 버전을 설치한다.
CUDA Toolkit 과 Driver를 설치한다. 난 proprietary kernel module 를 이용했다.
CUDA와 관련된 것들이 있는 컨테이너를 이용한다. 하다보니 ubuntu 22.04 를 선택했는데 24.04를 선택했어도 잘 될 것 같다.
4번째 줄의 옵션을 저렇게 하지 않으면, 인코딩 할 때에 오류가 생긴다.
Specialized Configurations with Docker — NVIDIA Container Toolkit
Users can control the behavior of the NVIDIA container runtime using environment variables – especially for
enumerating the GPUs and the capabilities of the driver.
Each environment variable maps to an command-line argument for nvidia-container-cli from libnvidia-container.
These variables are already set in the NVIDIA provided base CUDA images.
enumerating the GPUs and the capabilities of the driver.
Each environment variable maps to an command-line argument for nvidia-container-cli from libnvidia-container.
These variables are already set in the NVIDIA provided base CUDA images.
docker run --gpus all \
-it --name ffmpeg \
--restart always \
-e NVIDIA_DRIVER_CAPABILITIES=all \
nvidia/cuda:12.9.1-devel-ubuntu22.04
echo 'Acquire::http::Proxy "http://rcc01.work:3142";' > /etc/apt/apt.conf
rm -rf /etc/localtime
ln -s /usr/share/zoneinfo/Asia/Seoul /etc/localtime
apt-get -y update && apt-get -y upgrade
apt-get -y install apt-utils build-essential git nasm pkg-config libx264-dev libx265-dev libnuma-dev libpostproc-dev libass-dev fontconfig libavcodec-dev libavformat-dev software-properties-common
다음 방법으로 ffmpeg를 설치한다.
Using FFmpeg with NVIDIA GPU Hardware Acceleration – NVIDIA Docs
All NVIDIA® GPUs starting with Kepler generation support fully-accelerated hardware video encoding and decoding. The hardware encoder and hardware decoder are referred to as NVENC and NVDEC, respectively, in the rest of the document.
ffnvcodec 설치한다.
git clone https://git.videolan.org/git/ffmpeg/nv-codec-headers.git
cd nv-codec-headers
sudo make install
cd –
ffmpeg를 다운 받는다.
git clone https://git.ffmpeg.org/ffmpeg.git ffmpeg/
./configure는 다음을 것으로 한다.
./configure --enable-nonfree --enable-cuda --enable-cuvid --enable-nvenc --enable-cuda-nvcc --enable-libnpp --extra-cflags=-I/usr/local/cuda/include --extra-ldflags=-L/usr/local/cuda/lib64 --disable-static --enable-shared --enable-gpl --enable-libx264 --enable-libx265 --enable-libass --enable-fontconfig
echo '/usr/local/lib' >> /etc/ld.so.conf
echo 'export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/cuda/lib64' >> ~/.bashrc
make -j 6
make install