Last active
June 11, 2020 10:21
-
-
Save geekteq/8d170117ca885d69463ba03c64591a97 to your computer and use it in GitHub Desktop.
This bash script will compile a static Ffmpeg build with NVENC and VAAPI hardware-accelerated support on Ubuntu in your home directory. You can modify the script to customize the build options as you see fit.
This file contains hidden or 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
#!/bin/bash | |
#install required things from apt | |
#updated for Ubuntu 18.04 and added YASM, SSL-support, SRT, AOM, X265, Patched X264 to get rid of keyintmin becoming "keyint/2+1" | |
# NOTE: This is currently not doing it's job so unless this message disappears don't try it :) | |
#forked from original here - https://gist.github.com/Brainiarc7/3f7695ac2a0905b05c5b | |
whoami="$(whoami)" | |
checkubuntuversion(){ | |
. /etc/os-release | |
ubunturequirement="18.04" | |
version=$(echo $VERSION_ID) | |
if [[ "$VERSION_ID" == "$ubunturequirement" ]]; then | |
echo "[ Ubuntu 18.04 detected - proceed ]" | |
else | |
echo "[ this is designed for Ubuntu 18.04 - due to Nvidia being a bit slow on the updates ]" | |
exit 0 | |
fi | |
} | |
installLibs(){ | |
echo "[ Installing prerequisites ]" | |
sudo dpkg --add-architecture i386 | |
sudo apt-get update | |
sudo apt-get install build-essential git yasm unzip wget sysstat nasm libc6:i386 \ | |
libavcodec-dev libavformat-dev libavutil-dev pkgconf g++ freeglut3-dev \ | |
libx11-dev libxmu-dev libxi-dev libglu1-mesa libglu1-mesa-dev autoconf \ | |
automake cmake git-core libass-dev libfreetype6-dev libsdl2-dev libtool libva-dev \ | |
libvdpau-dev libvorbis-dev libxcb1-dev libxcb-shm0-dev libxcb-xfixes0-dev libgnutls28-dev \ | |
openssl libssl-dev texinfo wget python3-pip python-pip unzip zlib1g-dev mercurial libnuma-dev \ | |
libtheora-dev | |
} | |
#install CUDA SDK | |
installCUDASDK(){ | |
echo "[ Installing CUDA and the latest driver repositories from repositories ]" | |
cd "$HOME/ffmpeg_sources" || exit | |
wget https://developer.download.nvidia.com/compute/cuda/repos/ubuntu1804/x86_64/cuda-ubuntu1804.pin | |
sudo mv cuda-ubuntu1804.pin /etc/apt/preferences.d/cuda-repository-pin-600 | |
wget http://developer.download.nvidia.com/compute/cuda/11.0.1/local_installers/cuda-repo-ubuntu1804-11-0-local_11.0.1-450.36.06-1_amd64.deb | |
sudo dpkg -i cuda-repo-ubuntu1804-11-0-local_11.0.1-450.36.06-1_amd64.deb | |
sudo apt-key add /var/cuda-repo-ubuntu1804-11-0-local/7fa2af80.pub | |
sudo apt-get update | |
sudo apt-get -o Dpkg::Options::="--force-overwrite" -y install cuda nvidia-cuda-toolkit gcc-6-locales g++-6-multilib gcc-6-doc \ | |
libstdc++6-6-dbg gcc-6-multilib libgcc1-dbg libgomp1-dbg libitm1-dbg libatomic1-dbg libasan3-dbg \ | |
liblsan0-dbg libtsan0-dbg libubsan0-dbg libcilkrts5-dbg libmpx2-dbg libquadmath0-dbg libstdc++-6-doc \ | |
libcupti-dev icedtea-8-plugin libnss-mdns fonts-ipafont-gothic \ | |
fonts-ipafont-mincho fonts-wqy-microhei fonts-wqy-zenhei fonts-indic | |
export PATH=/usr/local/cuda/bin${PATH:+:${PATH}} | |
export LD_LIBRARY_PATH=/usr/local/cuda/lib {LD_LIBRARY_PATH:+:${LD_LIBRARY_PATH}} | |
} | |
#Install nvidia SDK | |
installSDK(){ | |
echo "[ Installing the nVidia NVENC SDK ]" | |
cd "$HOME/ffmpeg_sources" || exit | |
wget -O Video_Codec_SDK_9.1.23.zip https://www.dropbox.com/s/nrl8lnwk11ezfpr/Video_Codec_SDK_9.1.23.zip?dl=0 | |
unzip Video_Codec_SDK_9.1.23 | |
sudo cp Video_Codec_SDK_9.1.23/Samples/common.mk /usr/local/include/ | |
git clone https://git.videolan.org/git/ffmpeg/nv-codec-headers.git | |
cd nv-codec-headers | |
make | |
sudo make install | |
} | |
#Compile nasm | |
compileNasm(){ | |
echo "[ Compiling nasm ]" | |
cd "$HOME/ffmpeg_sources" || exit | |
wget https://www.nasm.us/pub/nasm/releasebuilds/2.14.02/nasm-2.14.02.tar.bz2 | |
tar jxvf nasm-2.14.02.tar.bz2 | |
cd nasm-2.14.02 || exit | |
./configure --prefix="$HOME/ffmpeg_build" --bindir="$HOME/bin" | |
make -j"$(nproc)" | |
make -j"$(nproc)" install | |
make -j"$(nproc)" distclean | |
} | |
#Compile yasm | |
compileYasm(){ | |
echo "[ Compiling Yasm ]" | |
cd "$HOME/ffmpeg_sources" || exit | |
wget -O yasm-1.3.0.tar.gz https://www.tortall.net/projects/yasm/releases/yasm-1.3.0.tar.gz | |
tar xzvf yasm-1.3.0.tar.gz | |
cd yasm-1.3.0 || exit | |
./configure --prefix="$HOME/ffmpeg_build" --bindir="$HOME/bin" | |
make -j"$(nproc)" | |
make -j"$(nproc)" install | |
make -j"$(nproc)" distclean | |
} | |
#Compile libx264 | |
compileLibX264(){ | |
echo "[ Compiling libx264 ]" | |
cd "$HOME/ffmpeg_sources" || exit | |
git clone https://code.videolan.org/videolan/x264.git | |
cd x264 || exit | |
wget -O "$HOME/x264.patch" "https://www.dropbox.com/s/fp8wtrgc8b87e5i/x264.patch?dl=0" | |
patch "$HOME/ffmpeg_sources/x264/encoder/encoder.c" < "$HOME/x264.patch" | |
PATH="$HOME/bin:$PATH" ./configure --prefix="$HOME/ffmpeg_build" --bindir="$HOME/bin" --enable-static | |
PATH="$HOME/bin:$PATH" make -j"$(nproc)" | |
make -j"$(nproc)" install | |
make -j"$(nproc)" distclean | |
} | |
#Compile libfdk-acc | |
compileLibfdkaac(){ | |
echo "[ Compiling libfdk-aac ]" | |
cd "$HOME/ffmpeg_sources" || exit | |
git clone --depth 1 https://github.com/mstorsjo/fdk-aac | |
cd fdk-aac || exit | |
autoreconf -fiv | |
./configure --prefix="$HOME/ffmpeg_build" --disable-shared | |
make -j"$(nproc)" | |
make -j"$(nproc)" install | |
make -j"$(nproc)" distclean | |
} | |
#Compile libmp3lame | |
compileLibMP3Lame(){ | |
echo "[ Compiling libmp3lame ]" | |
cd "$HOME/ffmpeg_sources" || exit | |
wget 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 || exit | |
./configure --prefix="$HOME/ffmpeg_build" --enable-nasm --disable-shared | |
make -j"$(nproc)" | |
make -j"$(nproc)" install | |
make -j"$(nproc)" distclean | |
} | |
#Compile libopus | |
compileLibOpus(){ | |
echo "[ Compiling libopus ]" | |
cd "$HOME/ffmpeg_sources" || exit | |
wget http://downloads.xiph.org/releases/opus/opus-1.3.1.tar.gz | |
tar xzvf opus-1.3.1.tar.gz | |
cd opus-1.3.1 || exit | |
./configure --prefix="$HOME/ffmpeg_build" --disable-shared | |
make -j"$(nproc)" | |
make -j"$(nproc)" install | |
make -j"$(nproc)" distclean | |
} | |
#Compile libvpx | |
compileLibVpx(){ | |
echo "[ Compiling libvpx ]" | |
cd "$HOME/ffmpeg_sources" || exit | |
git clone https://chromium.googlesource.com/webm/libvpx | |
cd libvpx || exit | |
PATH="$HOME/bin:$PATH" ./configure --prefix="$HOME/ffmpeg_build" --disable-examples --enable-runtime-cpu-detect --enable-vp9 --enable-vp8 \ | |
--enable-postproc --enable-vp9-postproc --enable-multi-res-encoding --enable-webm-io --enable-better-hw-compatibility --enable-vp9-highbitdepth --enable-onthefly-bitpacking --enable-realtime-only \ | |
--cpu=native --as=nasm | |
PATH="$HOME/bin:$PATH" make -j"$(nproc)" | |
make -j"$(nproc)" install | |
make -j"$(nproc)" clean | |
} | |
#Compile libx265 | |
compileLibX265(){ | |
echo "[ Compiling libx265 ]" | |
cd "$HOME/ffmpeg_sources" || exit | |
hg clone https://bitbucket.org/multicoreware/x265 | |
cd x265/build/linux || exit | |
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 -j"$(nproc)" install | |
make -j"$(nproc)" clean | |
} | |
#Compile libaom | |
compileLibAom(){ | |
echo "[ Compiling libaom ]" | |
cd "$HOME/ffmpeg_sources" || exit | |
git clone --depth 1 https://aomedia.googlesource.com/aom | |
mkdir -p aom_build | |
cd aom_build || exit | |
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 -j"$(nproc)" install | |
make -j"$(nproc)" clean | |
} | |
#Compile libsrt | |
compileLibSRT(){ | |
echo "[ Compiling SRT ]" | |
cd "$HOME/ffmpeg_sources" || exit | |
git clone --depth 1 https://github.com/Haivision/srt.git | |
mkdir srt/build | |
cd srt/build || exit | |
cmake -DCMAKE_INSTALL_PREFIX="$HOME/ffmpeg_build" -DENABLE_C_DEPS=ON -DENABLE_SHARED=OFF -DENABLE_STATIC=ON .. | |
make -j"$(nproc)" | |
make -j"$(nproc)" install | |
make -j"$(nproc)" clean | |
} | |
#Compile ffmpeg | |
compileFfmpeg(){ | |
echo "[ Compiling ffmpeg ]" | |
cd "$HOME/ffmpeg_sources" || exit | |
git clone https://github.com/FFmpeg/FFmpeg -b master | |
cd FFmpeg || exit | |
PATH="$HOME/bin:$PATH" PKG_CONFIG_PATH="$HOME/ffmpeg_build/lib/pkgconfig" ./configure \ | |
--prefix="$HOME/ffmpeg_build" \ | |
--pkg-config-flags="--static" \ | |
--extra-cflags="-I$HOME/ffmpeg_build/include" \ | |
--extra-ldflags="-L$HOME/ffmpeg_build/lib" \ | |
--extra-cflags="-I/usr/local/cuda/include" \ | |
--extra-ldflags="-L/usr/local/cuda/lib64" \ | |
--extra-libs="-lpthread -lm" \ | |
--bindir="$HOME/bin" \ | |
--enable-cuda \ | |
--enable-cuda-nvcc \ | |
--enable-cuvid \ | |
--enable-libnpp \ | |
--enable-gpl \ | |
--enable-libass \ | |
--enable-libfdk-aac \ | |
--enable-vaapi \ | |
--enable-libfreetype \ | |
--enable-libmp3lame \ | |
--enable-libopus \ | |
--enable-libtheora \ | |
--enable-libvorbis \ | |
--enable-libvpx \ | |
--enable-libx264 \ | |
--enable-nonfree \ | |
--enable-nvenc \ | |
--enable-libsrt \ | |
--enable-libaom \ | |
--enable-libx264 \ | |
--enable-libx265 \ | |
--enable-openssl | |
PATH="$HOME/bin:$PATH" make -j"$(nproc)" | |
make -j"$(nproc)" install | |
make -j"$(nproc)" distclean | |
hash -r | |
} | |
#The process | |
cd "$HOME" || exit | |
checkubuntuversion | |
mkdir ffmpeg_sources | |
installLibs | |
installCUDASDK | |
installSDK | |
compileNasm | |
compileYasm | |
compileLibX264 | |
compileLibfdkaac | |
compileLibMP3Lame | |
compileLibOpus | |
compileLibVpx | |
compileLibX265 | |
compileLibAom | |
compileLibSRT | |
compileFfmpeg | |
echo "[ Complete! ]" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment