Vargol / ffmpeg-apple-arm64-build

Build script for ffmpeg targeting the latest open source video codecs running on macOS using Apple's M1 processor.
221 stars 38 forks source link

fontconfig fails on undefined brotli symbols #30

Closed aikinai closed 2 months ago

aikinai commented 2 months ago

First of all, thanks for the great script! Back when I first discovered this I spent a long time trying to find the best way to build a feature-complete and Apple Silicon-optimized ffmpeg, so I was super happy to finally come across your script!

It worked great the first time—I think sometime last year—but now I'm getting some build issues. First brotli wasn't building, but I downloaded the patched script from another issue and got past that. Is there a reason that's not committed to main, by the way?

Now that I'm past brotli, I'm running into this brotli-related error in fontconfig. Any idea what's causing this?

  CCLD     fc-cache
ld: Undefined symbols:
  _BrotliDefaultAllocFunc, referenced from:
      _BrotliDecoderStateInit in libbrotlidec.a[5](state.c.o)
  _BrotliDefaultFreeFunc, referenced from:
      _BrotliDecoderStateInit in libbrotlidec.a[5](state.c.o)
  _BrotliSharedDictionaryAttach, referenced from:
      _BrotliDecoderAttachDictionary in libbrotlidec.a[3](decode.c.o)
  _BrotliSharedDictionaryCreateInstance, referenced from:
      _BrotliDecoderStateInit in libbrotlidec.a[5](state.c.o)
  _BrotliSharedDictionaryDestroyInstance, referenced from:
      _BrotliDecoderStateCleanup in libbrotlidec.a[5](state.c.o)
  _BrotliTransformDictionaryWord, referenced from:
      _ProcessCommands in libbrotlidec.a[3](decode.c.o)
      _SafeProcessCommands in libbrotlidec.a[3](decode.c.o)
  __kBrotliContextLookupTable, referenced from:
      _BrotliDecoderDecompressStream in libbrotlidec.a[3](decode.c.o)
      _SafeDecodeLiteralBlockSwitch in libbrotlidec.a[3](decode.c.o)
      _DecodeLiteralBlockSwitch in libbrotlidec.a[3](decode.c.o)
  __kBrotliPrefixCodeRanges, referenced from:
      _BrotliDecoderDecompressStream in libbrotlidec.a[3](decode.c.o)
      _SafeDecodeCommandBlockSwitch in libbrotlidec.a[3](decode.c.o)
      _DecodeCommandBlockSwitch in libbrotlidec.a[3](decode.c.o)
      _SafeDecodeDistanceBlockSwitch in libbrotlidec.a[3](decode.c.o)
      _DecodeDistanceBlockSwitch in libbrotlidec.a[3](decode.c.o)
      _SafeDecodeLiteralBlockSwitch in libbrotlidec.a[3](decode.c.o)
      _DecodeLiteralBlockSwitch in libbrotlidec.a[3](decode.c.o)
      ...
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make[2]: *** [fc-cache] Error 1
make[1]: *** [all-recursive] Error 1                                            make: *** [all] Error 2                                                         check failed: build of fontconfig-2.15.0 failed
Vargol commented 2 months ago

HI If the patch was the ""they're trying to install the man stuff into system man directories" patch, that was committed, then Brotli broke it again but provided a way to set where to install the man pages, so my script was changed to use that instead of the patch. Seems strange that you need it, how did you get my script, the releases page or a git clone, or the 'Code' button download option.

I'm running a full rebuild to see if I get the same error, my last re-run was May 1st which was fine.

EDIT The fresh build completed successfully for me.

compile brotli
took 5s
...
compile fontconfig
took 16s
...
compile ffmpeg
took 174s
compilation finished successfully
took 889s

bundle result
  adding: ffmpeg (deflated 58%)
  adding: ffprobe (deflated 58%)

run tests
tests executed successfully

Error wise, brotli frequently move stuff around between decoder and common libraries, it's a pain to keep up with. make sure the tool/lib/pkgconfig/libbrotlidec.pc has references to libbrotlicommon in them

Libs: -L${libdir} -lbrotlidec -lbrotlicommon
Requires.private: libbrotlicommon >= 1.1.0
Vargol commented 2 months ago

BTW I guess I should point out this script is close to being obsolete, as all the bits needed are now in the release versions of the libraries. There's pretty much just the handbrake threading patch, I've no idea if that actually makes a differences though as I'm on a base M3 and thats targeting the Max/Pro/Ultra variations of the M series.

aikinai commented 2 months ago

Thanks for the super quick response! I used git clone to get the script. Here's exactly what I'm running:

diskutil erasevolume APFS 'RAMdisk' `hdiutil attach -nobrowse -nomount ram://8388608` #4GB
cd /Volumes/RAMdisk
git clone https://github.com/Vargol/ffmpeg-apple-arm64-build.git
cd ffmpeg-apple-arm64-build
./build.sh
sudo rsync -vaX /Volumes/RAMdisk/ffmpeg-apple-arm64-build/out/* /usr/local/

And here is the patch I got for brotli

diff --git a/build/build-brotli.sh b/build/build-brotli.sh
index c52f350..d7de60f 100755
--- a/build/build-brotli.sh
+++ b/build/build-brotli.sh
@@ -40,6 +40,8 @@ configure_build () {

   cd "$2/${SOFTWARE}/${SOFTWARE}/"
   checkStatus $? "change directory failed"
+#  git apply $1/brotli_man_fix.patch
+#  checkStatus $? "git apply patch failed"

   cd "$2/${SOFTWARE}/build-${SOFTWARE}/"
   checkStatus $? "change directory failed"
@@ -71,9 +73,6 @@ make_compile () {
   # install
   make install
   checkStatus $? "installation of ${SOFTWARE} failed"
-
-  #fix up the pkgconfig.
-  sed -i '' "s/lbrotlidec$/lbrotlidec -lbrotlicommon/" $3/lib/pkgconfig/libbrotlidec.pc

 }

There's pretty much just the handbrake threading patch, I've no idea if that actually makes a differences though as I'm on a base M3 and thats targeting the Max/Pro/Ultra variations of the M series.

That's the libx265 patch right? It made a huge difference for me on my M1 Max. That's how I originally found my way to your script. But if everything except that is in release versions, maybe I could just use Homebrew builds of everything and manually build libx265 with that patch and then ffmpeg.

aikinai commented 2 months ago

make sure the tool/lib/pkgconfig/libbrotlidec.pc has references to libbrotlicommon in them

This was it! I just added -lbrotlicommon and it fontconfig works now. 👍🏻

But now libbluray is getting this error:

  CCLD     sound_dump
 /opt/homebrew/opt/coreutils/libexec/gnubin/mkdir -p '/Volumes/RAMdisk/ffmpeg-apple-arm64-build/tool/lib'
 /bin/sh ./libtool   --mode=install /opt/homebrew/opt/coreutils/libexec/gnubin/install -c   libbluray.la '/Volumes/RAMdisk/ffmpeg-apple-arm64-build/tool/lib'
libtool: install: /opt/homebrew/opt/coreutils/libexec/gnubin/install -c .libs/libbluray.lai /Volumes/RAMdisk/ffmpeg-apple-arm64-build/tool/lib/libbluray.la
libtool: install: /opt/homebrew/opt/coreutils/libexec/gnubin/install -c .libs/libbluray.a /Volumes/RAMdisk/ffmpeg-apple-arm64-build/tool/lib/libbluray.a
libtool: install: chmod 644 /Volumes/RAMdisk/ffmpeg-apple-arm64-build/tool/lib/libbluray.a
libtool: install: ranlib /Volumes/RAMdisk/ffmpeg-apple-arm64-build/tool/lib/libbluray.a
 /opt/homebrew/opt/coreutils/libexec/gnubin/mkdir -p '/Volumes/RAMdisk/ffmpeg-apple-arm64-build/tool/bin'
  /bin/sh ./libtool   --mode=install /opt/homebrew/opt/coreutils/libexec/gnubin/install -c bd_list_titles bd_splice bd_info '/Volumes/RAMdisk/ffmpeg-apple-arm64-build/tool/bin'
libtool: install: /opt/homebrew/opt/coreutils/libexec/gnubin/install -c bd_list_titles /Volumes/RAMdisk/ffmpeg-apple-arm64-build/tool/bin/bd_list_titles        libtool: install: /opt/homebrew/opt/coreutils/libexec/gnubin/install -c bd_splice /Volumes/RAMdisk/ffmpeg-apple-arm64-build/tool/bin/bd_splice
libtool: install: /opt/homebrew/opt/coreutils/libexec/gnubin/install -c bd_info /Volumes/RAMdisk/ffmpeg-apple-arm64-build/tool/bin/bd_info
 /opt/homebrew/opt/coreutils/libexec/gnubin/mkdir -p '/Volumes/RAMdisk/ffmpeg-apple-arm64-build/tool/lib/pkgconfig'
 /opt/homebrew/opt/coreutils/libexec/gnubin/install -c -m 644 src/libbluray.pc '/Volumes/RAMdisk/ffmpeg-apple-arm64-build/tool/lib/pkgconfig'
 /opt/homebrew/opt/coreutils/libexec/gnubin/mkdir -p '/Volumes/RAMdisk/ffmpeg-apple-arm64-build/tool/include/libbluray'
 /opt/homebrew/opt/coreutils/libexec/gnubin/install -c -m 644 ../libbluray-1.3.4/src/file/filesystem.h ../libbluray-1.3.4/src/libbluray/bluray.h src/libbluray/bluray-version.h ../libbluray-1.3.4/src/libbluray/keys.h ../libbluray-1.3.4/src/libbluray/player_settings.h ../libbluray-1.3.4/src/libbluray/bdnav/clpi_data.h ../libbluray-1.3.4/src/libbluray/bdnav/meta_data.h ../libbluray-1.3.4/src/libbluray/decoders/overlay.h ../libbluray-1.3.4/src/util/log_control.h '/Volumes/RAMdisk/ffmpeg-apple-arm64-build/tool/include/libbluray'                               sed: can't read s/libxml-2.0 >= 2.6//: No such file or directory
sed: can't read s/lbluray/lbluray -lxml2/: No such file or directory
Vargol commented 2 months ago

That interesting the brotlicommon thing should get done in the build-brotli.sh script as a sed, and now there's a sed failing here too, and they are both pkgconfig scripts too.

I wonder if the way I'm using sed doesn't work with hombrew's sed (I'm guessing homebrew's sed is being used as all the other bits are homebrews in your output ), the script is built around the tools installed by Apple.

build-libbluray.sh has these lines

  sed -i '' "s/libxml-2.0 >= 2.6//" $3/lib/pkgconfig/libbluray.pc
  sed -i '' "s/lbluray/lbluray -lxml2/" $3/lib/pkgconfig/libbluray.pc

try changing them to use /usr/bin/sed

  /usr/bin/sed -i '' "s/libxml-2.0 >= 2.6//" $3/lib/pkgconfig/libbluray.pc
  /usr/bin/sed -i '' "s/lbluray/lbluray -lxml2/" $3/lib/pkgconfig/libbluray.pc
aikinai commented 2 months ago

Oh, gnu sed is what was causing all of my issues! I removed it from my PATH and started everything from scratch. All goes well now except that I run into this issue with a duplicate symbol from libbluray. I don't really need libbluray anyway, so I disabled it and everything compiled fine again.

Thanks for the help!