-
Notifications
You must be signed in to change notification settings - Fork 6
/
functions.sh
627 lines (553 loc) · 17.5 KB
/
functions.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
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
#!/usr/bin/env bash
detectOs()
{
local OS_DETECT
if [[ -f "/etc/debian_version" ]]; then
OS_DETECT="debian"
elif [[ -f "/etc/almalinux-release" ]]; then
OS_DETECT="almalinux"
elif [[ -f "/etc/centos-release" ]]; then
OS_DETECT="centos"
elif [[ -f "/etc/redhat-release" ]]; then
OS_DETECT="redhat"
elif [[ $(uname) == "Darwin" ]]; then
OS_DETECT="darwin"
else
echo "OS non détecté"
exit
fi
echo "$OS_DETECT"
}
cpuCount()
{
local CPU_DETECT
if [[ "$OS" == "debian" ]] \
|| [[ "$OS" == "almalinux" ]] \
|| [[ "$OS" == "centos" ]] \
|| [[ "$OS" == "redhat" ]]; then
CPU_DETECT=$(nproc)
elif [[ "$OS" == "darwin" ]]; then
CPU_DETECT=$(sysctl -n hw.logicalcpu)
else
CPU_DETECT=-1
fi
echo "$CPU_DETECT"
}
mkBaseDirs()
{
if [[ ! -d "$SRC_PATH" ]]; then
mkdir -pv "$SRC_PATH"
fi
if [[ ! -d "$BUILD_PATH" ]]; then
mkdir -pv "$BUILD_PATH"
fi
if [[ ! -d "$BIN_PATH" ]]; then
mkdir -pv "$BIN_PATH"
fi
}
##
# mise à jour globale du système
##
systemUpdate()
{
# à exécuter uniquement si à l'intérieur du conteneur docker
if [[ ! -f /.dockerenv ]]; then
return
fi
if [[ "$OS" == "debian" ]]; then
apt -y update
apt -y full-upgrade
elif [[ "$OS" == "almalinux" ]] \
|| [[ "$OS" == "redhat" ]]; then
dnf -y update
elif [[ "$OS" == "centos" ]]; then
yum -y update
elif [[ "$OS" == "darwin" ]]; then
brew update
brew upgrade
fi
}
##
# Installation des dépendances globales
##
installDependencies()
{
if [[ "$OS" == "debian" ]]; then
apt -y install curl bzip2 autoconf automake g++ cmake libtool pkg-config git-core
elif [[ "$OS" == "almalinux" ]] \
|| [[ "$OS" == "redhat" ]]; then
dnf -y install autoconf automake bzip2 bzip2-devel cmake gcc gcc-c++ git libtool make pkgconfig zlib-devel file
elif [[ "$OS" == "redhat" ]]; then
# file pour ? optionnel ?
# bzip2 pour décompresser les archives .tar.bz2
yum -y install autoconf automake bzip2 bzip2-devel cmake gcc gcc-c++ git libtool make pkgconfig zlib-devel file
elif [[ "$OS" == "darwin" ]]; then
brew install automake pkg-config
fi
}
##
# NASM : que utile pour liblame ?
#
# Note CentOS7: compilation indispensable car CentOS 7 est fourni avec NASM 2.10 et ffmpeg requiert >= 2.13
##
installNASM()
{
echo " - installation NASM $VERSION_NASM"
cd "$SRC_PATH" || return
if [[ ! -d "nasm-$VERSION_NASM" ]]; then
echo " - Téléchargement NASM $VERSION_NASM"
curl -O -L "https://www.nasm.us/pub/nasm/releasebuilds/$VERSION_NASM/nasm-$VERSION_NASM.tar.bz2"
tar xjvf "nasm-$VERSION_NASM.tar.bz2"
else
echo " - NASM déjà téléchargé"
fi
if [[ ! -f "$BIN_PATH/nasm" ]]; then
echo " - Compilation NASM $VERSION_NASM"
cd "nasm-$VERSION_NASM" && \
./autogen.sh && \
./configure --prefix="$BUILD_PATH" --bindir="$BIN_PATH" && \
make -j "${CPU_COUNT}" && \
make install
else
echo " - NASM déjà compilé"
fi
}
##
# Yasm
#
# Note CentOS7: version 1.2.0-4.el7 dans epel (= minimum requis par ffmpeg)
##
installYasm()
{
echo " - Installation Yasm $VERSION_YASM"
cd "$SRC_PATH" || return
if [[ ! -d "yasm-$VERSION_YASM" ]]; then
echo " - Téléchargement Yasm $VERSION_YASM"
curl -O -L "http://www.tortall.net/projects/yasm/releases/yasm-$VERSION_YASM.tar.gz"
tar xzvf "yasm-$VERSION_YASM.tar.gz"
else
echo " - Yasm déjà téléchargé"
fi
if [[ ! -f "$BIN_PATH/yasm" ]]; then
echo " - Compilation Yasm $VERSION_YASM"
cd "yasm-$VERSION_YASM" && \
PATH="$BIN_PATH:$PATH" ./configure --prefix="$BUILD_PATH" --bindir="$BIN_PATH" && \
make -j "${CPU_COUNT}" && \
make install
else
echo " - Yasm déjà compilé"
fi
}
enableLibMp3Lame()
{
echo " - enableLibMp3Lame"
FFMPEG_ENABLE="${FFMPEG_ENABLE} --enable-libmp3lame"
}
enableLibVorbis()
{
echo " - enableLibVorbis"
# il faut quand même installer libvorbis-dev
# pas réussi à compiler en static
FFMPEG_ENABLE="${FFMPEG_ENABLE} --enable-libvorbis"
}
enableLibFdkAac()
{
echo " - enableLibFdkAac"
FFMPEG_ENABLE="${FFMPEG_ENABLE} --enable-libfdk_aac"
}
enableLibOpus()
{
echo " - enableLibOpus"
FFMPEG_ENABLE="${FFMPEG_ENABLE} --enable-libopus"
}
enableLibX264()
{
echo " - enableLibX264"
FFMPEG_ENABLE="${FFMPEG_ENABLE} --enable-libx264"
}
enableLibX265()
{
echo " - enableLibX265"
FFMPEG_ENABLE="${FFMPEG_ENABLE} --enable-libx265"
}
enableLibVpx()
{
echo " - enableLibVpx"
FFMPEG_ENABLE="${FFMPEG_ENABLE} --enable-libvpx"
}
enableLibFlite()
{
echo " - enableLibFlite"
FFMPEG_ENABLE="${FFMPEG_ENABLE} --enable-libflite"
}
enableLibAss()
{
echo " - enableLibAss"
FFMPEG_ENABLE="${FFMPEG_ENABLE} --enable-libfribidi --enable-libfreetype --enable-libass --enable-libharfbuzz --enable-libfontconfig"
}
enableOpenssl()
{
echo " - enableOpenssl"
if [[ "$OS" == "debian" ]]; then
apt -y install libssl-dev
elif [[ "$OS" == "almalinux" ]] \
|| [[ "$OS" == "redhat" ]]; then
dnf -y install openssl-devel
elif [[ "$OS" == "centos" ]]; then
yum -y install openssl-devel
fi
FFMPEG_ENABLE="${FFMPEG_ENABLE} --enable-openssl"
}
enableZimg()
{
echo " - enableZimg"
if [[ "$OS" == "debian" ]]; then
apt -y install libzimg-dev
elif [[ "$OS" == "almalinux" ]] \
|| [[ "$OS" == "redhat" ]]; then
dnf -y install zimg-devel
elif [[ "$OS" == "centos" ]]; then
yum -y install zimg-devel
fi
FFMPEG_ENABLE="${FFMPEG_ENABLE} --enable-libzimg"
}
##
# activer ffplay
##
enableFfplay()
{
echo " - enableFfplay"
if [[ "$OS" == "debian" ]]; then
apt -y install libsdl2-dev libva-dev libvdpau-dev libxcb1-dev libxcb-shm0-dev libxcb-xfixes0-dev
else
installLibSDL2
fi
FFMPEG_ENABLE="${FFMPEG_ENABLE} --enable-ffplay"
}
disableFfplay()
{
echo " - disableFfplay"
FFMPEG_ENABLE="${FFMPEG_ENABLE} --disable-ffplay"
}
##
# libSDL2 nécessaire pour compiler ffplay
#
# note CentOS7: pas dispo dans base ni epel
##
installLibSDL2()
{
echo " - installLibSDL2 $VERSION_SDL2"
cd "$SRC_PATH" || return
if [[ ! -d "SDL2-$VERSION_SDL2" ]]; then
echo " - Téléchargement libSDL2"
curl -O -L "http://www.libsdl.org/release/SDL2-${VERSION_SDL2}.tar.gz" && \
tar fvxz "SDL2-${VERSION_SDL2}.tar.gz" && \
rm tar fvxz "SDL2-${VERSION_SDL2}.tar.gz"
else
echo " - libSDL2 déjà téléchargé"
fi
if [[ ! -f "$BUILD_PATH/lib/libSDL2.a" ]]; then
echo " - Compilation libSDL2"
cd "SDL2-${VERSION_SDL2}" && \
PATH="$BIN_PATH:$PATH" ./configure --prefix="$BUILD_PATH" --bindir="$BIN_PATH" --enable-static && \
make -j "${CPU_COUNT}" && \
make install
else
echo " - libSDL2 déjà compilé"
fi
}
##
# libx264
# note CentOS7: pas dispo dans base ni epel
# note Debian: paquet ne marche pas
# note CentOS7: PKG_CONFIG_PATH="$BUILD_PATH/lib/pkgconfig"
##
installLibX264()
{
echo " - installLibX264 $VERSION_X264"
cd "$SRC_PATH" || return
# version déjà packagée par Debian : marche pas
#apt -y install libx264-dev
#return
if [[ ! -d "x264" ]]; then
echo " - Téléchargement x264"
git clone --depth 1 --branch "$VERSION_X264" https://code.videolan.org/videolan/x264.git
else
echo " - x264 déjà téléchargé"
fi
if [[ ! -f "${BIN_PATH}/x264" ]]; then
echo " - Compilation x264"
cd x264 && \
PATH="$BIN_PATH:$PATH" PKG_CONFIG_PATH="$BUILD_PATH/lib/pkgconfig" ./configure --prefix="$BUILD_PATH" --bindir="$BIN_PATH" --enable-static
PATH="$BIN_PATH:$PATH" make -j "${CPU_COUNT}" && \
make install
else
echo " - x264 déjà compilé"
fi
}
##
#
##
installLibX265()
{
echo " - installLibX265 $VERSION_X265"
cd "$SRC_PATH" || return
if [[ "$OS" == "darwin" ]]; then
brew install x265
return
elif [[ "$OS" == "debian" ]]; then
apt -y install libx265-dev libnuma-dev
return
else
if [[ ! -d "x265" ]]; then
echo " - Téléchargement x265"
git clone --depth 1 --branch "$VERSION_X265" https://bitbucket.org/multicoreware/x265_git
else
echo " - x265 déjà téléchargé"
fi
if [[ ! -f "${BUILD_PATH}/bin/x265" ]]; then
echo " - Compilation x265"
cd x265_git/build/linux && \
PATH="$BIN_PATH:$PATH" cmake -G "Unix Makefiles" -DCMAKE_INSTALL_PREFIX="$BUILD_PATH" -DENABLE_SHARED:bool=off ../../source && \
PATH="$BIN_PATH:$PATH" make -j "${CPU_COUNT}" && \
make install
else
echo " - x265 déjà compilé"
fi
fi
}
installLibVpx()
{
echo " - installLibVpx"
# surement ...
if [[ "$OS" == "darwin" ]]; then
brew install libvpx
elif [[ "$OS" == "debian" ]]; then
apt-get install libvpx-dev
else
git -C libvpx pull 2> /dev/null || git clone --depth 1 https://chromium.googlesource.com/webm/libvpx.git && \
cd libvpx && \
./configure --prefix="$BUILD_PATH" --disable-examples --disable-unit-tests --enable-vp9-highbitdepth --as=yasm && \
make && \
make install
#echo "LibVpx non implémenté pour cet OS"
#exit 1
fi
}
installLibFdkAac()
{
echo " - installLibFdkAac $VERSION_FDKAAC"
cd "$SRC_PATH" || return
if [[ "$OS" == "darwin" ]]; then
brew install libtool
fi
if [[ ! -d "fdk-aac" ]]; then
echo " - Téléchargement fdk-aac"
git clone --depth 1 --branch "$VERSION_FDKAAC" https://github.com/mstorsjo/fdk-aac
else
echo " - fdk-aac déjà téléchargé"
fi
if [[ ! -f "${BUILD_PATH}/lib/libfdk-aac.a" ]] || [[ ! -f "${BUILD_PATH}/lib/libfdk-aac.la" ]]; then
echo " - Compilation fdk-aac"
cd fdk-aac && \
autoreconf -fiv && \
./configure --prefix="$BUILD_PATH" --disable-shared && \
make -j "${CPU_COUNT}" && \
make install
else
echo " - fdk-aac déjà compilé"
fi
}
##
# libass
# options possibles: --disable-fontconfig, --disable-static
# note CentOS7: dans epel, version 0.13.4-6.el7
##
installLibAss()
{
echo " - installLibAss $VERSION_ASS"
cd "$SRC_PATH" || return
if [[ "$OS" == "debian" ]]; then
apt -y install libass-dev libfreetype6-dev libfribidi-dev libharfbuzz-dev libfontconfig-dev
elif [[ "$OS" == "almalinux" ]] \
|| [[ "$OS" == "redhat" ]]; then
dnf -y install epel-release
dnf -y install libass-devel freetype-devel fribidi-devel harfbuzz-devel fontconfig-devel
elif [[ "$OS" == "centos" ]]; then
yum -y install freetype-devel fribidi-devel harfbuzz-devel fontconfig-devel
fi
if [[ "$OS" == "almalinux" ]] || [[ "$OS" == "redhat" ]] || [[ "$OS" == "centos" ]]; then
installFribidi
fi
if [[ ! -d "libass" ]]; then
echo " - Téléchargement libass"
git clone --depth 1 --branch "$VERSION_ASS" https://github.com/libass/libass.git
else
echo " - libass déjà téléchargé"
fi
if true; then # améliorer le true
echo " - Compilation libass"
if [[ "$OS" == "redhat" ]]; then
yum -y install harfbuzz-devel
fi
if [[ "$OS" == "debian" ]]; then
apt -y install libass-dev
fi
#redhat: PATH="$BIN_PATH:$PATH" PKG_CONFIG_PATH="$BUILD_PATH/lib/pkgconfig" ./configure --prefix="$BUILD_PATH" --bindir="$BIN_PATH" --disable-shared --enable-static --disable-require-system-font-provider && \
#darwin: PATH="$BIN_PATH:$PATH" ./configure --prefix="$BUILD_PATH" --bindir="$BIN_PATH" --enable-static && \
cd libass || exit
./autogen.sh
if [[ "$OS" == "darwin" ]]; then
PATH="$BIN_PATH:$PATH" ./configure --prefix="$BUILD_PATH" --bindir="$BIN_PATH" --enable-static
else
PATH="$BIN_PATH:$PATH" PKG_CONFIG_PATH="$BUILD_PATH/lib/pkgconfig" ./configure --prefix="$BUILD_PATH" --bindir="$BIN_PATH" --disable-shared --enable-static --disable-require-system-font-provider
fi
PATH="$BIN_PATH:$PATH" make -j "${CPU_COUNT}" && \
make install
else
echo " - libass déjà compilé"
fi
}
##
# fribidi nécessaire à libass
# note: version 1.0.2-1.el7 dans base
##
installFribidi()
{
echo " - installFribidi $VERSION_FRIBIDI"
cd "$SRC_PATH" || return
# which pour autogen.sh de fribidi
if [[ "$OS" == "almalinux" ]] || [[ "$OS" == "redhat" ]] || [[ "$OS" == "centos" ]]; then
yum -y install which
elif [[ "$OS" == "debian" ]]; then
apt -y install which
fi
if [[ ! -d "fribidi-$VERSION_FRIBIDI" ]]; then
# @see https://github.com/fribidi/fribidi/issues/8
echo " - Téléchargemeng Fribidi"
curl -O -L "https://github.com/fribidi/fribidi/releases/download/v${VERSION_FRIBIDI}/fribidi-${VERSION_FRIBIDI}.tar.xz"
tar xvf "fribidi-${VERSION_FRIBIDI}.tar.xz" && \
rm "fribidi-${VERSION_FRIBIDI}.tar.xz"
else
echo " - Fribidi déjà téléchargé"
fi
if true; then # améliorer le true
echo " - Compilation Fribidi"
echo "fribidi-${VERSION_FRIBIDI}"
cd "fribidi-${VERSION_FRIBIDI}" && \
./autogen.sh && \
./configure --prefix="${BUILD_PATH}" --bindir="${BIN_PATH}" --disable-shared --enable-static && \
make -j "${CPU_COUNT}" -C lib && \
make install
else
echo " - Fribidi déjà compilé"
fi
}
installLibVorbis()
{
echo " - installLibVorbis"
cd "$SRC_PATH" || return
if [[ "$OS" == "debian" ]]; then
apt -y install libvorbis-dev
else
echo "libVorbis non implémenté sur cette plateforme"
exit 1
fi
}
installLibMp3Lame()
{
echo " - installLibMp3Lame $VERSION_MP3LAME"
cd "$SRC_PATH" || return
if [[ ! -d "lame-$VERSION_MP3LAME" ]]; then
echo " - Téléchargement lame"
curl -O -L "https://downloads.sourceforge.net/project/lame/lame/$VERSION_MP3LAME/lame-$VERSION_MP3LAME.tar.gz"
tar xzvf "lame-$VERSION_MP3LAME.tar.gz"
else
echo " - lame déjà téléchargé"
fi
if [[ ! -f "$BUILD_PATH/lib/libmp3lame.a" ]] || [[ ! -f "$BUILD_PATH/lib/libmp3lame.la" ]]; then
echo " - Compilation lame"
cd "lame-$VERSION_MP3LAME" && \
PATH="$BIN_PATH:$PATH" ./configure --prefix="$BUILD_PATH" --bindir="$BIN_PATH" --disable-shared --enable-nasm && \
PATH="$BIN_PATH:$PATH" make -j "$CPU_COUNT" && \
make install
else
echo " - lame déjà compilé"
fi
}
installLibOpus()
{
echo " - installLibOpus $VERSION_OPUS"
cd "$SRC_PATH" || return
if [[ ! -d "opus-$VERSION_OPUS" ]]; then
echo " - Téléchargement opus"
curl -O -L "https://downloads.xiph.org/releases/opus/opus-$VERSION_OPUS.tar.gz"
tar xzvf "opus-$VERSION_OPUS.tar.gz"
else
echo " - opus déjà téléchargé"
fi
if [[ ! -f "$BUILD_PATH/lib/libopus.a" ]] || [[ ! -f "$BUILD_PATH/lib/libopus.la" ]]; then
echo " - Compilation opus"
cd "opus-$VERSION_OPUS" && \
PATH="$BIN_PATH:$PATH" ./configure --prefix="$BUILD_PATH" --disable-shared && \
PATH="$BIN_PATH:$PATH" make -j "$CPU_COUNT" && \
make install
else
echo " - opus déjà compilé"
fi
}
# bien pour anglais, bof pour français
installFlite()
{
echo " - Installation Flite $VERSION_FLITE"
cd "$SRC_PATH" || return
if [[ ! -d "flite" ]]; then
echo " - Téléchargement flite"
git clone --depth 1 --branch "$VERSION_FLITE" https://github.com/festvox/flite.git
else
echo " - flite déjà téléchargé"
fi
if [[ ! -f "$BIN_PATH/flite" ]]; then
echo " - Compilation flite"
cd flite && \
PATH="$BIN_PATH:$PATH" ./configure --prefix="$BUILD_PATH" --bindir="$BIN_PATH" --enable-static && \
PATH="$BIN_PATH:$PATH" make -j "${CPU_COUNT}" && \
make install
else
echo " - flite déjà compilé"
fi
}
##
# ffmpeg
# note CentOS7: pas dispo dans base ni epel
# note darwin: pas extra-libs -lpthread et -lm ?
##
installFfmpeg()
{
echo " - installFfmpeg $VERSION_FFMPEG"
cd "$SRC_PATH" || return
if [[ ! -d "ffmpeg-$VERSION_FFMPEG" ]]; then
echo " - Téléchargement ffmpeg $VERSION_FFMPEG"
# patch AC4
# curl -o ffmpeg-$VERSION_FFMPEG.tar.gz -L "https://github.com/elliotclee/FFmpeg/archive/refs/tags/n$VERSION_FFMPEG.tar.gz" && \
# tar fvxz "ffmpeg-$VERSION_FFMPEG.tar.gz"
# natif
curl -O -L "https://ffmpeg.org/releases/ffmpeg-$VERSION_FFMPEG.tar.bz2" && \
tar xjvf "ffmpeg-$VERSION_FFMPEG.tar.bz2"
else
echo " - ffmpeg déjà téléchargé"
fi
echo " - Compilation ffmpeg $VERSION_FFMPEG"
cd "ffmpeg-$VERSION_FFMPEG" && \
PATH="$BIN_PATH:$PATH" PKG_CONFIG_PATH="$BUILD_PATH/lib/pkgconfig" ./configure \
--prefix="$BUILD_PATH" \
--pkg-config-flags="--static" \
--extra-cflags="-I$BUILD_PATH/include" \
--extra-ldflags="-L$BUILD_PATH/lib" \
--extra-libs=-lpthread \
--extra-libs=-lm \
--bindir="$BIN_PATH" \
$FFMPEG_ENABLE && \
PATH="$BIN_PATH:$PATH" make -j "${CPU_COUNT}" && \
make install
}