Skip to content

Commit b18759f

Browse files
authored
Changes per request, plus bonus
* Define M1 variable once * Grab x264 archive vs git * configure vs Configure * bonus: output binary type. Feel free to take or leave :)
1 parent 11ffcd6 commit b18759f

File tree

1 file changed

+32
-15
lines changed

1 file changed

+32
-15
lines changed

build-ffmpeg

Lines changed: 32 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,14 @@ CFLAGS='-I$WORKSPACE/include'
1212
LDFLAGS="-L$WORKSPACE/lib"
1313
LDEXEFLAGS=""
1414
EXTRALIBS="-ldl -lpthread -lm -lz"
15+
MACOS_M1=false
1516
CONFIGURE_OPTIONS=()
1617
# Check for Apple Silicon
1718
if [[ ( "$(uname -m)" == "arm64" ) && ( "$OSTYPE" == "darwin"* ) ]]; then
1819
# If arm64 AND darwin (macOS)
1920
export ARCH=arm64
2021
export MACOSX_DEPLOYMENT_TARGET=11.0
22+
MACOS_M1=true
2123
fi
2224

2325

@@ -153,6 +155,19 @@ build_done () {
153155
touch "$PACKAGES/$1.done"
154156
}
155157

158+
verify_binary_type () {
159+
BINARY_TYPE=$(file $WORKSPACE/bin/ffmpeg | sed -n 's/^.*\:\ \(.*$\)/\1/p')
160+
echo ""
161+
case $BINARY_TYPE in
162+
"Mach-O 64-bit executable arm64")
163+
echo "Successfully built Apple Silicon (M1): ${BINARY_TYPE}"
164+
;;
165+
*)
166+
echo "Successfully built binary for ${OSTYPE}: ${BINARY_TYPE}"
167+
;;
168+
esac
169+
}
170+
156171
cleanup () {
157172
remove_dir "$PACKAGES"
158173
remove_dir "$WORKSPACE"
@@ -358,9 +373,9 @@ fi
358373

359374
if build "openssl"; then
360375
download "https://www.openssl.org/source/openssl-1.1.1i.tar.gz"
361-
if [[ ( "$ARCH" == "arm64" ) && ( "$OSTYPE" == "darwin"* ) ]]; then
376+
if $MACOS_M1 ; then
362377
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
363-
execute ./Configure --prefix="${WORKSPACE}" no-shared no-asm darwin64-arm64-cc
378+
execute ./configure --prefix="${WORKSPACE}" no-shared no-asm darwin64-arm64-cc
364379
else
365380
execute ./config --prefix="${WORKSPACE}" --openssldir="${WORKSPACE}" --with-zlib-include="${WORKSPACE}"/include/ --with-zlib-lib="${WORKSPACE}"/lib no-shared zlib
366381
fi
@@ -388,13 +403,14 @@ if build "x264"; then
388403

389404
if [[ "$OSTYPE" == "linux-gnu" ]]; then
390405
execute ./configure --prefix="${WORKSPACE}" --enable-static --enable-pic CXXFLAGS="-fPIC"
391-
elif [[ ( "$ARCH" == "arm64" ) && ( "$OSTYPE" == "darwin"* ) ]]; then
406+
elif $MACOS_M1 ; then
392407
## Get latest code to support arm64
393-
git clone --depth 1 -b master https://code.videolan.org/videolan/x264.git
394-
cd x264
395-
else
408+
download "https://code.videolan.org/videolan/x264/-/archive/0d754ec36013fee82978496cd56fbd48824910b3/x264-0d754ec36013fee82978496cd56fbd48824910b3.tar.gz" "x264-0d754ec.tar.gz"
409+
cd "${PACKAGES}"/x264-0d754ec
410+
else
396411
execute ./configure --prefix="${WORKSPACE}" --enable-static --enable-pic
397412
fi
413+
398414

399415
execute make -j $MJOBS
400416
execute make install
@@ -458,9 +474,10 @@ CONFIGURE_OPTIONS+=("--enable-libxvid")
458474

459475
if build "vid_stab"; then
460476
download "https://github.com/georgmartius/vid.stab/archive/v1.1.0.tar.gz" "vid.stab-1.1.0.tar.gz"
461-
## rich
462-
if [[ ( "$ARCH" == "arm64" ) && ( "$OSTYPE" == "darwin"* ) ]]; then
463-
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
477+
478+
if $MACOS_M1 ; then
479+
480+
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
464481
patch -p1 < fix_cmake_quoting.patch
465482
fi
466483
## rich
@@ -476,13 +493,11 @@ if build "av1"; then
476493
download "https://aomedia.googlesource.com/aom/+archive/b52ee6d44adaef8a08f6984390de050d64df9faa.tar.gz" "av1.tar.gz" "av1"
477494
make_dir "$PACKAGES"/aom_build
478495
cd "$PACKAGES"/aom_build || exit
479-
## rich
480-
if [[ ( "$ARCH" == "arm64" ) && ( "$OSTYPE" == "darwin"* ) ]]; then
496+
if $MACOS_M1 ; then
481497
execute cmake -DENABLE_TESTS=0 -DCMAKE_INSTALL_PREFIX="${WORKSPACE}" -DCMAKE_INSTALL_LIBDIR=lib -DCONFIG_RUNTIME_CPU_DETECT=0 "$PACKAGES"/av1
482498
else
483499
execute cmake -DENABLE_TESTS=0 -DCMAKE_INSTALL_PREFIX="${WORKSPACE}" -DCMAKE_INSTALL_LIBDIR=lib "$PACKAGES"/av1
484500
fi
485-
## rich (added runtime detect )
486501
execute make -j $MJOBS
487502
execute make install
488503

@@ -680,9 +695,11 @@ execute make install
680695

681696
INSTALL_FOLDER="/usr/bin"
682697
if [[ "$OSTYPE" == "darwin"* ]]; then
683-
INSTALL_FOLDER="/usr/local/bin"
698+
INSTALL_FOLDER="/usr/local/bin"
684699
fi
685700

701+
verify_binary_type
702+
686703
echo ""
687704
echo "Building done. The following binaries can be found here:"
688705
echo "- ffmpeg: $WORKSPACE/bin/ffmpeg"
@@ -710,11 +727,11 @@ elif [[ ! "$SKIPINSTALL" == "yes" ]]; then
710727
if command_exists "sudo"; then
711728
sudo cp "$WORKSPACE/bin/ffmpeg" "$INSTALL_FOLDER/ffmpeg"
712729
sudo cp "$WORKSPACE/bin/ffprobe" "$INSTALL_FOLDER/ffprobe"
713-
sudo cp "$WORKSPACE/bin/ffplay" "$INSTALL_FOLDER/ffplay"
730+
sudo cp "$WORKSPACE/bin/ffplay" "$INSTALL_FOLDER/ffplay"
714731
else
715732
cp "$WORKSPACE/bin/ffmpeg" "$INSTALL_FOLDER/ffmpeg"
716733
cp "$WORKSPACE/bin/ffprobe" "$INSTALL_FOLDER/ffprobe"
717-
cp "$WORKSPACE/bin/ffplay" "$INSTALL_FOLDER/ffplay"
734+
cp "$WORKSPACE/bin/ffplay" "$INSTALL_FOLDER/ffplay"
718735
fi
719736
echo "Done. FFmpeg is now installed to your system."
720737
;;

0 commit comments

Comments
 (0)