From 8d1758375496bb35c5eaedb5941be70e166762b7 Mon Sep 17 00:00:00 2001 From: Ilya Evseev Date: Mon, 15 Oct 2018 18:38:34 +0300 Subject: [PATCH] Adopted to Ubuntu-18.04 and CentOS 7. --- compile-ffmpeg-nvenc.sh | 169 -------------------------- dynlink_cuda.h.patch | 15 +++ ffmpeg-build-static.sh | 261 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 276 insertions(+), 169 deletions(-) delete mode 100644 compile-ffmpeg-nvenc.sh create mode 100644 dynlink_cuda.h.patch create mode 100755 ffmpeg-build-static.sh diff --git a/compile-ffmpeg-nvenc.sh b/compile-ffmpeg-nvenc.sh deleted file mode 100644 index 2c09156..0000000 --- a/compile-ffmpeg-nvenc.sh +++ /dev/null @@ -1,169 +0,0 @@ -#!/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 -} - -#install CUDA SDK -InstallCUDASDK(){ -echo "Installing CUDA and the latest driver repositories from repositories" -cd ~/ffmpeg_sources -wget -c -v -nc https://developer.download.nvidia.com/compute/cuda/repos/ubuntu1604/x86_64/cuda-repo-ubuntu1604_9.2.88-1_amd64.deb -sudo dpkg -i cuda-repo-ubuntu1604_9.2.88-1_amd64.deb -sudo apt-key adv --fetch-keys http://developer.download.nvidia.com/compute/cuda/repos/ubuntu1604/x86_64/7fa2af80.pub -sudo apt-get -y update -sudo apt-get -y install cuda -sudo add-apt-repository ppa:graphics-drivers/ppa -sudo apt-get update && sudo apt-get -y upgrade -} - -#Install nvidia SDK -installSDK(){ -echo "Installing the nVidia NVENC SDK." -cd ~/ffmpeg_sources -cd ~/ffmpeg_sources -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 ~/ffmpeg_sources -wget http://www.nasm.us/pub/nasm/releasebuilds/2.14rc0/nasm-2.14rc0.tar.gz -tar xzvf nasm-2.14rc0.tar.gz -cd nasm-2.14rc0 -./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 ~/ffmpeg_sources -wget http://download.videolan.org/pub/x264/snapshots/last_x264.tar.bz2 -tar xjvf last_x264.tar.bz2 -cd x264-snapshot* -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 -compileLibfdkcc(){ -echo "Compiling libfdk-cc" -sudo apt-get install unzip -cd ~/ffmpeg_sources -wget -O fdk-aac.zip https://github.com/mstorsjo/fdk-aac/zipball/master -unzip fdk-aac.zip -cd mstorsjo-fdk-aac* -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" -sudo apt-get install nasm -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.2.1.tar.gz -tar xzvf opus-1.2.1.tar.gz -cd opus-1.2.1 -./configure --prefix="$HOME/ffmpeg_build" --disable-shared -make -j$(nproc) -make -j$(nproc) install -make -j$(nproc) distclean -} - -#Compile libvpx -compileLibPvx(){ -echo "Compiling libvpx" -cd ~/ffmpeg_sources -git clone https://chromium.googlesource.com/webm/libvpx -cd libvpx -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 ffmpeg -compileFfmpeg(){ -echo "Compiling ffmpeg" -cd ~/ffmpeg_sources -git clone https://github.com/FFmpeg/FFmpeg -b master -cd FFmpeg -PATH="$HOME/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" \ - --bindir="$HOME/bin" \ - --enable-cuda-sdk \ - --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-nonfree \ - --enable-nvenc -PATH="$HOME/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 -compileLibfdkcc -compileLibMP3Lame -compileLibOpus -compileLibPvx -compileFfmpeg -echo "Complete!" \ No newline at end of file diff --git a/dynlink_cuda.h.patch b/dynlink_cuda.h.patch new file mode 100644 index 0000000..f44b639 --- /dev/null +++ b/dynlink_cuda.h.patch @@ -0,0 +1,15 @@ +--- ffmpeg-build-static-binaries/include/ffnvcodec/dynlink_cuda.h.orig 2018-10-14 21:53:25.000000000 +0300 ++++ ffmpeg-build-static-binaries/include/ffnvcodec/dynlink_cuda.h 2018-10-14 22:01:15.791295749 +0300 +@@ -100,9 +100,12 @@ + CU_EXTERNAL_MEMORY_HANDLE_TYPE_D3D12_RESOURCE = 5, + } CUexternalMemoryHandleType; + ++#ifndef CU_UUID_HAS_BEEN_DEFINED ++#define CU_UUID_HAS_BEEN_DEFINED + typedef struct CUuuid_st { + char bytes[16]; + } CUuuid; ++#endif + + typedef struct CUDA_MEMCPY2D_st { + size_t srcXInBytes; diff --git a/ffmpeg-build-static.sh b/ffmpeg-build-static.sh new file mode 100755 index 0000000..69b50c8 --- /dev/null +++ b/ffmpeg-build-static.sh @@ -0,0 +1,261 @@ +#!/bin/sh -e + +#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. + +# Based on: https://trac.ffmpeg.org/wiki/CompilationGuide/Ubuntu +# Based on: https://gist.github.com/Brainiarc7/3f7695ac2a0905b05c5b +# Rewritten here: https://github.com/ilyaevseev/ffmpeg-build-static/ + + +# Globals +NASM_VERSION="2.14rc15" +YASM_VERSION="1.3.0" +LAME_VERSION="3.100" +OPUS_VERSION="1.2.1" +CUDA_VERSION="10.0.130-1" +CUDA_REPO_KEY="http://developer.download.nvidia.com/compute/cuda/repos/ubuntu1604/x86_64/7fa2af80.pub" +CUDA_DIR="/usr/local/cuda" +WORK_DIR="$HOME/ffmpeg-build-static-sources" +DEST_DIR="$HOME/ffmpeg-build-static-binaries" + +mkdir -p "$WORK_DIR" "$DEST_DIR" "$DEST_DIR/bin" + +export PATH="$DEST_DIR/bin:$PATH" + +#### Routines ################################################ + +Wget() { wget -cN "$@"; } + +installAptLibs() { + 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 \ + wget software-properties-common unzip cmake mercurial +} + +installYumLibs() { + sudo yum -y install autoconf automake bzip2 cmake freetype-devel gcc gcc-c++ git libtool make mercurial pkgconfig zlib-devel \ + libass-devel tibtheora-devel libvorbis-devel libva-devel \ + wget unzip cmake mercurial patch +} + +installLibs() { + echo "Installing prerequisites" + . /etc/os-release + if test "$ID" = "ubuntu"; then installAptLibs; else installYumLibs; fi +} + +installCUDASDKdeb() { + UBUNTU_VERSION="$1" + local CUDA_REPO_URL="https://developer.download.nvidia.com/compute/cuda/repos/ubuntu${UBUNTU_VERSION}/x86_64/cuda-repo-ubuntu1804_${CUDA_VERSION}_amd64.deb" + Wget "$CUDA_REPO_URL" + sudo dpkg -i "$(basename "$CUDA_REPO_URL")" + sudo apt-key adv --fetch-keys "$CUDA_REPO_KEY" + sudo apt-get -y update + sudo apt-get -y install cuda + + sudo add-apt-repository -y ppa:graphics-drivers/ppa + sudo apt-get -y update + sudo apt-get -y upgrade +} + +installCUDASDKyum() { + rpm -q cuda-repo-rhel7 2>/dev/null || + yum install -y "https://developer.download.nvidia.com/compute/cuda/repos/rhel7/x86_64/cuda-repo-rhel7-${CUDA_VERSION}.x86_64.rpm" + yum install -y cuda +} + +installCUDASDK() { + echo "Installing CUDA and the latest driver repositories from repositories" + cd "$WORK_DIR/" + + . /etc/os-release + case "$ID-$VERSION_ID" in + ubuntu-16.04 ) installCUDASDKdeb 1604 ;; + ubuntu-18.04 ) installCUDASDKdeb 1804 ;; + centos-7 ) installCUDASDKyum ;; + * ) echo "ERROR: only CentOS 7, Ubuntu 16.04 or 18.04 are supported now."; exit 1;; + esac +} + +installNvidiaSDK() { + echo "Installing the nVidia NVENC SDK." + cd "$WORK_DIR/" + test -d nv-codec-headers || git clone https://git.videolan.org/git/ffmpeg/nv-codec-headers.git + cd nv-codec-headers + git pull + make + make install PREFIX="$DEST_DIR" + patch -d "$DEST_DIR" -p1 < "$(dirname "$0")/dynlink_cuda.h.patch" +} + +compileNasm() { + echo "Compiling nasm" + cd "$WORK_DIR/" + Wget "http://www.nasm.us/pub/nasm/releasebuilds/$NASM_VERSION/nasm-$NASM_VERSION.tar.gz" + tar xzvf "nasm-$NASM_VERSION.tar.gz" + cd "nasm-$NASM_VERSION" + ./configure --prefix="$DEST_DIR" --bindir="$DEST_DIR/bin" + make -j$(nproc) + make install distclean +} + +compileYasm() { + echo "Compiling yasm" + cd "$WORK_DIR/" + Wget "http://www.tortall.net/projects/yasm/releases/yasm-$YASM_VERSION.tar.gz" + tar xzvf "yasm-$YASM_VERSION.tar.gz" + cd "yasm-$YASM_VERSION/" + ./configure --prefix="$DEST_DIR" --bindir="$DEST_DIR/bin" + make -j$(nproc) + make install distclean +} + +compileLibX264() { + echo "Compiling libx264" + cd "$WORK_DIR/" + Wget http://download.videolan.org/pub/x264/snapshots/last_x264.tar.bz2 + rm -rf x264-snapshot*/ || : + tar xjvf last_x264.tar.bz2 + cd x264-snapshot* + ./configure --prefix="$DEST_DIR" --bindir="$DEST_DIR/bin" --enable-static --enable-pic + make -j$(nproc) + make install distclean +} + +compileLibX265() { + if cd "$WORK_DIR/x265/"; then + hg pull + hg update + else + hg clone https://bitbucket.org/multicoreware/x265 + fi + + cd "$WORK_DIR/x265/build/linux/" + cmake -G "Unix Makefiles" -DCMAKE_INSTALL_PREFIX="$DEST_DIR" -DENABLE_SHARED:bool=off ../../source + make -j$(nproc) + make install +} + +compileLibAom() { + cd "$WORK_DIR/" + test -d aom/.git || git clone --depth 1 https://aomedia.googlesource.com/aom + cd aom + git pull + mkdir ../aom_build + cd ../aom_build + cmake -G "Unix Makefiles" -DCMAKE_INSTALL_PREFIX="$DEST_DIR" -DENABLE_SHARED=off -DENABLE_NASM=on ../aom + make -j$(nproc) + make install +} + +compileLibfdkcc() { + echo "Compiling libfdk-cc" + cd "$WORK_DIR/" + Wget -O fdk-aac.zip https://github.com/mstorsjo/fdk-aac/zipball/master + unzip -o fdk-aac.zip + cd mstorsjo-fdk-aac* + autoreconf -fiv + ./configure --prefix="$DEST_DIR" --disable-shared + make -j$(nproc) + make install distclean +} + +compileLibMP3Lame() { + echo "Compiling libmp3lame" + cd "$WORK_DIR/" + Wget "http://downloads.sourceforge.net/project/lame/lame/$LAME_VERSION/lame-$LAME_VERSION.tar.gz" + tar xzvf "lame-$LAME_VERSION.tar.gz" + cd "lame-$LAME_VERSION" + ./configure --prefix="$DEST_DIR" --enable-nasm --disable-shared + make -j$(nproc) + make install distclean +} + +compileLibOpus() { + echo "Compiling libopus" + cd "$WORK_DIR/" + Wget "http://downloads.xiph.org/releases/opus/opus-$OPUS_VERSION.tar.gz" + tar xzvf "opus-$OPUS_VERSION.tar.gz" + cd "opus-$OPUS_VERSION" + #./autogen.sh + ./configure --prefix="$DEST_DIR" --disable-shared + make -j$(nproc) + make install distclean +} + +compileLibVpx() { + echo "Compiling libvpx" + cd "$WORK_DIR/" + test -d libvpx || git clone https://chromium.googlesource.com/webm/libvpx + cd libvpx + git pull + ./configure --prefix="$DEST_DIR" --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 + make -j$(nproc) + make install clean +} + +compileFfmpeg(){ + echo "Compiling ffmpeg" + cd "$WORK_DIR/" + test -d FFmpeg || git clone https://github.com/FFmpeg/FFmpeg -b master + cd FFmpeg + git pull + + export PATH="$CUDA_DIR/bin:$PATH" # ..path to nvcc + PKG_CONFIG_PATH="$DEST_DIR/lib/pkgconfig" \ + ./configure \ + --pkg-config-flags="--static" \ + --prefix="$DEST_DIR" \ + --bindir="$DEST_DIR/bin" \ + --extra-cflags="-I $DEST_DIR/include -I $CUDA_DIR/include/" \ + --extra-ldflags="-L $DEST_DIR/lib -L $CUDA_DIR/lib64/" \ + --extra-libs="-lpthread" \ + --enable-cuda-sdk \ + --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-libx265 \ + --enable-nonfree \ + --enable-nvenc +# --enable-libaom \ + make -j$(nproc) + make install distclean + hash -r +} + +installLibs +installCUDASDK +installNvidiaSDK + +compileNasm +compileYasm +compileLibX264 +compileLibX265 +# TODO: compileLibAom -- requires cmake-3.5 while centos7 provides cmake-2.8 only +compileLibVpx +compileLibfdkcc +compileLibMP3Lame +compileLibOpus +# TODO: libogg +# TODO: libvorbis +compileFfmpeg + +echo "Complete!" + +## END ##