Skip to content

Commit 4a626d8

Browse files
authored
Merge pull request #146 from native-api/use_patched_ffmpeg
Use patched ffmpeg formula in OSX
2 parents 3d8a1e9 + c416449 commit 4a626d8

File tree

1 file changed

+45
-2
lines changed

1 file changed

+45
-2
lines changed

config.sh

+45-2
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,55 @@ if [ -n "$IS_OSX" ]; then
3333
BREW_SLOW_BUILIDING_PACKAGES=$(printf '%s\n' \
3434
"x265 20" \
3535
"cmake 15" \
36-
"ffmpeg 10" \
36+
"ffmpeg_opencv 10" \
3737
)
3838

3939
#Contrib adds significantly to project's build time
4040
if [ "$ENABLE_CONTRIB" -eq 1 ]; then
4141
BREW_TIME_LIMIT=$((BREW_TIME_LIMIT - 10*60))
4242
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+
}
4385

4486
fi
4587

@@ -71,7 +113,8 @@ function pre_build {
71113

72114
echo 'Installing FFmpeg'
73115

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; }
75118

76119
else
77120
echo "Running for linux"

0 commit comments

Comments
 (0)