@@ -33,13 +33,55 @@ if [ -n "$IS_OSX" ]; then
33
33
BREW_SLOW_BUILIDING_PACKAGES=$( printf ' %s\n' \
34
34
" x265 20" \
35
35
" cmake 15" \
36
- " ffmpeg 10" \
36
+ " ffmpeg_opencv 10" \
37
37
)
38
38
39
39
# Contrib adds significantly to project's build time
40
40
if [ " $ENABLE_CONTRIB " -eq 1 ]; then
41
41
BREW_TIME_LIMIT=$(( BREW_TIME_LIMIT - 10 * 60 ))
42
42
fi
43
+
44
+ function generate_ffmpeg_formula {
45
+ local FF=" ffmpeg"
46
+ local LFF=" ffmpeg_opencv"
47
+ local FF_FORMULA; FF_FORMULA=$( brew formula " $FF " )
48
+ local LFF_FORMULA; LFF_FORMULA=" $( dirname " $FF_FORMULA " ) /${LFF} .rb"
49
+
50
+ local REGENERATE
51
+ if [ -f " $LFF_FORMULA " ]; then
52
+ local UPSTREAM_VERSION VERSION
53
+ _brew_parse_package_info " $FF " " " UPSTREAM_VERSION _ _
54
+ _brew_parse_package_info " $LFF " " " VERSION _ _ || REGENERATE=1
55
+ # `rebuild` clause is ignored on `brew bottle` and deleted
56
+ # from newly-generated formula on `brew bottle --merge` for some reason
57
+ # so can't compare rebuild numbers
58
+ if [ " $UPSTREAM_VERSION " != " $VERSION " ]; then
59
+ REGENERATE=1
60
+ fi
61
+ else
62
+ REGENERATE=1
63
+ fi
64
+ if [ -n " $REGENERATE " ]; then
65
+ echo " Regenerating custom ffmpeg formula"
66
+ # Bottle block syntax: https://docs.brew.sh/Bottles#bottle-dsl-domain-specific-language
67
+ perl -wpe ' BEGIN {our ($found_blank, $bottle_block);}
68
+ if (/(^class )(Ffmpeg)(\s.*)/) {$_=$1.$2."Opencv".$3."\n"; next;}
69
+ if (!$found_blank && /^$/) {$_.="conflicts_with \"ffmpeg\"\n\n"; $found_blank=1; next;}
70
+ if (!$bottle_block && /^\s*bottle do$/) { $bottle_block=1; next; }
71
+ if ($bottle_block) { if (/^\s*end\s*$/) { $bottle_block=0} elsif (/^\s*sha256\s/) {$_=""} next; }
72
+ if (/^\s*depends_on "(x264|x265|xvid)"$/) {$_=""; next;}
73
+ if (/^\s*--enable-(gpl|libx264|libx265|libxvid)$/) {$_=""; next;}
74
+ ' < " $FF_FORMULA " > " $LFF_FORMULA "
75
+ diff -u " $FF_FORMULA " " $LFF_FORMULA " || test $? -le 1
76
+
77
+ ( cd " $( dirname " $LFF_FORMULA " ) "
78
+ # This is the official way to add a formula
79
+ # https://docs.brew.sh/Formula-Cookbook#commit
80
+ git add " $( basename " $LFF_FORMULA " ) "
81
+ git commit -m " add/update custom ffmpeg ${VERSION} "
82
+ )
83
+ fi
84
+ }
43
85
44
86
fi
45
87
@@ -71,7 +113,8 @@ function pre_build {
71
113
72
114
echo ' Installing FFmpeg'
73
115
74
- brew_install_and_cache_within_time_limit ffmpeg || { [ $? -gt 1 ] && return 2 || return 0; }
116
+ generate_ffmpeg_formula
117
+ brew_install_and_cache_within_time_limit ffmpeg_opencv || { [ $? -gt 1 ] && return 2 || return 0; }
75
118
76
119
else
77
120
echo " Running for linux"
0 commit comments