-
Notifications
You must be signed in to change notification settings - Fork 3
/
build-debian.sh
executable file
·703 lines (615 loc) · 18.4 KB
/
build-debian.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
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
#!/bin/bash
# nrchkb-ffmpeg-build Version 2.0
# MIT License
# Copyright (c) 2022 Marcus Davies
# Copyright (c) 2022 Garrett Porter
# 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.
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
# Colors
Red=$'\e[0;31m'
Yellow=$'\e[1;33m'
End=$'\e[0m'
# Defaults
JOBS=3 # Jobs Value
JOBS_PARAM=false # Arg provided
FDK="y" # FDK Choice Value
FDK_PARAM=false # Arg provided
L264="y" # 264 Choice Value
L264_PARAM=false # Arg provided
L265="n" # 265 Choice Value
L265_PARAM=false # Arg provided
LVPX="n" # VPX Choice Value
LVPX_PARAM=false # Arg provided
LOPUS="n" # Opus Choice Value
LOPUS_PARAM=false # Arg provided
FLAGSYN="n" # Flags Choice Value
FLAGS="" # Flasg Value
FLAGS_PARAM=false # Arg provided
MODE=0 # Mode Value
MODE_PARAM=false # Arg provided
INTERACTIVE="y" # Interactive
# Prefix
PREFIX="/usr/local"
export LDFLAGS="-L$PREFIX/lib"
export CFLAGS="-I$PREFIX/include"
# Ignore Repository sources
FORCE_BUILD=false
# Specific package manager implemention
INSTALL() {
sudo apt install -y $@
}
REMOVE() {
sudo apt remove -y $1
sudo apt purge -y $1
}
CHECK() {
apt info $1
}
# Package Names
DEP_X264="libx264-dev"
DEP_X265="libx265-dev"
DEP_VPX="libvpx-dev"
DEP_OPUS="libopus-dev"
DEP_AAC="libfdk-aac-dev"
# Print Header
printHeader() {
printf "\033c"
echo
echo " ---------------------------------------------------------"
echo " | 2.0 |"
echo " | P&M FFmpeg Build Script (Debian) |"
echo " | An FFmpeg build & installation utility for NRCHKB |"
echo " | |"
echo " ---------------------------------------------------------"
echo
echo " ${Yellow}Note: This script will install into $PREFIX/bin and $PREFIX/lib respectively.${End}"
echo
}
# Print menu
menu() {
echo " ${Yellow}What would you like to do:${End}"
echo
echo " 1 - Install build tools (Dependencies from apt)"
echo " 2 - Build/install libfdk-aac (AAC Audio Encoder)"
echo " 3 - Build/install libx264 (x264 Video Encoder)"
echo " 4 - Build/install libx265 (x265 Video Encoder)"
echo " 5 - Build/install libvpx (VP8/VP9 video Encoder/Decoder)"
echo " 6 - Build/install libopus (Opus Audio Encoder/Decoder)"
echo " 7 - Build FFmpeg (Builds from source only)"
echo " 8 - Guided Install"
echo " 9 - Purge build directories"
echo " q - Quit"
echo
echo " Note: This script will download and compile these software packages from source code,"
echo " unless they happen to be available from your systems repository."
echo " Where necessary, libaries will be built as shared libs."
echo
echo " This excludes FFMPEG which will always be built for source."
echo
echo " If you have previously run this script, running it again will update your software."
echo
printf " Choice: "
read -r
if [[ "$REPLY" = "q" ]]; then
exit 0
fi
MODE=$REPLY
if [[ $MODE -gt 8 || $MODE -lt 1 ]]; then
printHeader
menu
fi
processOptions $MODE
}
# Error Check
checkForError() {
if [[ $? -gt 0 ]]; then
stopWatch "stop"
echo "${Red}"
echo " ---------------------------------------------------------"
echo " | |"
echo " | Errors occurred |"
echo " | Please check the logs and try again |"
echo " | |"
echo " ---------------------------------------------------------"
echo "${End}"
echo
exit 1
fi
}
# Install Dependencies
installDependencies() {
echo
echo " ---------------------------------------------------------"
echo " | |"
echo " | Installing Dependencies |"
echo " | |"
echo " ---------------------------------------------------------"
echo
INSTALL pkg-config autoconf automake libtool git wget make g++ gcc nasm yasm build-essential cmake-curses-gui cmake
}
# Install Libx264
installLibx264() {
cd ~
echo
echo " ---------------------------------------------------------"
echo " | |"
echo " | Building/Installing libx264 |"
echo " | |"
echo " ---------------------------------------------------------"
echo
if [[ $FORCE_BUILD = false ]]; then
CHECK $DEP_X264
if [[ $? = 0 ]]; then
INSTALL $DEP_X264
return
fi
fi
REMOVE $DEP_X264
git clone https://code.videolan.org/videolan/x264.git
cd x264
./configure --prefix=$PREFIX --disable-static --enable-shared --enable-pic
checkForError
make -j"$JOBS"
checkForError
sudo make install
checkForError
sudo ldconfig
cd ~
}
# Install Libx265
installLibx265() {
cd ~
echo
echo " ---------------------------------------------------------"
echo " | |"
echo " | Building/Installing libx265 |"
echo " | |"
echo " ---------------------------------------------------------"
echo
if [[ $FORCE_BUILD = false ]]; then
CHECK $DEP_X265
if [[ $? = 0 ]]; then
INSTALL $DEP_X265
return
fi
fi
REMOVE $DEP_X265
git clone https://bitbucket.org/multicoreware/x265_git.git
cd x265_git/build/linux
cmake -G "Unix Makefiles" -DLIB_INSTALL_DIR="$PREFIX/lib" -DENABLE_SHARED=on -DENABLE_PIC=on ../../source
checkForError
make -j"$JOBS"
checkForError
sudo make install
checkForError
sudo ldconfig
cd ~
}
# Install Libfdk
installLibfdk() {
cd ~
echo
echo " ---------------------------------------------------------"
echo " | |"
echo " | Building/Installing libfdk-aac |"
echo " | |"
echo " ---------------------------------------------------------"
echo
if [[ $FORCE_BUILD = false ]]; then
CHECK $DEP_AAC
if [[ $? = 0 ]]; then
INSTALL $DEP_AAC
return
fi
fi
REMOVE $DEP_AAC
git clone https://github.com/mstorsjo/fdk-aac.git
cd fdk-aac
./autogen.sh
./configure --prefix=$PREFIX --disable-static --enable-shared --enable-pic
checkForError
make -j"$JOBS"
checkForError
sudo make install
checkForError
sudo ldconfig
cd ~
}
# Install VPX
installLibvpx() {
cd ~
echo
echo " ---------------------------------------------------------"
echo " | |"
echo " | Building/Installing libvpx-dev |"
echo " | |"
echo " ---------------------------------------------------------"
echo
if [[ $FORCE_BUILD = false ]]; then
CHECK $DEP_VPX
if [[ $? = 0 ]]; then
INSTALL $DEP_VPX
return
fi
fi
REMOVE $DEP_VPX
git clone https://chromium.googlesource.com/webm/libvpx.git
cd libvpx
./autogen.sh
./configure --prefix=$PREFIX --disable-static --enable-shared --enable-pic --disable-examples --disable-unit-tests --enable-vp9-highbitdepth --as=yasm
checkForError
make -j"$JOBS"
checkForError
sudo make install
checkForError
sudo ldconfig
cd ~
}
# Install VPX
installLibopus() {
cd ~
echo
echo " ---------------------------------------------------------"
echo " | |"
echo " | Building/Installing libopus-dev |"
echo " | |"
echo " ---------------------------------------------------------"
echo
if [[ $FORCE_BUILD = false ]]; then
CHECK $DEP_OPUS
if [[ $? = 0 ]]; then
INSTALL $DEP_OPUS
return
fi
fi
REMOVE $DEP_OPUS
git clone https://github.com/xiph/opus.git
cd opus
./autogen.sh
./configure --prefix=$PREFIX --disable-static --enable-shared --enable-pic
checkForError
make -j"$JOBS"
checkForError
sudo make install
checkForError
sudo ldconfig
cd ~
}
# Install FFmpeg
installFFmpeg() {
cd ~
echo
echo " ---------------------------------------------------------"
echo " | |"
echo " | Building/Installing FFmpeg |"
echo " | |"
echo " ---------------------------------------------------------"
echo
REMOVE ffmpeg
wget -O ffmpeg-snapshot.tar.bz2 https://ffmpeg.org/releases/ffmpeg-snapshot.tar.bz2
echo "Extracting source code..."
tar xjf ffmpeg-snapshot.tar.bz2
cd ffmpeg
CMD="--prefix=$PREFIX --enable-nonfree --enable-gpl --disable-ffprobe --disable-ffplay --enable-pic --disable-static --enable-shared"
if [[ "$FDK" = "y" ]]; then
CMD="$CMD --enable-libfdk-aac"
fi
if [[ "$L264" = "y" ]]; then
CMD="$CMD --enable-libx264"
fi
if [[ "$L265" = "y" ]]; then
CMD="$CMD --enable-libx265"
fi
if [[ "$LVPX" = "y" ]]; then
CMD="$CMD --enable-libvpx"
fi
if [[ "$LOPUS" = "y" ]]; then
CMD="$CMD --enable-libopus"
fi
if [[ "$FLAGSYN" = "y" ]]; then
CMD="$CMD $FLAGS"
fi
./configure $CMD --extra-libs="-lpthread -lm"
checkForError
make -j"$JOBS"
checkForError
sudo make install
checkForError
sudo ldconfig
cd ~
}
# Clear Up
cleanDirectory() {
rm -rf ffmpeg
rm -rf fdk-aac
rm -rf x264
rm -rf x265_git
rm -rf libvpx
rm -rf opus
rm -f ffmpeg-snapshot.tar.bz2
}
# Ask for Threads
getJobsCount() {
if [[ $JOBS_PARAM = true || "$INTERACTIVE" = "n" ]]; then
return
fi
echo
printf " ${Yellow}How many simultaneous jobs would you like to use for build processes (if needed) Default: $JOBS (#):${End}"
read -r
if [[ $REPLY -gt 0 ]]; then
JOBS=$REPLY
fi
}
# getLib L264_PARAM L264 "libx264"
getLib(){
if [[ ${!1} = true || "$INTERACTIVE" = "n" ]]; then
return
fi
printf " ${Yellow}Would you like to enable '$3'? Default: ${!2} (y/n):${End}"
read -r
if [[ "$REPLY" = "y" || "$REPLY" = "n" ]]; then
eval $2="$REPLY"
fi
}
# Get Compile Flags
getFlags() {
if [[ $FLAGS_PARAM = true || "$INTERACTIVE" = "n" ]]; then
return
fi
echo
echo " ${Yellow}Would you like to add any extra FFmpeg compile flags? Default: $FLAGSYN (y/n)"
echo
echo " ADVANCED: ${End}Compile flags could be added to the build process, to ensure ffmpeg is compiled with more features."
printf " You are responsible for ensuring any requied dev/header files are installed: "
read -r
if [[ "$REPLY" = "y" || "$REPLY" = "n" ]]; then
FLAGSYN="$REPLY"
if [[ "$FLAGSYN" = "y" ]]; then
echo
echo " ${Yellow}Please enter your compile flags below, separated by a space${End}"
echo
printf " Example: --enable-vaapi --enable-libvorbis : "
read -r
if [[ ${#REPLY} -gt 0 ]]; then
FLAGS="$REPLY"
else
FLAGSYN="n"
fi
fi
fi
}
# Performance Stop Watch
stopWatch() {
if [[ "$1" = "stop" ]]; then
endEpoch=$(date +%s)
endTime=$(date)
durationEpoch=$((endEpoch - startEpoch))
echo
echo " Start time: ${startTime}"
echo " End time: ${endTime}"
echo " Duration: ${durationEpoch} seconds"
echo " Max jobs: $JOBS"
echo " Option: $MODE"
echo
else
startEpoch=$(date +%s)
startTime=$(date)
fi
}
# Command Processor
processOptions() {
case $1 in
1)
stopWatch "start"
installDependencies
stopWatch "stop"
if [ "$INTERACTIVE" = "y" ]; then
echo " ${Yellow}All Done!${End} ...press enter"
read -r
printHeader
menu
fi
;;
2)
getJobsCount
stopWatch "start"
installLibfdk
stopWatch "stop"
if [ "$INTERACTIVE" = "y" ]; then
echo " ${Yellow}All Done!${End} ...press enter"
read -r
printHeader
menu
fi
;;
3)
getJobsCount
stopWatch "start"
installLibx264
stopWatch "stop"
if [ "$INTERACTIVE" = "y" ]; then
echo " ${Yellow}All Done!${End} ...press enter"
read -r
printHeader
menu
fi
;;
4)
getJobsCount
stopWatch "start"
installLibx265
stopWatch "stop"
if [ "$INTERACTIVE" = "y" ]; then
echo " ${Yellow}All Done!${End} ...press enter"
read -r
printHeader
menu
fi
;;
5)
getJobsCount
stopWatch "start"
installLibvpx
stopWatch "stop"
if [ "$INTERACTIVE" = "y" ]; then
echo " ${Yellow}All Done!${End} ...press enter"
read -r
printHeader
menu
fi
;;
6)
getJobsCount
stopWatch "start"
installLibopus
stopWatch "stop"
if [ "$INTERACTIVE" = "y" ]; then
echo " ${Yellow}All Done!${End} ...press enter"
read -r
printHeader
menu
fi
;;
7)
getJobsCount
stopWatch "start"
installFFmpeg
stopWatch "stop"
if [ "$INTERACTIVE" = "y" ]; then
echo " ${Yellow}All Done!${End} ...press enter"
read -r
printHeader
menu
fi
;;
8)
getJobsCount
getLib FDK_PARAM FDK "libfdk-aac"
getLib L264_PARAM L264 "libx264"
getLib L265_PARAM L265 "libx265"
getLib LVPX_PARAM LVPX "libvpx"
getLib LOPUS_PARAM LOPUS "libopus"
getFlags
stopWatch "start"
installDependencies
if [[ "$FDK" = "y" ]]; then
installLibfdk
fi
if [[ "$L264" = "y" ]]; then
installLibx264
fi
if [[ "$L265" = "y" ]]; then
installLibx265
fi
if [[ "$LVPX" = "y" ]]; then
installLibvpx
fi
if [[ "$LOPUS" = "y" ]]; then
installLibopus
fi
installFFmpeg
cleanDirectory
stopWatch "stop"
if [ "$INTERACTIVE" = "y" ]; then
echo " ${Yellow}All Done!${End} ...press enter"
read -r
printHeader
menu
fi
;;
9)
stopWatch "start"
cleanDirectory
stopWatch "stop"
if [ "$INTERACTIVE" = "y" ]; then
echo " ${Yellow}All Done!${End} ...press enter"
read -r
printHeader
menu
fi
;;
esac
}
# Entry Point
cd ~
while [ $# -gt 0 ]; do
case "$1" in
--help)
printf "\033c"
echo "Options:"
echo
echo " --force-build : Forces the build of required libs, regaldess of their availability with the systems repository sources"
echo " --none-interactive : Disables interactive mode"
echo " --mode [1-9] : Sets the operation. Requies --none-interactive"
echo " --max-jobs [1-#] Default: 3 : Sets the number of build threads"
echo " --libfdk-aac [y:n] Default: y : Enable/Disable this lib"
echo " --libx264 [y:n] Default: y : Enable/Disable this lib"
echo " --libx265 [y:n] Default: n : Enable/Disable this lib"
echo " --libopus [y:n] Default: n : Enable/Disable this lib"
echo " --libvpx [y:n] Default: n : Enable/Disable this lib"
echo " --extra-flags [*] Default: None : Adds extra build args to the ffmpeg build"
echo
exit 0
;;
--force-build)
FORCE_BUILD=true
;;
--none-interactive)
INTERACTIVE="n"
;;
--mode)
MODE=$2
MODE_PARAM=true
;;
--max-jobs)
JOBS=$2
JOBS_PARAM=true
;;
--libfdk-aac)
FDK="$2"
FDK_PARAM=true
;;
--libx264)
L264="$2"
L264_PARAM=true
;;
--libx265)
L265="$2"
L265_PARAM=true
;;
--libopus)
LOPUS="$2"
LOPUS_PARAM=true
;;
--libvpx)
LVPX="$2"
LVPX_PARAM=true
;;
--extra-flags)
FLAGSYN="y"
FLAGS="$2"
FLAGS_PARAM=true
;;
esac
shift
done
if [ "$INTERACTIVE" = "n" ]; then
printHeader
processOptions $MODE
else
printHeader
menu
fi