forked from ilyaevseev/ffmpeg-build
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathffmpeg-nvenc-build.sh
executable file
·273 lines (237 loc) · 8.02 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
#!/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"
MYDIR="$(cd "$(dirname "$0")" && pwd)" #"
#### Routines ################################################
Wget() { wget -cN "$@"; }
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 \
libass-dev 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 \
libass-devel tibtheora-devel libvorbis-devel libva-devel
}
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 ||
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 ;;
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."
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 --force -d "$DEST_DIR" -p1 < "$MYDIR/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
cd "$WORK_DIR/"
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
# 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() {
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 \
--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 ##