Skip to content

Commit 11ffcd6

Browse files
authored
Random patches and tricks for building on M1
Needs newer code in some cases, and some conditionals to check platform. The external patches possibly should be brought in? Seems to work for now if anyone is in need. Learnings from https://github.com/ssut/ffmpeg-on-apple-silicon
1 parent ea460e0 commit 11ffcd6

File tree

1 file changed

+35
-7
lines changed

1 file changed

+35
-7
lines changed

build-ffmpeg

Lines changed: 35 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,18 @@ 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"
1515
CONFIGURE_OPTIONS=()
16+
# Check for Apple Silicon
17+
if [[ ( "$(uname -m)" == "arm64" ) && ( "$OSTYPE" == "darwin"* ) ]]; then
18+
# If arm64 AND darwin (macOS)
19+
export ARCH=arm64
20+
export MACOSX_DEPLOYMENT_TARGET=11.0
21+
fi
22+
1623

1724
# Speed up the process
1825
# Env Var NUMJOBS overrides automatic detection
@@ -350,11 +357,15 @@ if build "zlib"; then
350357
fi
351358

352359
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
360+
download "https://www.openssl.org/source/openssl-1.1.1i.tar.gz"
361+
if [[ ( "$ARCH" == "arm64" ) && ( "$OSTYPE" == "darwin"* ) ]]; then
362+
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
364+
else
365+
execute ./config --prefix="${WORKSPACE}" --openssldir="${WORKSPACE}" --with-zlib-include="${WORKSPACE}"/include/ --with-zlib-lib="${WORKSPACE}"/lib no-shared zlib
366+
fi
355367
execute make -j $MJOBS
356368
execute make install_sw
357-
358369
build_done "openssl"
359370
fi
360371
CONFIGURE_OPTIONS+=("--enable-openssl")
@@ -377,7 +388,11 @@ if build "x264"; then
377388

378389
if [[ "$OSTYPE" == "linux-gnu" ]]; then
379390
execute ./configure --prefix="${WORKSPACE}" --enable-static --enable-pic CXXFLAGS="-fPIC"
380-
else
391+
elif [[ ( "$ARCH" == "arm64" ) && ( "$OSTYPE" == "darwin"* ) ]]; then
392+
## 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
381396
execute ./configure --prefix="${WORKSPACE}" --enable-static --enable-pic
382397
fi
383398

@@ -392,6 +407,7 @@ CONFIGURE_OPTIONS+=("--enable-libx264")
392407
if build "x265"; then
393408
download "https://github.com/videolan/x265/archive/Release_3.5.tar.gz" "x265-3.5.tar.gz"
394409
cd build/linux || exit
410+
395411
execute cmake -DCMAKE_INSTALL_PREFIX="${WORKSPACE}" -DENABLE_SHARED=off -DBUILD_SHARED_LIBS=OFF ../../source
396412
execute make -j $MJOBS
397413
execute make install
@@ -442,6 +458,12 @@ CONFIGURE_OPTIONS+=("--enable-libxvid")
442458

443459
if build "vid_stab"; then
444460
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
464+
patch -p1 < fix_cmake_quoting.patch
465+
fi
466+
## rich
445467
execute cmake -DBUILD_SHARED_LIBS=OFF -DCMAKE_INSTALL_PREFIX="${WORKSPACE}" -DUSE_OMP=OFF -DENABLE_SHARED=off .
446468
execute make
447469
execute make install
@@ -454,7 +476,13 @@ if build "av1"; then
454476
download "https://aomedia.googlesource.com/aom/+archive/b52ee6d44adaef8a08f6984390de050d64df9faa.tar.gz" "av1.tar.gz" "av1"
455477
make_dir "$PACKAGES"/aom_build
456478
cd "$PACKAGES"/aom_build || exit
457-
execute cmake -DENABLE_TESTS=0 -DCMAKE_INSTALL_PREFIX="${WORKSPACE}" -DCMAKE_INSTALL_LIBDIR=lib "$PACKAGES"/av1
479+
## rich
480+
if [[ ( "$ARCH" == "arm64" ) && ( "$OSTYPE" == "darwin"* ) ]]; then
481+
execute cmake -DENABLE_TESTS=0 -DCMAKE_INSTALL_PREFIX="${WORKSPACE}" -DCMAKE_INSTALL_LIBDIR=lib -DCONFIG_RUNTIME_CPU_DETECT=0 "$PACKAGES"/av1
482+
else
483+
execute cmake -DENABLE_TESTS=0 -DCMAKE_INSTALL_PREFIX="${WORKSPACE}" -DCMAKE_INSTALL_LIBDIR=lib "$PACKAGES"/av1
484+
fi
485+
## rich (added runtime detect )
458486
execute make -j $MJOBS
459487
execute make install
460488

@@ -560,7 +588,7 @@ CONFIGURE_OPTIONS+=("--enable-libwebp")
560588
##
561589

562590
if build "libsdl"; then
563-
download "https://www.libsdl.org/release/SDL2-2.0.12.tar.gz"
591+
download "https://www.libsdl.org/release/SDL2-2.0.14.tar.gz"
564592
execute ./configure --prefix="${WORKSPACE}" --disable-shared --enable-static
565593
execute make -j $MJOBS
566594
execute make install

0 commit comments

Comments
 (0)