Last active
October 17, 2024 11:57
-
-
Save kiyoon/55a7bf31f926edec94abebb22dc3eabd to your computer and use it in GitHub Desktop.
Install nvidia accelerated ffmpeg in a conda environment.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
git clone https://git.videolan.org/git/ffmpeg/nv-codec-headers.git | |
cd nv-codec-headers | |
vi Makefile # change the first line to PREFIX = ${CONDA_PREFIX} | |
make install | |
cd .. | |
git clone https://git.ffmpeg.org/ffmpeg.git | |
cd ffmpeg | |
git checkout n4.2.2 | |
conda install nasm | |
./configure --prefix=$CONDA_PREFIX --enable-cuda-sdk --enable-cuvid --enable-nvenc --enable-nonfree --enable-libnpp --extra-cflags=-I/usr/local/cuda/include --extra-ldflags=-L/usr/local/cuda/lib64 | |
make -j 10 | |
make install | |
###### DONE ###### | |
### TIP: | |
# If CUDA is not installed, you can install without root permission as below. | |
bash cuda_10.2.89_440.33.01_linux.run --silent --override --toolkit --toolkitpath="$CUDA_DIR" --librarypath="$CUDA_LIB_DIR" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
mkdir -p ~/ffmpeg_sources ~/bin | |
# NASM | |
cd ~/ffmpeg_sources && \ | |
wget https://www.nasm.us/pub/nasm/releasebuilds/2.15.05/nasm-2.15.05.tar.bz2 && \ | |
tar xjvf nasm-2.15.05.tar.bz2 && \ | |
cd nasm-2.15.05 && \ | |
./autogen.sh && \ | |
PATH="$HOME/bin:$PATH" ./configure --prefix="$HOME/ffmpeg_build" --bindir="$HOME/bin" && \ | |
make -j$(nproc) && \ | |
make install | |
# libx264 | |
cd ~/ffmpeg_sources && \ | |
git -C x264 pull 2> /dev/null || git clone --depth 1 https://code.videolan.org/videolan/x264.git && \ | |
cd x264 && \ | |
PATH="$HOME/bin:$PATH" PKG_CONFIG_PATH="$HOME/ffmpeg_build/lib/pkgconfig" ./configure --prefix="$HOME/ffmpeg_build" --bindir="$HOME/bin" --enable-static --enable-pic && \ | |
PATH="$HOME/bin:$PATH" make -j$(nproc) && \ | |
make install | |
# cmake (for libx265, libaom, libsvtav1. if not installed already) | |
cd ~/bin && \ | |
wget https://github.com/Kitware/CMake/releases/download/v3.21.2/cmake-3.21.2-linux-x86_64.tar.gz && \ | |
tar xzf cmake-3.21.2-linux-x86_64.tar.gz --strip-components=1 -C "$HOME/ffmpeg_build" | |
# libx265 | |
cd ~/ffmpeg_sources && \ | |
git -C x265_git pull 2> /dev/null || git clone https://bitbucket.org/multicoreware/x265_git && \ | |
cd x265_git/build/linux && \ | |
PATH="$HOME/bin:$PATH" cmake -G "Unix Makefiles" -DCMAKE_INSTALL_PREFIX="$HOME/ffmpeg_build" -DENABLE_SHARED=off ../../source && \ | |
PATH="$HOME/bin:$PATH" make -j$(nproc) && \ | |
make install | |
# yasm (for libvpx. if not installed already) | |
cd ~/bin && \ | |
wget http://www.tortall.net/projects/yasm/releases/yasm-1.3.0.tar.gz && \ | |
tar xzf yasm-1.3.0.tar.gz && \ | |
cd yasm-1.3.0 && \ | |
./configure --prefix="$HOME/ffmpeg_build" && \ | |
make -j$(nproc) && make install | |
# libvpx | |
cd ~/ffmpeg_sources && \ | |
git -C libvpx pull 2> /dev/null || git clone --depth 1 https://chromium.googlesource.com/webm/libvpx.git && \ | |
cd libvpx && \ | |
PATH="$HOME/bin:$PATH" ./configure --prefix="$HOME/ffmpeg_build" --disable-examples --disable-unit-tests --enable-vp9-highbitdepth --as=yasm && \ | |
PATH="$HOME/bin:$HOME/ffmpeg_build/bin:$PATH" make -j$(nproc) && \ | |
make install | |
# gnu m4 (for autoconf) | |
cd ~/bin && \ | |
wget http://ftp.gnu.org/gnu/m4/m4-1.4.19.tar.gz && \ | |
tar xzf m4-1.4.19.tar.gz && \ | |
cd m4-1.4.19 && \ | |
./configure --prefix="$HOME/ffmpeg_build" && \ | |
make -j$(nproc) && \ | |
make install | |
# autoconf (for libfdk-aac. if not installed already) | |
cd ~/bin && \ | |
wget http://ftp.gnu.org/gnu/autoconf/autoconf-2.71.tar.gz && \ | |
tar xzf autoconf-2.71.tar.gz | |
cd autoconf-2.71 && \ | |
PATH="$HOME/ffmpeg_build/bin:$PATH" ./configure --prefix="$HOME/ffmpeg_build" && \ | |
make -j$(nproc) && \ | |
make install | |
# automake | |
cd ~/bin && \ | |
wget http://ftp.gnu.org/gnu/automake/automake-1.16.tar.gz && \ | |
tar xfz automake-1.16.tar.gz && \ | |
cd automake-1.16 && \ | |
PATH="$HOME/ffmpeg_build/bin:$PATH" ./configure --prefix="$HOME/ffmpeg_build" && \ | |
make -j $(nproc) && make install | |
# libtool | |
cd ~/bin && \ | |
wget http://ftp.jaist.ac.jp/pub/GNU/libtool/libtool-2.4.6.tar.gz && \ | |
tar xvfz libtool-2.4.6.tar.gz && \ | |
cd libtool-2.4.6 && \ | |
PATH="$HOME/ffmpeg_build/bin:$PATH" ./configure --prefix="$HOME/ffmpeg_build" && \ | |
make -j $(nproc) && make install | |
# libfdk-aac | |
cd ~/ffmpeg_sources && \ | |
git -C fdk-aac pull 2> /dev/null || git clone --depth 1 https://github.com/mstorsjo/fdk-aac && \ | |
cd fdk-aac && \ | |
PATH="$HOME/ffmpeg_build/bin:$PATH" autoreconf -fiv && \ | |
./configure --prefix="$HOME/ffmpeg_build" --disable-shared && \ | |
make -j$(nproc) && \ | |
make install | |
# libmp3lame | |
cd ~/ffmpeg_sources && \ | |
wget -O lame-3.100.tar.gz https://downloads.sourceforge.net/project/lame/lame/3.100/lame-3.100.tar.gz && \ | |
tar xzvf lame-3.100.tar.gz && \ | |
cd lame-3.100 && \ | |
PATH="$HOME/bin:$PATH" ./configure --prefix="$HOME/ffmpeg_build" --bindir="$HOME/bin" --disable-shared --enable-nasm && \ | |
PATH="$HOME/bin:$PATH" make -j$(nproc)&& \ | |
make install | |
# libopus | |
cd ~/ffmpeg_sources && \ | |
git -C opus pull 2> /dev/null || git clone --depth 1 https://github.com/xiph/opus.git && \ | |
cd opus && \ | |
PATH="$HOME/ffmpeg_build/bin:$PATH" ./autogen.sh && \ | |
./configure --prefix="$HOME/ffmpeg_build" --disable-shared && \ | |
make -j$(nproc) && \ | |
make install | |
# libaom (av1 video) | |
cd ~/ffmpeg_sources && \ | |
git -C aom pull 2> /dev/null || git clone --depth 1 https://aomedia.googlesource.com/aom && \ | |
mkdir -p aom_build && \ | |
cd aom_build && \ | |
PATH="$HOME/bin:$PATH" cmake -G "Unix Makefiles" -DCMAKE_INSTALL_PREFIX="$HOME/ffmpeg_build" -DENABLE_SHARED=off -DENABLE_NASM=on ../aom && \ | |
PATH="$HOME/bin:$PATH" make -j$(nproc) && \ | |
make install | |
# libsvtav1 (av1 video) | |
cd ~/ffmpeg_sources && \ | |
git -C SVT-AV1 pull 2> /dev/null || git clone https://gitlab.com/AOMediaCodec/SVT-AV1.git && \ | |
mkdir -p SVT-AV1/build && \ | |
cd SVT-AV1/build && \ | |
PATH="$HOME/bin:$PATH" cmake -G "Unix Makefiles" -DCMAKE_INSTALL_PREFIX="$HOME/ffmpeg_build" -DCMAKE_BUILD_TYPE=Release -DBUILD_DEC=OFF -DBUILD_SHARED_LIBS=OFF .. && \ | |
PATH="$HOME/bin:$PATH" make -j$(nproc) && \ | |
make install | |
# libdav1d (av1 decode fast) | |
conda install meson | |
cd ~/ffmpeg_sources && \ | |
git -C dav1d pull 2> /dev/null || git clone --depth 1 https://code.videolan.org/videolan/dav1d.git && \ | |
mkdir -p dav1d/build && \ | |
cd dav1d/build && \ | |
meson setup -Denable_tools=false -Denable_tests=false --default-library=static .. --prefix "$HOME/ffmpeg_build" --libdir="$HOME/ffmpeg_build/lib" && \ | |
ninja && \ | |
ninja install | |
# libvmaf | |
cd ~/ffmpeg_sources && \ | |
wget https://github.com/Netflix/vmaf/archive/v2.1.1.tar.gz && \ | |
tar xvf v2.1.1.tar.gz && \ | |
mkdir -p vmaf-2.1.1/libvmaf/build &&\ | |
cd vmaf-2.1.1/libvmaf/build && \ | |
meson setup -Denable_tests=false -Denable_docs=false --buildtype=release --default-library=static .. --prefix "$HOME/ffmpeg_build" --bindir="$HOME/bin" --libdir="$HOME/ffmpeg_build/lib" && \ | |
ninja && \ | |
ninja install | |
# gnutls | |
cd ~/bin && \ | |
git clone https://gitlab.com/gnutls/gnutls.git && \ | |
cd gnutls && \ | |
git checkout 3.7.2 && \ | |
./bootstrap && \ | |
./configure --prefix="$HOME/ffmpeg_build" && \ | |
make -j$(nproc) && make install | |
# nv-codec-headers | |
cd ~/bin && \ | |
git clone https://git.videolan.org/git/ffmpeg/nv-codec-headers.git && \ | |
cd nv-codec-headers && \ | |
vi Makefile # change the first line to PREFIX = ${CONDA_PREFIX} | |
make install | |
# ffmpeg | |
cd ~/ffmpeg_sources && \ | |
wget -O ffmpeg-snapshot.tar.bz2 https://ffmpeg.org/releases/ffmpeg-snapshot.tar.bz2 && \ | |
tar xjvf ffmpeg-snapshot.tar.bz2 && \ | |
cd ffmpeg && \ | |
PATH="$HOME/bin:$CUDA_DIR/bin:$PATH" PKG_CONFIG_PATH="$HOME/ffmpeg_build/lib/pkgconfig" ./configure \ | |
--prefix="$HOME/ffmpeg_build" \ | |
--extra-cflags="-I$HOME/ffmpeg_build/include" \ | |
--extra-ldflags="-L$HOME/ffmpeg_build/lib" \ | |
--extra-libs="-lpthread -lm" \ | |
--ld="g++" \ | |
--bindir="$HOME/bin" \ | |
--enable-gpl \ | |
--enable-gnutls \ | |
--enable-libaom \ | |
--enable-libfdk-aac \ | |
--enable-libfreetype \ | |
--enable-libmp3lame \ | |
--enable-libopus \ | |
--enable-libsvtav1 \ | |
--enable-libdav1d \ | |
--enable-libvpx \ | |
--enable-libx264 \ | |
--enable-nonfree \ | |
--enable-cuda-sdk \ | |
--enable-cuvid \ | |
--enable-nvenc \ | |
--enable-libnpp \ | |
--extra-cflags=-I"$CUDA_DIR/include" --extra-ldflags=-L"$CUDA_DIR/lib64" && \ | |
PATH="$HOME/bin:$CUDA_DIR/bin:$PATH" make -j $(nproc) && \ | |
make install && \ | |
hash -r | |
# --pkg-config-flags="--static" \ | |
# --enable-libass \ | |
# --enable-libvorbis \ | |
# --enable-libx265 \ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
https://trac.ffmpeg.org/wiki/CompilationGuide/Ubuntu