forked from immstudios/installers
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinstall.ffmpeg.sh
executable file
·312 lines (273 loc) · 8.08 KB
/
install.ffmpeg.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
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
#!/bin/bash
#
# Copyright (c) 2015 - 2020 imm studios, z.s.
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
##############################################################################
## COMMON UTILS
base_dir=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )
temp_dir=/tmp/$(basename "${BASH_SOURCE[0]}")
function error_exit {
printf "\n\033[0;31mInstallation failed\033[0m\n"
cd ${base_dir}
exit 1
}
function finished {
printf "\n\033[0;92mInstallation completed\033[0m\n"
cd ${base_dir}
exit 0
}
if [ "$(id -u)" != "0" ]; then
echo "This script must be run as root" 1>&2
error_exit
fi
if [ ! -d ${temp_dir} ]; then
mkdir ${temp_dir} || error_exit
fi
## COMMON UTILS
##############################################################################
make_threads=8
NASM_VERSION="2.14.02"
REPOS=(
"https://github.com/mstorsjo/fdk-aac"
"https://github.com/mirror/x264"
"https://github.com/Haivision/srt"
"https://github.com/stoth68000/libklvanc"
"https://github.com/martastain/bmd-sdk"
"https://github.com/immstudios/ffmpeg"
"https://github.com/immstudios/ndi-headers"
)
extra_flags=""
if [ -z "$PREFIX" ]; then
PREFIX="/usr/local"
fi
function install_prerequisites {
# bulid tools
apt-get -y install\
build-essential \
unzip \
cmake \
yasm \
git \
libtool \
autoconf \
automake \
pkg-config \
libxml2-dev \
tclsh \
wget \
|| exit 1
# network and security
apt-get -y install \
avahi-daemon \
avahi-discover \
avahi-utils \
libssl-dev \
|| exit 1
# text rendering
apt-get -y install \
fontconfig \
libfontconfig1 \
libfontconfig1-dev \
libfribidi-dev \
libfribidi0 \
libfreetype6-dev \
libass-dev \
|| exit 1
# 3rd party codecs and filters
apt-get -y install \
libx265-dev \
libmp3lame-dev \
libtwolame-dev \
libopus-dev \
libv4l-dev \
libvpx-dev \
libwebp-dev \
libzvbi-dev \
librubberband-dev \
libfftw3-dev \
ocl-icd-opencl-dev \
opencl-headers \
|| exit 1
}
function download_repos {
cd ${temp_dir}
for i in ${REPOS[@]}; do
MNAME=`basename $i`
if [ -d $MNAME ]; then
cd $MNAME
git checkout master || return 1
git pull || return 1
cd ..
else
git clone $i || return 1
fi
done
return 0
}
function install_nasm {
cd $temp_dir
nasm_name=nasm-${NASM_VERSION}
if [ -f ${nasm_name}.tar.gz ]; then
rm ${nasm_name}.tar.gz
fi
wget https://www.nasm.us/pub/nasm/releasebuilds/${NASM_VERSION}/${nasm_name}.tar.gz || return 1
tar -xf ${nasm_name}.tar.gz
cd ${nasm_name}
./configure || return 1
make -j$make_threads || return 1
make install || return 1
return 0
}
#
# 3rd party libraries
#
function install_fdk_aac {
cd ${temp_dir}/fdk-aac
autoreconf -fiv || return 1
./configure --prefix=$PREFIX || return 1
make -j$make_threads || return 1
make install || return 1
extra_flags="$extra_flags --enable-libfdk-aac"
return 0
}
function install_nvcodec {
HAS_NVIDIA=`hash nvidia-smi 2> /dev/null && echo 1 || echo ""`
if [ $HAS_NVIDIA ] ; then
cd $temp_dir
if [ -d nv-codec-headers ]; then
rm -rf nv-codec-headers
fi
git clone "https://git.videolan.org/git/ffmpeg/nv-codec-headers"
cd nv-codec-headers
make || return 1
make install || return 1
extra_flags="$extra_flags --enable-nvenc --enable-cuda --enable-cuvid --enable-libnpp --enable-cuda-nvcc"
extra_flags="$extra_flags --extra-cflags=-I/usr/local/cuda/include --extra-ldflags=-L/usr/local/cuda/lib64"
fi
return 0
}
function install_bmd {
cd ${temp_dir}
cp bmd-sdk/* /usr/include/ || return 1
extra_flags="$extra_flags --enable-decklink"
return 0
}
function install_ndi {
cd ${temp_dir}
cp ndi-headers/*.h /usr/include
ndi_file="libndi4_4.5.1-1_amd64.deb"
if [ ! -f $ndi_file ]; then
wget https://github.com/Palakis/obs-ndi/releases/download/4.9.1/$ndi_file || return 1
fi
dpkg -i $ndi_file || return 1
extra_flags="$extra_flags --enable-libndi_newtek"
return 0
}
function install_x264 {
cd $temp_dir/x264
./configure --enable-shared --bit-depth=all --chroma-format=all || return 1
make -j$make_threads || return 1
make install || return 1
extra_flags="$extra_flags --enable-libx264"
return 0
}
function install_libsrt {
cd $temp_dir/srt
./configure || return 1
make -j$make_threads || return 1
make install || return 1
extra_flags="$extra_flags --enable-libsrt"
return 0
}
function install_libklvanc {
cd $temp_dir/libklvanc
./autogen.sh --build || return 1
./configure || return 1
make -j$make_threads || return 1
make install || return 1
extra_flags="$extra_flags --enable-libklvanc"
return 0
}
function install_openjpeg {
cd $temp_dir
openjpeg_src_file="v2.4.0.tar.gz"
openjpeg_file="openjpeg-2.4.0"
if [ ! -f $openjpeg_file.tar.gz ]; then
wget https://github.com/uclouvain/openjpeg/archive/refs/tags/v2.4.0.tar.gz -O $openjpeg_file.tar.gz || exit 1
fi
if [ ! -d $openjpeg_file ]; then
tar -xf $openjpeg_file.tar.gz
fi
cd $openjpeg_file
mkdir build
cd build
cmake .. -DCMAKE_BUILD_TYPE=Release
make
make install
extra_flags="$extra_flags --enable-libopenjpeg"
}
#
# Install FFmpeg
#
function install_ffmpeg {
cd ${temp_dir}/ffmpeg
PATH=/usr/local/cuda/bin${PATH:+:${PATH}}
echo ""
echo $extra_flags
echo ""
./configure --prefix=$PREFIX \
--enable-nonfree \
--enable-gpl \
--enable-version3 \
--enable-shared \
--enable-pic \
\
--enable-fontconfig ` # enable fontconfig, useful for drawtext filter` \
--enable-libass ` # enable libass subtitles rendering` \
--enable-libfreetype ` # enable libfreetype, needed for drawtext filter` \
--enable-libfribidi ` # enable libfribidi, improves drawtext filter` \
--enable-libmp3lame ` # enable MP3 encoding via libmp3lame` \
--enable-libtwolame ` # enable MP2 encoding via libtwolame` \
--enable-libwebp ` # enable WebP encoding via libwebp` \
--enable-libx265 ` # enable HEVC encoding via x265` \
--enable-libopus ` # enable Opus de/encoding via libopus` \
--enable-libzvbi ` # enable teletext support via libzvbi` \
--enable-libv4l2 ` # enable libv4l2/v4l-utils` \
--enable-openssl ` # needed for https support if gnutls is not used` \
--enable-libxml2 ` # enable XML parsing needed for dash demuxing support` \
--enable-libvpx ` # enable VP8 and VP9 de/encoding via libvpx` \
--enable-librubberband \
--enable-opencl \
$extra_flags \
|| return 1
echo "Making ffmpeg"
make -j$make_threads || return 1
make install || return 1
make clean
ldconfig
return 0
}
################################################
install_prerequisites || error_exit
download_repos || error_exit
install_nasm || error_exit
install_fdk_aac || error_exit
install_x264 || error_exit
install_nvcodec || error_exit
install_bmd || error_exit
install_ndi || error_exit
install_libsrt || error_exit
install_libklvanc || error_exit
install_openjpeg || error_exit
install_ffmpeg || error_exit
finished