Last active
December 2, 2021 13:06
-
-
Save kristofkeppens/d65f31d132acd3db36522ad7aa4dffda 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 | |
| #This script will compile and install a static ffmpeg build with support for nvenc un ubuntu. | |
| #See the prefix path and compile options if edits are needed to suit your needs. | |
| #install required things from apt | |
| installLibs(){ | |
| echo "Installing prerequisites" | |
| sudo apt-get update | |
| sudo apt-get -y --force-yes install autoconf automake build-essential libass-dev libfreetype6-dev libgpac-dev \ | |
| libsdl1.2-dev libtheora-dev libtool libva-dev libvdpau-dev libvorbis-dev libxcb1-dev libxcb-shm0-dev \ | |
| libxcb-xfixes0-dev pkg-config texi2html zlib1g-dev libgmp-dev cmake | |
| } | |
| #Install nvidia SDK | |
| installSDK(){ | |
| echo "Installing the nVidia NVENC SDK." | |
| cd ~/ffmpeg_sources | |
| git clone https://git.videolan.org/git/ffmpeg/nv-codec-headers.git | |
| cd nv-codec-headers | |
| git checkout n11.0.10.1 | |
| sudo make install | |
| } | |
| #Compile nasm | |
| compileNasm(){ | |
| echo "Compiling nasm" | |
| cd ~/ffmpeg_sources | |
| wget http://www.nasm.us/pub/nasm/releasebuilds/2.15/nasm-2.15.tar.gz | |
| tar xzvf nasm-2.15.tar.gz | |
| cd nasm-2.15 | |
| ./configure --prefix="$HOME/ffmpeg_build" --bindir="$HOME/ffmpeg_build/bin" | |
| make -j$(nproc) | |
| make -j$(nproc) install | |
| make -j$(nproc) distclean | |
| } | |
| #Compile libx264 | |
| compileLibX264(){ | |
| echo "Compiling libx264" | |
| cd ~/ffmpeg_sources | |
| git clone https://code.videolan.org/videolan/x264.git | |
| cd x264 | |
| PATH="$HOME/ffmpeg_build/bin:$PATH" ./configure --prefix="$HOME/ffmpeg_build" --bindir="$HOME/ffmpeg_build/bin" --enable-static | |
| PATH="$HOME/ffmpeg_build/bin:$PATH" make -j$(nproc) | |
| make -j$(nproc) install | |
| make -j$(nproc) distclean | |
| } | |
| #Compile libfdk-acc | |
| compileLibfdkaac(){ | |
| echo "Compiling libfdk-aac" | |
| cd ~/ffmpeg_sources | |
| git clone https://github.com/mstorsjo/fdk-aac.git | |
| cd fdk-aac | |
| autoreconf -fiv | |
| ./configure --prefix="$HOME/ffmpeg_build" --enable-static --disable-shared | |
| make -j$(nproc) | |
| make -j$(nproc) install | |
| make -j$(nproc) distclean | |
| } | |
| #Compile libmp3lame | |
| compileLibMP3Lame(){ | |
| echo "Compiling libmp3lame" | |
| cd ~/ffmpeg_sources | |
| wget http://downloads.sourceforge.net/project/lame/lame/3.99/lame-3.99.5.tar.gz | |
| tar xzvf lame-3.99.5.tar.gz | |
| cd lame-3.99.5 | |
| ./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 ~/ffmpeg_sources | |
| 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 | |
| ./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 ~/ffmpeg_sources | |
| git clone https://chromium.googlesource.com/webm/libvpx | |
| cd libvpx | |
| PATH="$HOME/ffmpeg_build/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/ffmpeg_build/bin:$PATH" make -j$(nproc) | |
| make -j$(nproc) install | |
| make -j$(nproc) clean | |
| } | |
| #Compilex265 | |
| compileX265(){ | |
| cd ~/ffmpeg_sources | |
| git clone https://github.com/videolan/x265.git | |
| cd x265 | |
| cd build/linux | |
| cmake -G "Unix Makefiles" -DCMAKE_INSTALL_PREFIX="$HOME/ffmpeg_build" -DENABLE_SHARED:bool=off ../../source | |
| make -j$(nproc) | |
| make -j$(nproc) install | |
| } | |
| #Compile ffmpeg | |
| compileFfmpeg(){ | |
| echo "Compiling ffmpeg" | |
| cd ~/ffmpeg_sources | |
| git clone https://github.com/FFmpeg/FFmpeg -b master | |
| cd FFmpeg | |
| PATH="$HOME/ffmpeg_build/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" \ | |
| --pkg-config-flags="--static" \ | |
| --extra-libs=-lpthread \ | |
| --bindir="$HOME/ffmpeg_build/bin" \ | |
| --enable-cuda-nvcc \ | |
| --enable-cuvid \ | |
| --enable-libnpp \ | |
| --extra-cflags="-I/usr/local/cuda/include/" \ | |
| --extra-ldflags="-L/usr/local/cuda/lib64/" \ | |
| --enable-gpl \ | |
| --enable-libass \ | |
| --enable-libfdk-aac \ | |
| --enable-vaapi \ | |
| --enable-libfreetype \ | |
| --enable-libmp3lame \ | |
| --enable-libopus \ | |
| --enable-libtheora \ | |
| --enable-libvorbis \ | |
| --enable-libvpx \ | |
| --enable-libx264 \ | |
| --enable-libx265 \ | |
| --enable-nonfree \ | |
| --enable-nvenc \ | |
| --enable-nvdec | |
| PATH="$HOME/ffmpeg_build/bin:$PATH" make -j$(nproc) | |
| make -j$(nproc) install | |
| make -j$(nproc) distclean | |
| hash -r | |
| } | |
| #The process | |
| cd ~ | |
| mkdir ffmpeg_sources | |
| installLibs | |
| InstallCUDASDK | |
| installSDK | |
| compileNasm | |
| compileLibX264 | |
| compileLibfdkaac | |
| compileLibMP3Lame | |
| compileLibOpus | |
| compileLibVpx | |
| compileX265 | |
| compileFfmpeg | |
| echo "Complete!" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment