-
Notifications
You must be signed in to change notification settings - Fork 41
/
ffmpeg-nvenc-build.sh
executable file
·280 lines (239 loc) · 8.23 KB
/
ffmpeg-nvenc-build.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
#!/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.15.03"
YASM_VERSION="1.3.0"
LAME_VERSION="3.100"
OPUS_VERSION="1.3.1"
LASS_VERSION="0.14.0"
CUDA_VERSION="10.1.243-1"
CUDA_RPM_VER="-10-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"
MYDIR="$(cd "$(dirname "$0")" && pwd)" #"
#### Routines ################################################
Wget() { wget -cN "$@"; }
Make() { make -j$(nproc); make "$@"; }
Clone() {
local DIR="$(basename "$1" .git)"
cd "$WORK_DIR/"
test -d "$DIR/.git" || git clone --depth=1 "$@"
cd "$DIR"
git pull
}
PKGS="autoconf automake libtool patch make cmake bzip2 unzip wget git mercurial"
installAptLibs() {
sudo apt-get update
sudo apt-get -y --force-yes install $PKGS \
build-essential pkg-config texi2html software-properties-common \
libfreetype6-dev libgpac-dev libsdl1.2-dev libtheora-dev libva-dev \
libvdpau-dev libvorbis-dev libxcb1-dev libxcb-shm0-dev libxcb-xfixes0-dev zlib1g-dev
}
installYumLibs() {
sudo yum -y install $PKGS freetype-devel gcc gcc-c++ pkgconfig zlib-devel \
libtheora-devel libvorbis-devel libva-devel cmake3
}
installLibs() {
echo "Installing prerequisites"
. /etc/os-release
case "$ID" in
ubuntu | linuxmint ) installAptLibs ;;
* ) installYumLibs ;;
esac
}
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 env LC_ALL=C.UTF-8 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 ||
sudo yum install -y "https://developer.download.nvidia.com/compute/cuda/repos/rhel7/x86_64/cuda-repo-rhel7-${CUDA_VERSION}.x86_64.rpm"
sudo yum install -y "cuda${CUDA_RPM_VER}"
}
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 ;;
linuxmint-19.1)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."
Clone https://git.videolan.org/git/ffmpeg/nv-codec-headers.git
make
make install PREFIX="$DEST_DIR"
patch --force -d "$DEST_DIR" -p1 < "$MYDIR/dynlink_cuda.h.patch" ||
echo "..SKIP PATCH, POSSIBLY NOT NEEDED. CONTINUED.."
}
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 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 install distclean
}
compileLibX264() {
echo "Compiling libx264"
cd "$WORK_DIR/"
Wget https://code.videolan.org/videolan/x264/-/archive/master/x264-master.tar.bz2
rm -rf x264-*/ || :
tar xjvf x264-master.tar.bz2
cd x264-master/
./configure --prefix="$DEST_DIR" --bindir="$DEST_DIR/bin" --enable-static --enable-pic
Make install distclean
}
compileLibX265() {
if cd "$WORK_DIR/x265/" 2>/dev/null; then
hg pull
hg update
else
cd "$WORK_DIR/"
hg clone http://hg.videolan.org/x265
fi
cd "$WORK_DIR/x265/build/linux/"
cmake -G "Unix Makefiles" -DCMAKE_INSTALL_PREFIX="$DEST_DIR" -DENABLE_SHARED:bool=off ../../source
Make install
# forward declaration should not be used without struct keyword!
sed -i.orig -e 's,^ *x265_param\* zoneParam,struct x265_param* zoneParam,' "$DEST_DIR/include/x265.h"
}
compileLibAom() {
echo "Compiling libaom"
Clone https://aomedia.googlesource.com/aom
mkdir ../aom_build
cd ../aom_build
which cmake3 && PROG=cmake3 || PROG=cmake
$PROG -G "Unix Makefiles" -DCMAKE_INSTALL_PREFIX="$DEST_DIR" -DENABLE_SHARED=off -DENABLE_NASM=on ../aom
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 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 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 install distclean
}
compileLibVpx() {
echo "Compiling libvpx"
Clone https://chromium.googlesource.com/webm/libvpx
./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 --disable-docs
Make install clean
}
compileLibAss() {
echo "Compiling libass"
cd "$WORK_DIR/"
Wget "https://github.com/libass/libass/releases/download/$LASS_VERSION/libass-$LASS_VERSION.tar.xz"
tar Jxvf "libass-$LASS_VERSION.tar.xz"
cd "libass-$LASS_VERSION"
autoreconf -fiv
./configure --prefix="$DEST_DIR" --disable-shared
Make install distclean
}
compileFfmpeg(){
echo "Compiling ffmpeg"
Clone https://github.com/FFmpeg/FFmpeg -b master
export PATH="$CUDA_DIR/bin:$PATH" # ..path to nvcc
PKG_CONFIG_PATH="$DEST_DIR/lib/pkgconfig:$DEST_DIR/lib64/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 \
--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-libaom \
--enable-nvenc
Make install distclean
hash -r
}
installLibs
installCUDASDK
installNvidiaSDK
compileNasm
compileYasm
compileLibX264
compileLibX265
compileLibAom
compileLibVpx
compileLibfdkcc
compileLibMP3Lame
compileLibOpus
compileLibAss
# TODO: libogg
# TODO: libvorbis
compileFfmpeg
echo "Complete!"
## END ##