@@ -8,11 +8,20 @@ VERSION=1.21
88CWD=$( pwd)
99PACKAGES=" $CWD /packages"
1010WORKSPACE=" $CWD /workspace"
11- CFLAGS=" -I$WORKSPACE /include"
11+ CFLAGS=' -I$WORKSPACE/include'
1212LDFLAGS=" -L$WORKSPACE /lib"
1313LDEXEFLAGS=" "
1414EXTRALIBS=" -ldl -lpthread -lm -lz"
15+ MACOS_M1=false
1516CONFIGURE_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+
149171cleanup () {
150172 remove_dir " $PACKAGES "
151173 remove_dir " $WORKSPACE "
@@ -350,11 +372,15 @@ if build "zlib"; then
350372fi
351373
352374if 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"
359385fi
360386CONFIGURE_OPTIONS+=(" --enable-openssl" )
@@ -386,13 +412,16 @@ CONFIGURE_OPTIONS+=("--enable-libsvtav1")
386412# #
387413
388414if 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")
405434if 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
456486if 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
575616if 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
666707INSTALL_FOLDER=" /usr/bin"
667708if [[ " $OSTYPE " == " darwin" * ]]; then
668- INSTALL_FOLDER=" /usr/local/bin"
709+ INSTALL_FOLDER=" /usr/local/bin"
669710fi
670711
712+ verify_binary_type
713+
671714echo " "
672715echo " Building done. The following binaries can be found here:"
673716echo " - 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