Skip to content

Commit

Permalink
Merge pull request #71 from rtgoodwin/apple_silicon_plus_x264_commit
Browse files Browse the repository at this point in the history
Apple silicon plus x264 commit
  • Loading branch information
markus-perl authored Jan 20, 2021
2 parents e574579 + c5434ee commit cd5c294
Showing 1 changed file with 53 additions and 10 deletions.
63 changes: 53 additions & 10 deletions build-ffmpeg
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,20 @@ VERSION=1.21
CWD=$(pwd)
PACKAGES="$CWD/packages"
WORKSPACE="$CWD/workspace"
CFLAGS="-I$WORKSPACE/include"
CFLAGS='-I$WORKSPACE/include'
LDFLAGS="-L$WORKSPACE/lib"
LDEXEFLAGS=""
EXTRALIBS="-ldl -lpthread -lm -lz"
MACOS_M1=false
CONFIGURE_OPTIONS=()
# Check for Apple Silicon
if [[ ( "$(uname -m)" == "arm64" ) && ( "$OSTYPE" == "darwin"* ) ]]; then
# If arm64 AND darwin (macOS)
export ARCH=arm64
export MACOSX_DEPLOYMENT_TARGET=11.0
MACOS_M1=true
fi


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

verify_binary_type () {
BINARY_TYPE=$(file $WORKSPACE/bin/ffmpeg | sed -n 's/^.*\:\ \(.*$\)/\1/p')
echo ""
case $BINARY_TYPE in
"Mach-O 64-bit executable arm64")
echo "Successfully built Apple Silicon (M1) for ${OSTYPE}: ${BINARY_TYPE}"
;;
*)
echo "Successfully built binary for ${OSTYPE}: ${BINARY_TYPE}"
;;
esac
}

cleanup () {
remove_dir "$PACKAGES"
remove_dir "$WORKSPACE"
Expand Down Expand Up @@ -350,11 +372,15 @@ if build "zlib"; then
fi

if build "openssl"; then
download "https://www.openssl.org/source/openssl-1.1.1h.tar.gz"
execute ./config --prefix="${WORKSPACE}" --openssldir="${WORKSPACE}" --with-zlib-include="${WORKSPACE}"/include/ --with-zlib-lib="${WORKSPACE}"/lib no-shared zlib
download "https://www.openssl.org/source/openssl-1.1.1i.tar.gz"
if $MACOS_M1 ; then
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
execute ./configure --prefix="${WORKSPACE}" no-shared no-asm darwin64-arm64-cc
else
execute ./config --prefix="${WORKSPACE}" --openssldir="${WORKSPACE}" --with-zlib-include="${WORKSPACE}"/include/ --with-zlib-lib="${WORKSPACE}"/lib no-shared zlib
fi
execute make -j $MJOBS
execute make install_sw

build_done "openssl"
fi
CONFIGURE_OPTIONS+=("--enable-openssl")
Expand Down Expand Up @@ -386,13 +412,16 @@ CONFIGURE_OPTIONS+=("--enable-libsvtav1")
##

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


if [[ "$OSTYPE" == "linux-gnu" ]]; then
execute ./configure --prefix="${WORKSPACE}" --enable-static --enable-pic CXXFLAGS="-fPIC"
else
execute ./configure --prefix="${WORKSPACE}" --enable-static --enable-pic
fi


execute make -j $MJOBS
execute make install
Expand All @@ -405,6 +434,7 @@ CONFIGURE_OPTIONS+=("--enable-libx264")
if build "x265"; then
download "https://github.com/videolan/x265/archive/Release_3.5.tar.gz" "x265-3.5.tar.gz"
cd build/linux || exit

execute cmake -DCMAKE_INSTALL_PREFIX="${WORKSPACE}" -DENABLE_SHARED=off -DBUILD_SHARED_LIBS=OFF ../../source
execute make -j $MJOBS
execute make install
Expand Down Expand Up @@ -455,6 +485,13 @@ CONFIGURE_OPTIONS+=("--enable-libxvid")

if build "vid_stab"; then
download "https://github.com/georgmartius/vid.stab/archive/v1.1.0.tar.gz" "vid.stab-1.1.0.tar.gz"

if $MACOS_M1 ; then

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
patch -p1 < fix_cmake_quoting.patch
fi

execute cmake -DBUILD_SHARED_LIBS=OFF -DCMAKE_INSTALL_PREFIX="${WORKSPACE}" -DUSE_OMP=OFF -DENABLE_SHARED=off .
execute make
execute make install
Expand All @@ -467,7 +504,11 @@ if build "av1"; then
download "https://aomedia.googlesource.com/aom/+archive/b52ee6d44adaef8a08f6984390de050d64df9faa.tar.gz" "av1.tar.gz" "av1"
make_dir "$PACKAGES"/aom_build
cd "$PACKAGES"/aom_build || exit
execute cmake -DENABLE_TESTS=0 -DCMAKE_INSTALL_PREFIX="${WORKSPACE}" -DCMAKE_INSTALL_LIBDIR=lib "$PACKAGES"/av1
if $MACOS_M1 ; then
execute cmake -DENABLE_TESTS=0 -DCMAKE_INSTALL_PREFIX="${WORKSPACE}" -DCMAKE_INSTALL_LIBDIR=lib -DCONFIG_RUNTIME_CPU_DETECT=0 "$PACKAGES"/av1
else
execute cmake -DENABLE_TESTS=0 -DCMAKE_INSTALL_PREFIX="${WORKSPACE}" -DCMAKE_INSTALL_LIBDIR=lib "$PACKAGES"/av1
fi
execute make -j $MJOBS
execute make install

Expand Down Expand Up @@ -573,7 +614,7 @@ CONFIGURE_OPTIONS+=("--enable-libwebp")
##

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

INSTALL_FOLDER="/usr/bin"
if [[ "$OSTYPE" == "darwin"* ]]; then
INSTALL_FOLDER="/usr/local/bin"
INSTALL_FOLDER="/usr/local/bin"
fi

verify_binary_type

echo ""
echo "Building done. The following binaries can be found here:"
echo "- ffmpeg: $WORKSPACE/bin/ffmpeg"
Expand Down Expand Up @@ -695,11 +738,11 @@ elif [[ ! "$SKIPINSTALL" == "yes" ]]; then
if command_exists "sudo"; then
sudo cp "$WORKSPACE/bin/ffmpeg" "$INSTALL_FOLDER/ffmpeg"
sudo cp "$WORKSPACE/bin/ffprobe" "$INSTALL_FOLDER/ffprobe"
sudo cp "$WORKSPACE/bin/ffplay" "$INSTALL_FOLDER/ffplay"
sudo cp "$WORKSPACE/bin/ffplay" "$INSTALL_FOLDER/ffplay"
else
cp "$WORKSPACE/bin/ffmpeg" "$INSTALL_FOLDER/ffmpeg"
cp "$WORKSPACE/bin/ffprobe" "$INSTALL_FOLDER/ffprobe"
cp "$WORKSPACE/bin/ffplay" "$INSTALL_FOLDER/ffplay"
cp "$WORKSPACE/bin/ffplay" "$INSTALL_FOLDER/ffplay"
fi
echo "Done. FFmpeg is now installed to your system."
;;
Expand Down

0 comments on commit cd5c294

Please sign in to comment.