Skip to content

Instantly share code, notes, and snippets.

@SeeRich
Last active March 4, 2025 18:37
Show Gist options
  • Save SeeRich/2afe2a71d08a2a5492ec5d5ba2feca5d to your computer and use it in GitHub Desktop.
Save SeeRich/2afe2a71d08a2a5492ec5d5ba2feca5d to your computer and use it in GitHub Desktop.
NVIDIA Accelerated Ubuntu 22.04 FFmpeg

FFMPEG:

Build and install CUDA-accelerated FFmpeg for all users on the system.

DEPENDENCIES:

sudo apt-get update -qq && sudo apt-get -y install \
  autoconf \
  automake \
  build-essential \
  git-core \
  libass-dev \
  libfreetype6-dev \
  libgnutls28-dev \
  libmp3lame-dev \
  libx264-dev \
  libx265-dev libnuma-dev \
  libtool \
  libvorbis-dev \
  libunistring-dev \
  meson \
  ninja-build \
  pkg-config \
  texinfo \
  wget \
  yasm \
  zlib1g-dev \
  nasm \
  libdav1d-dev

Setup NVENC/NVDEC support (NVIDIA driver version matters for branch here)

git clone -b n12.1.14.0 --single-branch https://git.videolan.org/git/ffmpeg/nv-codec-headers.git && \
cd nv-codec-headers && sudo make install && cd ..

CONFIGURE AND BUILD

# Put cuda compiler on the path
PATH=/usr/local/cuda/bin:$PATH
# Set ffmpeg version
FFMPEG_VER=7.1
# Create install directory
INSTALL_DIR=/usr/local/ffmpeg
sudo mkdir -p $INSTALL_DIR
# Create sources and install directories
mkdir -p ffmpeg_sources && \
cd ./ffmpeg_sources && \
wget -O ffmpeg-$FFMPEG_VER.tar.bz2 https://ffmpeg.org/releases/ffmpeg-$FFMPEG_VER.tar.bz2 && \
tar xjvf ffmpeg-$FFMPEG_VER.tar.bz2 && \
cd ffmpeg-$FFMPEG_VER
PATH="$INSTALL_DIR/bin:$PATH" PKG_CONFIG_PATH="ffmpeg_build/lib/pkgconfig" ./configure \
  --prefix="ffmpeg_build" \
  --pkg-config-flags="--static" \
  --extra-cflags="-Iffmpeg_build/include" \
  --extra-ldflags="-Lffmpeg_build/lib" \
  --extra-cflags=-I/usr/local/cuda/include \
  --extra-ldflags=-L/usr/local/cuda/lib64 \
  --bindir="$INSTALL_DIR/bin" \
  --enable-gnutls \
  --enable-libass \
  --enable-libfreetype \
  --enable-libmp3lame \
  --enable-libdav1d \
  --enable-libvorbis \
  --enable-nonfree \
  --enable-gpl \
  --enable-libx264 \
  --enable-libx265 \
  --enable-cuda-nvcc \
  --enable-libnpp
PATH="$INSTALL_DIR/bin:$PATH" make -j20 && \
sudo make install
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment