Skip to content

Commit cd5c294

Browse files
authored
Merge pull request #71 from rtgoodwin/apple_silicon_plus_x264_commit
Apple silicon plus x264 commit
2 parents e574579 + c5434ee commit cd5c294

File tree

1 file changed

+53
-10
lines changed

1 file changed

+53
-10
lines changed

build-ffmpeg

Lines changed: 53 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,20 @@ VERSION=1.21
88
CWD=$(pwd)
99
PACKAGES="$CWD/packages"
1010
WORKSPACE="$CWD/workspace"
11-
CFLAGS="-I$WORKSPACE/include"
11+
CFLAGS='-I$WORKSPACE/include'
1212
LDFLAGS="-L$WORKSPACE/lib"
1313
LDEXEFLAGS=""
1414
EXTRALIBS="-ldl -lpthread -lm -lz"
15+
MACOS_M1=false
1516
CONFIGURE_OPTIONS=()
17+
# Check for Apple Silicon
18+
if [[ ( "$(uname -m)" == "arm64" ) && ( "$OSTYPE" == "darwin"* ) ]]; then
19+
# If arm64 AND darwin (macOS)
20+
export ARCH=arm64
21+
export MACOSX_DEPLOYMENT_TARGET=11.0
22+
MACOS_M1=true
23+
fi
24+
1625

1726
# Speed up the process
1827
# Env Var NUMJOBS overrides automatic detection
@@ -146,6 +155,19 @@ build_done () {
146155
touch "$PACKAGES/$1.done"
147156
}
148157

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) for ${OSTYPE}: ${BINARY_TYPE}"
164+
;;
165+
*)
166+
echo "Successfully built binary for ${OSTYPE}: ${BINARY_TYPE}"
167+
;;
168+
esac
169+
}
170+
149171
cleanup () {
150172
remove_dir "$PACKAGES"
151173
remove_dir "$WORKSPACE"
@@ -350,11 +372,15 @@ if build "zlib"; then
350372
fi
351373

352374
if build "openssl"; then
353-
download "https://www.openssl.org/source/openssl-1.1.1h.tar.gz"
354-
execute ./config --prefix="${WORKSPACE}" --openssldir="${WORKSPACE}" --with-zlib-include="${WORKSPACE}"/include/ --with-zlib-lib="${WORKSPACE}"/lib no-shared zlib
375+
download "https://www.openssl.org/source/openssl-1.1.1i.tar.gz"
376+
if $MACOS_M1 ; then
377+
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
378+
execute ./configure --prefix="${WORKSPACE}" no-shared no-asm darwin64-arm64-cc
379+
else
380+
execute ./config --prefix="${WORKSPACE}" --openssldir="${WORKSPACE}" --with-zlib-include="${WORKSPACE}"/include/ --with-zlib-lib="${WORKSPACE}"/lib no-shared zlib
381+
fi
355382
execute make -j $MJOBS
356383
execute make install_sw
357-
358384
build_done "openssl"
359385
fi
360386
CONFIGURE_OPTIONS+=("--enable-openssl")
@@ -386,13 +412,16 @@ CONFIGURE_OPTIONS+=("--enable-libsvtav1")
386412
##
387413

388414
if build "x264"; then
389-
download "https://code.videolan.org/videolan/x264/-/archive/stable/x264-stable.tar.bz2"
415+
download "https://code.videolan.org/videolan/x264/-/archive/0d754ec36013fee82978496cd56fbd48824910b3/x264-0d754ec36013fee82978496cd56fbd48824910b3.tar.gz" "x264-0d754ec.tar.gz"
416+
cd "${PACKAGES}"/x264-0d754ec
417+
390418

391419
if [[ "$OSTYPE" == "linux-gnu" ]]; then
392420
execute ./configure --prefix="${WORKSPACE}" --enable-static --enable-pic CXXFLAGS="-fPIC"
393421
else
394422
execute ./configure --prefix="${WORKSPACE}" --enable-static --enable-pic
395423
fi
424+
396425

397426
execute make -j $MJOBS
398427
execute make install
@@ -405,6 +434,7 @@ CONFIGURE_OPTIONS+=("--enable-libx264")
405434
if build "x265"; then
406435
download "https://github.com/videolan/x265/archive/Release_3.5.tar.gz" "x265-3.5.tar.gz"
407436
cd build/linux || exit
437+
408438
execute cmake -DCMAKE_INSTALL_PREFIX="${WORKSPACE}" -DENABLE_SHARED=off -DBUILD_SHARED_LIBS=OFF ../../source
409439
execute make -j $MJOBS
410440
execute make install
@@ -455,6 +485,13 @@ CONFIGURE_OPTIONS+=("--enable-libxvid")
455485

456486
if build "vid_stab"; then
457487
download "https://github.com/georgmartius/vid.stab/archive/v1.1.0.tar.gz" "vid.stab-1.1.0.tar.gz"
488+
489+
if $MACOS_M1 ; then
490+
491+
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
492+
patch -p1 < fix_cmake_quoting.patch
493+
fi
494+
458495
execute cmake -DBUILD_SHARED_LIBS=OFF -DCMAKE_INSTALL_PREFIX="${WORKSPACE}" -DUSE_OMP=OFF -DENABLE_SHARED=off .
459496
execute make
460497
execute make install
@@ -467,7 +504,11 @@ if build "av1"; then
467504
download "https://aomedia.googlesource.com/aom/+archive/b52ee6d44adaef8a08f6984390de050d64df9faa.tar.gz" "av1.tar.gz" "av1"
468505
make_dir "$PACKAGES"/aom_build
469506
cd "$PACKAGES"/aom_build || exit
470-
execute cmake -DENABLE_TESTS=0 -DCMAKE_INSTALL_PREFIX="${WORKSPACE}" -DCMAKE_INSTALL_LIBDIR=lib "$PACKAGES"/av1
507+
if $MACOS_M1 ; then
508+
execute cmake -DENABLE_TESTS=0 -DCMAKE_INSTALL_PREFIX="${WORKSPACE}" -DCMAKE_INSTALL_LIBDIR=lib -DCONFIG_RUNTIME_CPU_DETECT=0 "$PACKAGES"/av1
509+
else
510+
execute cmake -DENABLE_TESTS=0 -DCMAKE_INSTALL_PREFIX="${WORKSPACE}" -DCMAKE_INSTALL_LIBDIR=lib "$PACKAGES"/av1
511+
fi
471512
execute make -j $MJOBS
472513
execute make install
473514

@@ -573,7 +614,7 @@ CONFIGURE_OPTIONS+=("--enable-libwebp")
573614
##
574615

575616
if build "libsdl"; then
576-
download "https://www.libsdl.org/release/SDL2-2.0.12.tar.gz"
617+
download "https://www.libsdl.org/release/SDL2-2.0.14.tar.gz"
577618
execute ./configure --prefix="${WORKSPACE}" --disable-shared --enable-static
578619
execute make -j $MJOBS
579620
execute make install
@@ -665,9 +706,11 @@ execute make install
665706

666707
INSTALL_FOLDER="/usr/bin"
667708
if [[ "$OSTYPE" == "darwin"* ]]; then
668-
INSTALL_FOLDER="/usr/local/bin"
709+
INSTALL_FOLDER="/usr/local/bin"
669710
fi
670711

712+
verify_binary_type
713+
671714
echo ""
672715
echo "Building done. The following binaries can be found here:"
673716
echo "- ffmpeg: $WORKSPACE/bin/ffmpeg"
@@ -695,11 +738,11 @@ elif [[ ! "$SKIPINSTALL" == "yes" ]]; then
695738
if command_exists "sudo"; then
696739
sudo cp "$WORKSPACE/bin/ffmpeg" "$INSTALL_FOLDER/ffmpeg"
697740
sudo cp "$WORKSPACE/bin/ffprobe" "$INSTALL_FOLDER/ffprobe"
698-
sudo cp "$WORKSPACE/bin/ffplay" "$INSTALL_FOLDER/ffplay"
741+
sudo cp "$WORKSPACE/bin/ffplay" "$INSTALL_FOLDER/ffplay"
699742
else
700743
cp "$WORKSPACE/bin/ffmpeg" "$INSTALL_FOLDER/ffmpeg"
701744
cp "$WORKSPACE/bin/ffprobe" "$INSTALL_FOLDER/ffprobe"
702-
cp "$WORKSPACE/bin/ffplay" "$INSTALL_FOLDER/ffplay"
745+
cp "$WORKSPACE/bin/ffplay" "$INSTALL_FOLDER/ffplay"
703746
fi
704747
echo "Done. FFmpeg is now installed to your system."
705748
;;

0 commit comments

Comments
 (0)