forked from markus-perl/ffmpeg-build-script
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathbuild-ffmpeg
executable file
·896 lines (746 loc) · 26 KB
/
build-ffmpeg
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
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
#!/bin/bash
# HOMEPAGE: https://github.com/markus-perl/ffmpeg-build-script
# LICENSE: https://github.com/markus-perl/ffmpeg-build-script/blob/master/LICENSE
PROGNAME=$(basename "$0")
VERSION=1.22.rc1
CWD=$(pwd)
PACKAGES="$CWD/packages"
WORKSPACE="$CWD/workspace"
CFLAGS="-I$WORKSPACE/include"
LDFLAGS="-L$WORKSPACE/lib"
LDEXEFLAGS=""
EXTRALIBS="-ldl -lpthread -lm -lz"
MACOS_M1=false
CONFIGURE_OPTIONS=()
# Check for Apple Silicon
if [[ ("$(uname -m)" == "arm64") && ("$OSTYPE" == "darwin"*) ]]; then
# If arm64 AND darwin (macOS)
export ARCH=arm64
export MACOSX_DEPLOYMENT_TARGET=11.0
MACOS_M1=true
fi
is_mac () {
if [[ "$OSTYPE" == "darwin"* ]]; then
return 0
fi
return 1
}
# read by gcc and cmake
# https://cmake.org/cmake/help/latest/variable/CMAKE_OSX_DEPLOYMENT_TARGET.html
export MACOSX_DEPLOYMENT_TARGET=10.11
# Speed up the process
# Env Var NUMJOBS overrides automatic detection
if [[ -n "$NUMJOBS" ]]; then
MJOBS="$NUMJOBS"
elif [[ -f /proc/cpuinfo ]]; then
MJOBS=$(grep -c processor /proc/cpuinfo)
elif is_mac; then
MJOBS=$(sysctl -n machdep.cpu.thread_count)
CONFIGURE_OPTIONS=("--enable-videotoolbox")
else
MJOBS=4
fi
CONFIGURE_OPTIONS+=("--extra-version=beamcube")
make_dir() {
remove_dir "$1"
if ! mkdir "$1"; then
printf "\n Failed to create dir %s" "$1"
exit 1
fi
}
remove_dir() {
if [ -d "$1" ]; then
rm -r "$1"
fi
}
download() {
# download url [filename[dirname]]
DOWNLOAD_PATH="$PACKAGES"
DOWNLOAD_FILE="${2:-"${1##*/}"}"
if [[ "$DOWNLOAD_FILE" =~ tar. ]]; then
TARGETDIR="${DOWNLOAD_FILE%.*}"
TARGETDIR="${3:-"${TARGETDIR%.*}"}"
else
TARGETDIR="${3:-"${DOWNLOAD_FILE%.*}"}"
fi
if [ ! -f "$DOWNLOAD_PATH/$DOWNLOAD_FILE" ]; then
echo "Downloading $1 as $DOWNLOAD_FILE"
curl -L --silent -o "$DOWNLOAD_PATH/$DOWNLOAD_FILE" "$1"
EXITCODE=$?
if [ $EXITCODE -ne 0 ]; then
echo ""
echo "Failed to download $1. Exitcode $EXITCODE. Retrying in 10 seconds"
sleep 10
curl -L --silent -o "$DOWNLOAD_PATH/$DOWNLOAD_FILE" "$1"
fi
EXITCODE=$?
if [ $EXITCODE -ne 0 ]; then
echo ""
echo "Failed to download $1. Exitcode $EXITCODE"
exit 1
fi
echo "... Done"
else
echo "$DOWNLOAD_FILE has already downloaded."
fi
make_dir "$DOWNLOAD_PATH/$TARGETDIR"
if [ -n "$3" ]; then
if ! tar -xvf "$DOWNLOAD_PATH/$DOWNLOAD_FILE" -C "$DOWNLOAD_PATH/$TARGETDIR" 2>/dev/null >/dev/null; then
echo "Failed to extract $DOWNLOAD_FILE"
exit 1
fi
else
if ! tar -xvf "$DOWNLOAD_PATH/$DOWNLOAD_FILE" -C "$DOWNLOAD_PATH/$TARGETDIR" --strip-components 1 2>/dev/null >/dev/null; then
echo "Failed to extract $DOWNLOAD_FILE"
exit 1
fi
fi
echo "Extracted $DOWNLOAD_FILE"
cd "$DOWNLOAD_PATH/$TARGETDIR" || (
echo "Error has occurred."
exit 1
)
}
execute() {
echo "$ $*"
OUTPUT=$("$@" 2>&1)
# shellcheck disable=SC2181
if [ $? -ne 0 ]; then
echo "$OUTPUT"
echo ""
echo "Failed to Execute $*" >&2
exit 1
fi
}
build() {
echo ""
echo "building $1"
echo "======================="
if [ -f "$PACKAGES/$1.done" ]; then
echo "$1 already built. Remove $PACKAGES/$1.done lockfile to rebuild it."
return 1
fi
return 0
}
command_exists() {
if ! [[ -x $(command -v "$1") ]]; then
return 1
fi
return 0
}
library_exists() {
if ! [[ -x $(pkg-config --exists --print-errors "$1" 2>&1 >/dev/null) ]]; then
return 1
fi
return 0
}
set_mac_install_name () {
local name="${2:-$1}"
if is_mac; then
execute install_name_tool -id "${WORKSPACE}/lib/$name" $1
fi
}
build_done() {
touch "$PACKAGES/$1.done"
}
verify_binary_type() {
BINARY_TYPE=$(file "$WORKSPACE/bin/ffmpeg" | sed -n 's/^.*\:\ \(.*$\)/\1/p')
echo ""
case $BINARY_TYPE in
"Mach-O 64-bit executable arm64")
echo "Successfully built Apple Silicon (M1) for ${OSTYPE}: ${BINARY_TYPE}"
;;
*)
echo "Successfully built binary for ${OSTYPE}: ${BINARY_TYPE}"
;;
esac
}
cleanup() {
remove_dir "$PACKAGES"
remove_dir "$WORKSPACE"
echo "Cleanup done."
echo ""
}
usage() {
echo "Usage: $PROGNAME [OPTIONS]"
echo "Options:"
echo " -h, --help Display usage information"
echo " --version Display version information"
echo " -b, --build Starts the build process"
echo " -c, --cleanup Remove all working dirs"
echo " -f, --full-static Build a full static FFmpeg binary (eg. glibc, pthreads etc...) **only Linux**"
echo " Note: Because of the NSS (Name Service Switch), glibc does not recommend static links."
echo ""
}
while (($# > 0)); do
case $1 in
-h | --help)
usage
exit 0
;;
--version)
echo "$VERSION"
exit 0
;;
-*)
if [[ "$1" == "--build" || "$1" =~ 'b' ]]; then
bflag='-b'
fi
if [[ "$1" == "--cleanup" || "$1" =~ 'c' && ! "$1" =~ '--' ]]; then
cflag='-c'
cleanup
fi
if [[ "$1" == "--full-static" || "$1" =~ 'f' ]]; then
if is_mac; then
echo "Error: A full static binary can only be build on Linux."
exit 1
fi
LDEXEFLAGS="-static"
fi
shift
;;
*)
usage
exit 1
;;
esac
done
echo "ffmpeg-build-script v$VERSION"
echo "========================="
echo ""
if [ -z "$bflag" ]; then
if [ -z "$cflag" ]; then
usage
exit 1
fi
exit 0
fi
echo "Using $MJOBS make jobs simultaneously."
if [ -n "$LDEXEFLAGS" ]; then
echo "Start the build in full static mode."
fi
mkdir -p "$PACKAGES"
mkdir -p "$WORKSPACE"
export PATH="${WORKSPACE}/bin:$PATH"
PKG_CONFIG_PATH="/usr/local/lib/x86_64-linux-gnu/pkgconfig:/usr/local/lib/pkgconfig"
PKG_CONFIG_PATH+=":/usr/local/share/pkgconfig:/usr/lib/x86_64-linux-gnu/pkgconfig:/usr/lib/pkgconfig:/usr/share/pkgconfig:/usr/lib64/pkgconfig"
export PKG_CONFIG_PATH
if ! command_exists "make"; then
echo "make not installed."
exit 1
fi
if ! command_exists "g++"; then
echo "g++ not installed."
exit 1
fi
if ! command_exists "curl"; then
echo "curl not installed."
exit 1
fi
if ! command_exists "python"; then
echo "Python command not found. Lv2 filter will not be available."
fi
##
## build tools
##
if build "pkg-config"; then
download "https://pkgconfig.freedesktop.org/releases/pkg-config-0.29.2.tar.gz"
execute ./configure --silent --prefix="${WORKSPACE}" --with-pc-path="${WORKSPACE}"/lib/pkgconfig --with-internal-glib
execute make -j $MJOBS
execute make install
build_done "pkg-config"
fi
if command_exists "python"; then
if build "lv2"; then
download "https://lv2plug.in/spec/lv2-1.18.0.tar.bz2" "lv2-1.18.0.tar.bz2"
execute ./waf configure --prefix="${WORKSPACE}" --lv2-user
execute ./waf
execute ./waf install
build_done "lv2"
fi
if build "waflib"; then
download "https://gitlab.com/drobilla/autowaf/-/archive/cc37724b9bfa889baebd8cb10f38b8c7cab83e37/autowaf-cc37724b9bfa889baebd8cb10f38b8c7cab83e37.tar.gz" "autowaf.tar.gz"
build_done "waflib"
fi
if build "serd"; then
download "https://gitlab.com/drobilla/serd/-/archive/v0.30.6/serd-v0.30.6.tar.gz" "serd-v0.30.6.tar.gz"
execute cp -r "${PACKAGES}"/autowaf/* "${PACKAGES}/serd-v0.30.6/waflib/"
execute ./waf configure --prefix="${WORKSPACE}" --static --no-shared --no-posix
execute ./waf
execute ./waf install
build_done "serd"
fi
if build "pcre"; then
download "https://ftp.pcre.org/pub/pcre/pcre-8.44.tar.gz" "pcre-8.44.tar.gz"
execute ./configure --prefix="${WORKSPACE}" --disable-shared --enable-static
execute make -j $MJOBS
execute make install
build_done "pcre"
fi
if build "sord"; then
download "https://gitlab.com/drobilla/sord/-/archive/v0.16.6/sord-v0.16.6.tar.gz" "sord-v0.16.6.tar.gz"
execute cp -r "${PACKAGES}"/autowaf/* "${PACKAGES}/sord-v0.16.6/waflib/"
execute ./waf configure --prefix="${WORKSPACE}" CFLAGS="${CFLAGS}" --static --no-shared --no-utils
execute ./waf CFLAGS="${CFLAGS}"
execute ./waf install
build_done "sord"
fi
if build "sratom"; then
download "https://gitlab.com/lv2/sratom/-/archive/v0.6.6/sratom-v0.6.6.tar.gz" "sratom-v0.6.6.tar.gz"
execute cp -r "${PACKAGES}"/autowaf/* "${PACKAGES}/sratom-v0.6.6/waflib/"
execute ./waf configure --prefix="${WORKSPACE}" --static --no-shared
execute ./waf
execute ./waf install
build_done "sratom"
fi
if build "lilv"; then
download "https://gitlab.com/lv2/lilv/-/archive/v0.24.10/lilv-v0.24.10.tar.gz" "lilv-v0.24.10.tar.gz"
execute cp -r "${PACKAGES}"/autowaf/* "${PACKAGES}/lilv-v0.24.10/waflib/"
execute ./waf configure --prefix="${WORKSPACE}" --static --no-shared --no-utils
execute ./waf
execute ./waf install
CFLAGS+=" -I$WORKSPACE/include/lilv-0"
build_done "lilv"
fi
CONFIGURE_OPTIONS+=("--enable-lv2")
fi
if build "yasm"; then
download "https://github.com/yasm/yasm/releases/download/v1.3.0/yasm-1.3.0.tar.gz"
execute ./configure --prefix="${WORKSPACE}"
execute make -j $MJOBS
execute make install
build_done "yasm"
fi
if build "nasm"; then
download "https://www.nasm.us/pub/nasm/releasebuilds/2.15.05/nasm-2.15.05.tar.xz"
execute ./configure --prefix="${WORKSPACE}" --disable-shared --enable-static
execute make -j $MJOBS
execute make install
build_done "nasm"
fi
if build "zlib"; then
download "https://www.zlib.net/zlib-1.2.11.tar.gz"
execute ./configure --static --prefix="${WORKSPACE}"
execute make -j $MJOBS
execute make install
build_done "zlib"
fi
if build "openssl"; then
download "https://www.openssl.org/source/openssl-1.1.1i.tar.gz"
if $MACOS_M1; then
sed -n 's/\(##### GNU Hurd\)/"darwin64-arm64-cc" => { \n inherit_from => [ "darwin-common", asm("aarch64_asm") ],\n CFLAGS => add("-Wall"),\n cflags => add("-arch arm64 "),\n lib_cppflags => add("-DL_ENDIAN"),\n bn_ops => "SIXTY_FOUR_BIT_LONG", \n perlasm_scheme => "macosx", \n}, \n\1/g' Configurations/10-main.conf
execute ./configure --prefix="${WORKSPACE}" no-shared no-asm darwin64-arm64-cc
else
execute ./config --prefix="${WORKSPACE}" --openssldir="${WORKSPACE}" --with-zlib-include="${WORKSPACE}"/include/ --with-zlib-lib="${WORKSPACE}"/lib no-shared zlib
fi
execute make -j $MJOBS
execute make install_sw
build_done "openssl"
fi
CONFIGURE_OPTIONS+=("--enable-openssl")
if build "meson"; then
execute pip3 install install meson ninja
build_done "meson"
fi
if build "cmake"; then
download "https://cmake.org/files/v3.18/cmake-3.18.4.tar.gz"
execute ./configure --prefix="${WORKSPACE}" --system-zlib
execute make -j $MJOBS
execute make install
build_done "cmake"
fi
if build "svtav1"; then
download "https://github.com/AOMediaCodec/SVT-AV1/archive/v0.8.6.tar.gz"
cd Build/linux || exit
execute cmake -DCMAKE_INSTALL_PREFIX="${WORKSPACE}" -DENABLE_SHARED=off -DBUILD_SHARED_LIBS=OFF ../.. -G"Unix Makefiles" -DCMAKE_BUILD_TYPE=Release
execute make -j $MJOBS
execute make install
execute cp SvtAv1Enc.pc "${WORKSPACE}/lib/pkgconfig/"
execute cp SvtAv1Dec.pc "${WORKSPACE}/lib/pkgconfig/"
build_done "svtav1"
fi
CONFIGURE_OPTIONS+=("--enable-libsvtav1")
##
## video library
##
if build "x264"; then
download "https://code.videolan.org/videolan/x264/-/archive/0d754ec36013fee82978496cd56fbd48824910b3/x264-0d754ec36013fee82978496cd56fbd48824910b3.tar.gz" "x264-0d754ec.tar.gz"
cd "${PACKAGES}"/x264-0d754ec || exit
if [[ "$OSTYPE" == "linux-gnu" ]]; then
execute ./configure --prefix="${WORKSPACE}" --enable-static --enable-pic CXXFLAGS="-fPIC"
else
execute ./configure --prefix="${WORKSPACE}" --enable-static --enable-pic
fi
execute make -j $MJOBS
execute make install
execute make install-lib-static
build_done "x264"
fi
CONFIGURE_OPTIONS+=("--enable-libx264")
if build "x265"; then
download "https://github.com/videolan/x265/archive/Release_3.5.tar.gz" "x265-3.5.tar.gz"
cd build/linux || exit
execute cmake -DCMAKE_INSTALL_PREFIX="${WORKSPACE}" -DENABLE_SHARED=off -DBUILD_SHARED_LIBS=OFF ../../source
execute make -j $MJOBS
execute make install
if [ -n "$LDEXEFLAGS" ]; then
sed -i.backup 's/-lgcc_s/-lgcc_eh/g' "${WORKSPACE}/lib/pkgconfig/x265.pc" # The -i.backup is intended and required on MacOS: https://stackoverflow.com/questions/5694228/sed-in-place-flag-that-works-both-on-mac-bsd-and-linux
fi
build_done "x265"
fi
CONFIGURE_OPTIONS+=("--enable-libx265")
if build "libvpx"; then
download "https://github.com/webmproject/libvpx/archive/v1.9.0.tar.gz" "libvpx-1.9.0.tar.gz"
if is_mac; then
echo "Applying Darwin patch"
sed "s/,--version-script//g" build/make/Makefile >build/make/Makefile.patched
sed "s/-Wl,--no-undefined -Wl,-soname/-Wl,-undefined,error -Wl,-install_name/g" build/make/Makefile.patched >build/make/Makefile
fi
execute ./configure --prefix="${WORKSPACE}" --disable-unit-tests --disable-shared --as=yasm
execute make -j $MJOBS
execute make install
build_done "libvpx"
fi
CONFIGURE_OPTIONS+=("--enable-libvpx")
if build "xvidcore"; then
download "https://downloads.xvid.com/downloads/xvidcore-1.3.7.tar.gz"
cd build/generic || exit
execute ./configure --prefix="${WORKSPACE}" --disable-shared --enable-static
execute make -j $MJOBS
execute make install
if [[ -f ${WORKSPACE}/lib/libxvidcore.4.dylib ]]; then
execute rm "${WORKSPACE}/lib/libxvidcore.4.dylib"
fi
if [[ -f ${WORKSPACE}/lib/libxvidcore.so ]]; then
execute rm "${WORKSPACE}"/lib/libxvidcore.so*
fi
build_done "xvidcore"
fi
CONFIGURE_OPTIONS+=("--enable-libxvid")
if build "vid_stab"; then
download "https://github.com/georgmartius/vid.stab/archive/v1.1.0.tar.gz" "vid.stab-1.1.0.tar.gz"
if $MACOS_M1; then
curl -s -o "$PACKAGES/vid.stab-1.1.0/fix_cmake_quoting.patch" https://raw.githubusercontent.com/Homebrew/formula-patches/5bf1a0e0cfe666ee410305cece9c9c755641bfdf/libvidstab/fix_cmake_quoting.patch
patch -p1 <fix_cmake_quoting.patch
fi
execute cmake -DBUILD_SHARED_LIBS=OFF -DCMAKE_INSTALL_PREFIX="${WORKSPACE}" -DUSE_OMP=OFF -DENABLE_SHARED=off .
execute make
execute make install
build_done "vid_stab"
fi
CONFIGURE_OPTIONS+=("--enable-libvidstab")
if build "twolame"; then
download "https://downloads.sourceforge.net/twolame/twolame-0.4.0.tar.gz"
execute ./configure --prefix="${WORKSPACE}" --enable-static --disable-shared
execute make -j $MJOBS
execute make install
build_done "twolame"
fi
CONFIGURE_OPTIONS+=("--enable-libtwolame")
if build "av1"; then
download "https://aomedia.googlesource.com/aom/+archive/b52ee6d44adaef8a08f6984390de050d64df9faa.tar.gz" "av1.tar.gz" "av1"
make_dir "$PACKAGES"/aom_build
cd "$PACKAGES"/aom_build || exit
if $MACOS_M1; then
execute cmake -DENABLE_TESTS=0 -DCMAKE_INSTALL_PREFIX="${WORKSPACE}" -DCMAKE_INSTALL_LIBDIR=lib -DCONFIG_RUNTIME_CPU_DETECT=0 "$PACKAGES"/av1
else
execute cmake -DENABLE_TESTS=0 -DCMAKE_INSTALL_PREFIX="${WORKSPACE}" -DCMAKE_INSTALL_LIBDIR=lib "$PACKAGES"/av1
fi
execute make -j $MJOBS
execute make install
build_done "av1"
fi
CONFIGURE_OPTIONS+=("--enable-libaom")
if build "dav1d"; then
download "https://code.videolan.org/videolan/dav1d/-/archive/0.7.1/dav1d-0.7.1.tar.gz"
make_dir "$PACKAGES"/dav1d_build
cd "$PACKAGES"/dav1d_build || exit
execute meson --prefix="${WORKSPACE}" --libdir="${WORKSPACE}/lib" --default-library=static ../dav1d-0.7.1
execute ninja
execute ninja install
build_done "dav1d"
fi
CONFIGURE_OPTIONS+=("--enable-libdav1d")
if build "zimg"; then
download "https://github.com/sekrit-twc/zimg/archive/release-3.0.1.tar.gz"
execute autoreconf -i
execute ./configure --prefix="${WORKSPACE}" --disable-shared --enable-static
execute make -j $MJOBS
execute make install
build_done "zimg"
fi
CONFIGURE_OPTIONS+=("--enable-libzimg")
##
## audio library
##
if build "opencore"; then
download "https://deac-riga.dl.sourceforge.net/project/opencore-amr/opencore-amr/opencore-amr-0.1.5.tar.gz"
execute ./configure --prefix="${WORKSPACE}" --disable-shared --enable-static
execute make -j $MJOBS
execute make install
build_done "opencore"
fi
CONFIGURE_OPTIONS+=("--enable-libopencore_amrnb" "--enable-libopencore_amrwb")
if build "lame"; then
download "https://netcologne.dl.sourceforge.net/project/lame/lame/3.100/lame-3.100.tar.gz"
execute ./configure --prefix="${WORKSPACE}" --disable-shared --enable-static
execute make -j $MJOBS
execute make install
build_done "lame"
fi
CONFIGURE_OPTIONS+=("--enable-libmp3lame")
if build "opus"; then
download "https://archive.mozilla.org/pub/opus/opus-1.3.1.tar.gz"
execute ./configure --prefix="${WORKSPACE}" --disable-shared --enable-static
execute make -j $MJOBS
execute make install
build_done "opus"
fi
CONFIGURE_OPTIONS+=("--enable-libopus")
if build "libogg"; then
download "https://ftp.osuosl.org/pub/xiph/releases/ogg/libogg-1.3.3.tar.gz"
execute ./configure --prefix="${WORKSPACE}" --disable-shared --enable-static
execute make -j $MJOBS
execute make install
build_done "libogg"
fi
if build "libvorbis"; then
download "https://ftp.osuosl.org/pub/xiph/releases/vorbis/libvorbis-1.3.6.tar.gz"
execute ./configure --prefix="${WORKSPACE}" --with-ogg-libraries="${WORKSPACE}"/lib --with-ogg-includes="${WORKSPACE}"/include/ --enable-static --disable-shared --disable-oggtest
execute make -j $MJOBS
execute make install
build_done "libvorbis"
fi
CONFIGURE_OPTIONS+=("--enable-libvorbis")
if build "libtheora"; then
download "https://ftp.osuosl.org/pub/xiph/releases/theora/libtheora-1.1.1.tar.gz"
sed "s/-fforce-addr//g" configure >configure.patched
chmod +x configure.patched
mv configure.patched configure
execute ./configure --prefix="${WORKSPACE}" --with-ogg-libraries="${WORKSPACE}"/lib --with-ogg-includes="${WORKSPACE}"/include/ --with-vorbis-libraries="${WORKSPACE}"/lib --with-vorbis-includes="${WORKSPACE}"/include/ --enable-static --disable-shared --disable-oggtest --disable-vorbistest --disable-examples --disable-asm --disable-spec
execute make -j $MJOBS
execute make install
build_done "libtheora"
fi
CONFIGURE_OPTIONS+=("--enable-libtheora")
if build "fdk_aac"; then
download "https://sourceforge.net/projects/opencore-amr/files/fdk-aac/fdk-aac-2.0.1.tar.gz/download?use_mirror=gigenet" "fdk-aac-2.0.1.tar.gz"
execute ./configure --prefix="${WORKSPACE}" --disable-shared --enable-static
execute make -j $MJOBS
execute make install
build_done "fdk_aac"
fi
CONFIGURE_OPTIONS+=("--enable-libfdk-aac")
if build "shine"; then
download "https://github.com/toots/shine/archive/3.1.1.tar.gz" "shine-3.1.1.tar.gz"
execute autoreconf -i
execute ./configure --prefix="${WORKSPACE}" --disable-shared --enable-static
execute make -j $MJOBS
execute make install
build_done "shine"
fi
CONFIGURE_OPTIONS+=("--enable-libshine")
if build "soxr"; then
download "http://ftp.debian.org/debian/pool/main/libs/libsoxr/libsoxr_0.1.3.orig.tar.xz" "soxr-0.1.3.tar.xz"
make_dir build
cd build || exit
execute cmake .. -DWITH_OPENMP:BOOL=OFF -Wno-dev -DCMAKE_INSTALL_PREFIX="${WORKSPACE}" -DCMAKE_BUILD_TYPE=Release -DBUILD_SHARED_LIBS:BOOL=OFF
execute make -j $MJOBS
execute make install
build_done "soxr"
fi
CONFIGURE_OPTIONS+=("--enable-libsoxr")
if build "speex"; then
download "http://downloads.us.xiph.org/releases/speex/speex-1.2.0.tar.gz"
execute ./configure --prefix="${WORKSPACE}" --disable-shared --enable-static
execute make -j $MJOBS
execute make install
build_done "speex"
fi
CONFIGURE_OPTIONS+=("--enable-libspeex")
##
## image library
##
if build "libwebp"; then
download "https://github.com/webmproject/libwebp/archive/v1.1.0.tar.gz" "libwebp-1.1.0.tar.gz"
make_dir build
cd build || exit
execute cmake -DCMAKE_INSTALL_PREFIX="${WORKSPACE}" -DCMAKE_INSTALL_LIBDIR=lib -DCMAKE_INSTALL_BINDIR=bin -DCMAKE_INSTALL_INCLUDEDIR=include -DENABLE_SHARED=OFF -DENABLE_STATIC=ON ../
execute make -j $MJOBS
execute make install
build_done "libwebp"
fi
CONFIGURE_OPTIONS+=("--enable-libwebp")
if build "openjpeg"; then
download "https://github.com/uclouvain/openjpeg/archive/v2.3.1.tar.gz" "openjpeg-v2.3.1.tar.gz"
make_dir build
cd build || exit
execute cmake .. -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX="${WORKSPACE}" -DBUILD_SHARED_LIBS:bool=OFF
execute make -j $MJOBS
execute make install
build_done "openjpeg"
fi
CONFIGURE_OPTIONS+=("--enable-libopenjpeg")
##
## other library
##
if build "libsdl"; then
download "https://www.libsdl.org/release/SDL2-2.0.14.tar.gz"
execute ./configure --prefix="${WORKSPACE}" --disable-shared --enable-static
execute make -j $MJOBS
execute make install
build_done "libsdl"
fi
if build "snappy"; then
download "https://github.com/google/snappy/archive/1.1.8.tar.gz"
make_dir build
cd build || exit
execute cmake .. -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX="${WORKSPACE}" -DBUILD_SHARED_LIBS:bool=OFF
execute make -j $MJOBS
set_mac_install_name "libsnappy.1.1.8.dylib" "libsnappy.1.dylib"
execute make install
build_done "srt"
build_done "snappy"
fi
CONFIGURE_OPTIONS+=("--enable-libsnappy")
if build "xz"; then
download "https://tukaani.org/xz/xz-5.2.5.tar.gz"
execute ./configure --prefix="${WORKSPACE}" --disable-shared --enable-static
execute make -j $MJOBS
execute make install
build_done "xz"
fi
##
## HWaccel library
##
if [[ "$OSTYPE" == "linux-gnu" ]]; then
if command_exists "nvcc"; then
if build "nv-codec"; then
download "https://github.com/FFmpeg/nv-codec-headers/releases/download/n11.0.10.0/nv-codec-headers-11.0.10.0.tar.gz"
execute make PREFIX="${WORKSPACE}"
execute make install PREFIX="${WORKSPACE}"
build_done "nv-codec"
fi
CFLAGS+=" -I/usr/local/cuda/include"
LDFLAGS+=" -L/usr/local/cuda/lib64"
CONFIGURE_OPTIONS+=("--enable-cuda-nvcc" "--enable-cuvid" "--enable-nvenc" "--enable-cuda-llvm")
if [ -z "$LDEXEFLAGS" ]; then
CONFIGURE_OPTIONS+=("--enable-libnpp") # Only libnpp cannot be statically linked.
fi
# https://arnon.dk/matching-sm-architectures-arch-and-gencode-for-various-nvidia-cards/
CONFIGURE_OPTIONS+=("--nvccflags=-gencode arch=compute_52,code=sm_52")
fi
# Vaapi doesn't work well with static links FFmpeg.
if [ -z "$LDEXEFLAGS" ]; then
# If the libva development SDK is installed, enable vaapi.
if library_exists "libva"; then
if build "vaapi"; then
build_done "vaapi"
fi
CONFIGURE_OPTIONS+=("--enable-vaapi")
fi
fi
fi
##
## FFmpeg
##
build "ffmpeg"
download "https://git.ffmpeg.org/gitweb/ffmpeg.git/snapshot/553eb0773763798a6b9656b621cb125e1f6edbcc.tar.gz"
# shellcheck disable=SC2086
./configure "${CONFIGURE_OPTIONS[@]}" \
--disable-debug \
--disable-doc \
--disable-shared \
--enable-gpl \
--enable-nonfree \
--enable-pthreads \
--enable-static \
--enable-version3 \
--extra-cflags="${CFLAGS}" \
--extra-ldexeflags="${LDEXEFLAGS}" \
--extra-ldflags="${LDFLAGS}" \
--extra-libs="${EXTRALIBS}" \
--pkgconfigdir="$WORKSPACE/lib/pkgconfig" \
--pkg-config-flags="--static" \
--prefix="${WORKSPACE}"
if is_mac; then
execute dsymutil libavcodec/libavcodec.dylib -o libavcodec.dSYM
execute dsymutil libavdevice/libavdevice.dylib -o libavdevice.dSYM
execute dsymutil libavfilter/libavfilter.dylib -o libavfilter.dSYM
execute dsymutil libavformat/libavformat.dylib -o libavformat.dSYM
# we're not building this one (libswresample replaces this)
# execute dsymutil libavresample/libavresample.dylib -o libavresample.dSYM
execute dsymutil libavutil/libavutil.dylib -o libavutil.dSYM
execute dsymutil libpostproc/libpostproc.dylib -o libpostproc.dSYM
execute dsymutil libswresample/libswresample.dylib -o libswresample.dSYM
execute dsymutil libswscale/libswscale.dylib -o libswscale.dSYM
fi
if [[ -n "$SENTRY_AUTH_TOKEN" ]] && [[ -n "$SENTRY_ORG" ]] && [[ -n "$SENTRY_PROJECT" ]]; then
# TODO: install sentry-cli when running on CI
# reads SENTRY_AUTH_TOKEN, SENTRY_ORG and SENTRY_PROJECT from env
# https://docs.sentry.io/product/cli/configuration/#configuration-values
sentry-cli upload-dif .
fi
# strip symbols from binaries (i.e., make them smaller)
if is_mac; then
execute strip -x libavcodec/libavcodec.dylib
execute strip -x libavdevice/libavdevice.dylib
execute strip -x libavfilter/libavfilter.dylib
execute strip -x libavformat/libavformat.dylib
execute strip -x libavutil/libavutil.dylib
execute strip -x libpostproc/libpostproc.dylib
execute strip -x libswresample/libswresample.dylib
execute strip -x libswscale/libswscale.dylib
execute strip -x ffmpeg
execute strip -x ffprobe
execute strip -x ffplay
fi
execute make -j $MJOBS
execute make install
INSTALL_FOLDER="/usr/bin"
if is_mac; then
INSTALL_FOLDER="/usr/local/bin"
fi
verify_binary_type
echo ""
echo "Building done. The following binaries can be found here:"
echo "- ffmpeg: $WORKSPACE/bin/ffmpeg"
echo "- ffprobe: $WORKSPACE/bin/ffprobe"
echo "- ffplay: $WORKSPACE/bin/ffplay"
echo ""
if [[ "$AUTOINSTALL" == "yes" ]]; then
if command_exists "sudo"; then
sudo cp "$WORKSPACE/bin/ffmpeg" "$INSTALL_FOLDER/ffmpeg"
sudo cp "$WORKSPACE/bin/ffprobe" "$INSTALL_FOLDER/ffprobe"
sudo cp "$WORKSPACE/bin/ffplay" "$INSTALL_FOLDER/ffplay"
echo "Done. FFmpeg is now installed to your system."
else
cp "$WORKSPACE/bin/ffmpeg" "$INSTALL_FOLDER/ffmpeg"
cp "$WORKSPACE/bin/ffprobe" "$INSTALL_FOLDER/ffprobe"
sudo cp "$WORKSPACE/bin/ffplay" "$INSTALL_FOLDER/ffplay"
echo "Done. FFmpeg is now installed to your system."
fi
elif [[ ! "$SKIPINSTALL" == "yes" ]]; then
read -r -p "Install these binaries to your $INSTALL_FOLDER folder? Existing binaries will be replaced. [Y/n] " response
case $response in
[yY][eE][sS] | [yY])
if command_exists "sudo"; then
sudo cp "$WORKSPACE/bin/ffmpeg" "$INSTALL_FOLDER/ffmpeg"
sudo cp "$WORKSPACE/bin/ffprobe" "$INSTALL_FOLDER/ffprobe"
sudo cp "$WORKSPACE/bin/ffplay" "$INSTALL_FOLDER/ffplay"
else
cp "$WORKSPACE/bin/ffmpeg" "$INSTALL_FOLDER/ffmpeg"
cp "$WORKSPACE/bin/ffprobe" "$INSTALL_FOLDER/ffprobe"
cp "$WORKSPACE/bin/ffplay" "$INSTALL_FOLDER/ffplay"
fi
echo "Done. FFmpeg is now installed to your system."
;;
esac
fi
cd $CWD
if is_mac; then
node copy_mac_libs.js
cd "$WORKSPACE/mac"
execute zip --symlinks -r "ffmpeg-ffprobe-shared-darwin-x86_64.${VERSION}.zip" *
fi
exit 0