mpv-player / mpv

🎥 Command line video player
https://mpv.io
Other
27.84k stars 2.87k forks source link

Build of standalone Mac app bundle fails #11897

Closed ElhemEnohpi closed 10 months ago

ElhemEnohpi commented 1 year ago

Important Information

Provide following Information:

Reproduction steps

I'm trying to get a static/standalone mpv app for Apple Silicon. I followed some instructions here: How to build mpv & mpv.app on an Apple silicon (M1 / M2) Mac

But the build fails, with missing lib files, when trying to build it standalone. It looks like a problem with the osxbundle.py or dylib-unhell.py scripts, but I don't really know... sorry if it has to do with Homebrew or something instead.

brew install --only-dependencies mpv
brew install meson
git clone https://github.com/mpv-player/mpv #(or download 0.35.1 release source)
cd mpv
meson setup build
meson compile -C build
./TOOLS/osxbundle.py build/mpv

Expected behavior

mpv and a standalone app bundle are built.

Actual behavior

A working cli mpv is built. A working app bundle can be built with ./TOOLS/osxbundle.py --skip-deps build/mpv, but trying to bundle the dependencies with ./TOOLS/osxbundle.py build/mpv fails. First, an error about missing libbrotlicommon, described in #10063, which is fixed with this:

install_name_tool -change "@loader_path/libbrotlicommon.1.dylib" "$(brew --prefix)/lib/libbrotlicommon.1.dylib" "$(brew --prefix)/lib/libbrotlidec.1.dylib"  
codesign --force -s - "$(brew --prefix)/lib/libbrotlidec.1.dylib"  
install_name_tool -change "@loader_path/libbrotlicommon.1.dylib" "$(brew --prefix)/lib/libbrotlicommon.1.dylib" "$(brew --prefix)/lib/libbrotlienc.1.dylib"  
codesign --force -s - "$(brew --prefix)/lib/libbrotlienc.1.dylib"

After that, an error about missing libwebp.7.dylib and libsharpyuv.0.dylib, which I don't know how to fix. The app bundle fails to launch.

If there's any other way to build or obtain a standalone app for Apple Silicon, please let me know. The links in https://mpv.io/installation/ don't provide it. It would be great if there were working instructions or helper scripts to build it from source.

Log file

+ ./build/mpv --version
mpv 0.35.0-505-g2da0c0b33f Copyright © 2000-2023 mpv/MPlayer/mplayer2 projects
 built on Fri Jul 07 12:17:32 2023
FFmpeg version: 6.0
FFmpeg library versions:
   libavutil       58.2.100
   libavcodec      60.3.100
   libavformat     60.3.100
   libswscale      7.1.100
   libavfilter     9.3.100
   libswresample   4.10.100

+ ./TOOLS/osxbundle.py build/mpv
Creating Mac OS X application bundle (version: 0.35.0-UNKNOWN)...
> copying bundle skeleton
> copying binary
> create bundle symlink
> generating Info.plist
> bundling dependencies
error: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/otool-classic: can't open file: @rpath/libsharpyuv.0.dylib (No such file or directory)
error: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/otool-classic: can't open file: @rpath/libwebp.7.dylib (No such file or directory)
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/install_name_tool: warning: changes being made to the file will invalidate the code signature in: /Users/elhem/mpv/build/mpv.app/Contents/MacOS/lib/libavfilter.9.dylib
[ ...then a hundred or so repetitions of the above line, for each lib... ]
Traceback (most recent call last):
  File "/Users/elhem/mpv/TOOLS/dylib-unhell.py", line 130, in <module>
    main()
  File "/Users/elhem/mpv/TOOLS/dylib-unhell.py", line 121, in main
    process_libraries(libs, binary)
  File "/Users/elhem/mpv/TOOLS/dylib-unhell.py", line 80, in process_libraries
    shutil.copy(src, dst)
  File "/opt/homebrew/Cellar/python@3.11/3.11.4_1/Frameworks/Python.framework/Versions/3.11/lib/python3.11/shutil.py", line 419, in copy
    copyfile(src, dst, follow_symlinks=follow_symlinks)
  File "/opt/homebrew/Cellar/python@3.11/3.11.4_1/Frameworks/Python.framework/Versions/3.11/lib/python3.11/shutil.py", line 256, in copyfile
    with open(src, 'rb') as fsrc:
         ^^^^^^^^^^^^^^^
FileNotFoundError: [Errno 2] No such file or directory: '@rpath/libwebp.7.dylib'
>> gathering all linked libraries
>> copying and processing all linked libraries
done.
Akemi commented 1 year ago

you need to roughly do this: https://github.com/mpv-player/mpv/issues/10387#issuecomment-1180578175

the bundle script is not able to resolve the dependencies in those cases and wasn't meant to.

xfangfang commented 1 year ago

@ElhemEnohpi I have also tried to package the dependencies of MPV into an app, and I borrowed from iina's script to reduce the dependency according to my needs, and used dylibbundler for packaging.

I hope it will be helpful to you.

ElhemEnohpi commented 1 year ago

@Akemi thanks for your help, I'm now able to get the standalone app built. I used otool -L to search all the dylibs in $(brew --prefix)/lib and found the libs that were referencing the missing ones. The following fixes it:

install_name_tool -change "@rpath/libsharpyuv.0.dylib" "$(brew --prefix)/lib/libsharpyuv.0.dylib" "$(brew --prefix)/lib/libwebp.7.dylib"  
codesign --force -s - "$(brew --prefix)/lib/libwebp.7.dylib"  
install_name_tool -change "@rpath/libwebp.7.dylib" "$(brew --prefix)/lib/libwebp.7.dylib" "$(brew --prefix)/lib/libwebpdemux.2.dylib"
install_name_tool -change "@rpath/libsharpyuv.0.dylib" "$(brew --prefix)/lib/libsharpyuv.0.dylib" "$(brew --prefix)/lib/libwebpdemux.2.dylib"
codesign --force -s - "$(brew --prefix)/lib/libwebpdemux.2.dylib"
install_name_tool -change "@rpath/libwebp.7.dylib" "$(brew --prefix)/lib/libwebp.7.dylib" "$(brew --prefix)/lib/libwebpmux.3.dylib"
install_name_tool -change "@rpath/libsharpyuv.0.dylib" "$(brew --prefix)/lib/libsharpyuv.0.dylib" "$(brew --prefix)/lib/libwebpmux.3.dylib"
codesign --force -s - "$(brew --prefix)/lib/libwebpmux.3.dylib"

I also disabled vapoursynth in meson_options.txt, because it was failing on looking for Python. Then I had to do this, as noted in Compiling distro releases for macOS · mpv-player/mpv Wiki

rm build/mpv.app/Contents/MacOS/mpv-bundle
mv build/mpv.app/Contents/MacOS/mpv build/mpv.app/Contents/MacOS/mpv-bundle
ln -s mpv-bundle build/mpv.app/Contents/MacOS/mpv
codesign --force --deep -s - build/mpv.app

Hopefully someone will start distributing a Universal Binary mpv app one of these days, but this is good enough for my purposes at the moment. I did find some info in issue #8533, and these scripts, but I didn't try it:

SubstituteR/mpv-build-scripts: A couple of scripts I use to build a Universal Big Sur binary for mpv.

@xfangfang it turned out to be a bit simpler to do it the above way, but thanks for the suggestion.

eko5624 commented 1 year ago

@ElhemEnohpi Can you try this bundle.sh script ?

  1. Put bundle.sh into the parent directory of mpv source code.
  2. After compiling mpv, then run bundle.sh.

https://github.com/eko5624/mpv-macos-intel/blob/main/bundle.sh

ElhemEnohpi commented 1 year ago

@eko5624 Why? In any case, sorry, no. I'm sure it's a good script, but I'm not familiar enough with what it's doing, there are many 'sudo' commands, no documentation, and I don't have time to figure it out myself. Whatever it is, it's not building a Universal Binary, so I don't have a need for it at the moment. I was able to compile using the standard mpv osxbundle.py script.

eko5624 commented 1 year ago

@ElhemEnohpi Ok then. You can remove 'sudo'. I use 'sudo' because github actions need it. This script is using for making bundle. I don't have an Apple silicon (M1 / M2) laptop, so I don't know how to build Universal Binary, sorry.