Skip to content

Instantly share code, notes, and snippets.

@dbrookman
Last active November 26, 2024 19:42
Show Gist options
  • Save dbrookman/74b8bcfb37a23452f7137b83bca9580f to your computer and use it in GitHub Desktop.
Save dbrookman/74b8bcfb37a23452f7137b83bca9580f to your computer and use it in GitHub Desktop.
How to build mpv & mpv.app on an Apple silicon Mac

Preparations

Before you can build mpv & mpv.app on an Apple silicon Mac, there's a couple of required dependencies you'll need to install if you haven't already:

  1. Go to System Preferences > Software Update. If there's anything there to update, do it.

  2. If you don't have the Xcode Command Line Tools installed, run xcode-select --install and select Install on the prompt that appears.

  3. If you don't have Homebrew installed, follow the instructions here.

  4. If you don't have all of mpv's dependencies installed, run brew install --build-from-source --only-dependencies mpv && brew install libplacebo.

You'll also need a local copy of the mpv repo, which you can get by running git clone https://github.com/mpv-player/mpv.

You can now run the attached script to build mpv & mpv.app on an Apple silicon Mac yourself. Just make sure to run it from the root directory of the cloned repo.

Static Build

If you want to bundle a static build of mpv.app, perform these steps following the ones above.

  1. Run brew install dylibbundler.

  2. Run the script from the root directory of the cloned repo, but append --static to the command, like ./build-mpv_silicon.sh --static.


Updating

Going forward, you can update your local copy of the repo by running the following commands from its root directory:

git reset --hard
git clean --force -d -x
git pull origin master
#!/usr/bin/env bash
# Builds mpv & mpv.app on Apple silicon Macs.
# Run this script from the root directory of the mpv repo.
# if anything fails, gtfo
set -ex
meson setup build
meson compile -C build
# test the binary we just built
./build/mpv --version
./TOOLS/osxbundle.py --skip-deps build/mpv
if [[ $1 == "--static" ]]; then
dylibbundler --bundle-deps --dest-dir build/mpv.app/Contents/MacOS/lib/ --install-path @executable_path/lib/ --fix-file build/mpv.app/Contents/MacOS/mpv
# test the app binary to make sure all the dylibs made it okay
./build/mpv.app/Contents/MacOS/mpv --version
fi
@sandlst
Copy link

sandlst commented Nov 18, 2023

building log
I'm successed build on sonoma 14.0 , but failed on sonoma 14.1

I'm having this too; related bug: mpv-player/mpv#12673

This build guide works and uses non-homebrew versions of a lot of deps; it makes me wonder if there is a bug in one of the homebrew Vulkan packages or possibly pkgconf.

In case anyone else is having the same issue:
/opt/homebrew/Cellar/libplacebo/6.338.1_1/include/libplacebo/vulkan.h:21:10: fatal error: 'vulkan/vulkan.h' file not found
when trying to build; I think messing around with the Vulkan-SDK installer and then trying to go back to homebrew's vulkan/libplacebo was the cause of it for me. After completely removing the vulkan-sdk and forcing brew to reinstall libplacebo, vulkan-headers, and vulkan-loader I was able to build mpv again. Even after removing the SDK it was still giving me that error until I force reinstalled those homebrew packages....I reinstalled all of them at once so I'm not sure which one(s) were responsible.

@Akczht
Copy link

Akczht commented Nov 18, 2023

I recently was able to build a standalone mpv app, without any errors after the latest commit bringing support hw decoding of libplacebo with videotoolbox, all I did was install molten-vk and libplacebo I got no errors.

@PsyPryss
Copy link

/!\ WARNING : can't get path for '@rpath/libspirv-cross-c-shared.0.dylib'
What other dependencies am I missing. I'm trying to compile a static build.

@temberature
Copy link

The Absolute Beginner's Guide to Installing and Using Meson
https://mesonbuild.com/SimpleStart.html

@miku1958
Copy link

FYI, If you want to enable gpu-next, you have to install the Vulkan SDK https://sdk.lunarg.com/sdk/download/latest/mac/vulkan-sdk.dmg

@ElhemEnohpi
Copy link

ElhemEnohpi commented Mar 20, 2024

@miku1958 Yes, it's nice having gpu-next, now I can watch Dolby Vision videos with mpv!

But you don't have to install the whole Vulkan SDK, which is relatively large. You only need the MoltenVK runtime. As noted in the third comment above yours, it can be installed easily from Homebrew. Just do:

brew install molten-vk

Maybe it can be added to the script...

@miku1958
Copy link

@ElhemEnohpi Got it thanks

@tano70
Copy link

tano70 commented Apr 10, 2024

no work today in my MacbookPro M3 when i ran "brew upgrade" and installed mpv 0.37.0.2 from 0.37.0.1 and ffmpeg 7.0 from 6.1.1.7
any solution?

@ttforsd
Copy link

ttforsd commented Apr 15, 2024

no work today in my MacbookPro M3 when i ran "brew upgrade" and installed mpv 0.37.0.2 from 0.37.0.1 and ffmpeg 7.0 from 6.1.1.7 any solution?

Same issue on m1 air

@ddiaconu21
Copy link

Anyone came across this error?

doriandiaconu@Dorians-MacBook-Pro mpv % ./script.sh --static
+ meson setup build
The Meson build system
Version: 1.5.0
Source dir: /Users/doriandiaconu/mpv
Build dir: /Users/doriandiaconu/mpv/build
Build type: native build
Project name: mpv
Project version: 0.38.0-UNKNOWN
C compiler for the host machine: cc (clang 16.0.0 "Apple clang version 16.0.0 (clang-1600.0.23.1)")
C linker for the host machine: cc ld64 1115.7.2
Host machine cpu family: aarch64
Host machine cpu: aarch64
Program python3 found: YES (/opt/homebrew/bin/python3)
Did not find pkg-config by name 'pkg-config'
Found pkg-config: NO
Did not find CMake 'cmake'
Found CMake: NO
Run-time dependency libavcodec found: NO (tried framework)

meson.build:22:13: ERROR: Dependency lookup for libavcodec with method 'pkgconfig' failed: Pkg-config for machine host machine not found. Giving up.

A full log can be found at /Users/doriandiaconu/mpv/build/meson-logs/meson-log.txt

@NathanielH-snek
Copy link

Perhaps someone (perhaps myself) could just host a repo with mpv builds? I’m surprised that hasn’t been done yet already actually

@nwparker
Copy link

Perhaps someone (perhaps myself) could just host a repo with mpv builds? I’m surprised that hasn’t been done yet already actually

That'd be nice.
If you build it on GitHub, I wonder if you could use macos-14 runner since it appears it uses the M1

@nwparker
Copy link

Anyone came across this error?

doriandiaconu@Dorians-MacBook-Pro mpv % ./script.sh --static
+ meson setup build
The Meson build system
Version: 1.5.0
Source dir: /Users/doriandiaconu/mpv
Build dir: /Users/doriandiaconu/mpv/build
Build type: native build
Project name: mpv
Project version: 0.38.0-UNKNOWN
C compiler for the host machine: cc (clang 16.0.0 "Apple clang version 16.0.0 (clang-1600.0.23.1)")
C linker for the host machine: cc ld64 1115.7.2
Host machine cpu family: aarch64
Host machine cpu: aarch64
Program python3 found: YES (/opt/homebrew/bin/python3)
Did not find pkg-config by name 'pkg-config'
Found pkg-config: NO
Did not find CMake 'cmake'
Found CMake: NO
Run-time dependency libavcodec found: NO (tried framework)

meson.build:22:13: ERROR: Dependency lookup for libavcodec with method 'pkgconfig' failed: Pkg-config for machine host machine not found. Giving up.

A full log can be found at /Users/doriandiaconu/mpv/build/meson-logs/meson-log.txt

Install dependencies. In this case, pkg-config

@ddiaconu21
Copy link

ddiaconu21 commented Jul 23, 2024

pkg-config

Thank you, but it's still not working. Same issues...

doriandiaconu@Dorians-MacBook-Pro mpv % ./script.sh --static   
+ meson setup build
The Meson build system
Version: 1.5.0
Source dir: /Users/doriandiaconu/mpv
Build dir: /Users/doriandiaconu/mpv/build
Build type: native build
Project name: mpv
Project version: 0.38.0-UNKNOWN
C compiler for the host machine: cc (clang 16.0.0 "Apple clang version 16.0.0 (clang-1600.0.23.1)")
C linker for the host machine: cc ld64 1115.7.2
Host machine cpu family: aarch64
Host machine cpu: aarch64
Program python3 found: YES (/opt/homebrew/bin/python3)
Found pkg-config: YES (/opt/homebrew/bin/pkg-config) 0.29.2
Did not find CMake 'cmake'
Found CMake: NO
Run-time dependency libavcodec found: NO (tried pkgconfig and framework)

meson.build:22:13: ERROR: Dependency "libavcodec" not found, tried pkgconfig and framework

A full log can be found at /Users/doriandiaconu/mpv/build/meson-logs/meson-log.txt
doriandiaconu@Dorians-MacBook-Pro mpv % brew install pkg-config
Warning: pkg-config 0.29.2_3 is already installed and up-to-date.
To reinstall 0.29.2_3, run:
  brew reinstall pkg-config

@nwparker
Copy link

pkg-config

Thank you, but it's still not working. Same issues...

doriandiaconu@Dorians-MacBook-Pro mpv % ./script.sh --static   
+ meson setup build
The Meson build system
Version: 1.5.0
Source dir: /Users/doriandiaconu/mpv
Build dir: /Users/doriandiaconu/mpv/build
Build type: native build
Project name: mpv
Project version: 0.38.0-UNKNOWN
C compiler for the host machine: cc (clang 16.0.0 "Apple clang version 16.0.0 (clang-1600.0.23.1)")
C linker for the host machine: cc ld64 1115.7.2
Host machine cpu family: aarch64
Host machine cpu: aarch64
Program python3 found: YES (/opt/homebrew/bin/python3)
Found pkg-config: YES (/opt/homebrew/bin/pkg-config) 0.29.2
Did not find CMake 'cmake'
Found CMake: NO
Run-time dependency libavcodec found: NO (tried pkgconfig and framework)

meson.build:22:13: ERROR: Dependency "libavcodec" not found, tried pkgconfig and framework

A full log can be found at /Users/doriandiaconu/mpv/build/meson-logs/meson-log.txt
doriandiaconu@Dorians-MacBook-Pro mpv % brew install pkg-config
Warning: pkg-config 0.29.2_3 is already installed and up-to-date.
To reinstall 0.29.2_3, run:
  brew reinstall pkg-config

The message here is pretty clear, libavcodec is not found. Try installing that. In general, follow the above instructions and install all dependencies.
Take no offense, but I suggest you try ChatGPT for assistance as these all seem straightforward enough issues

@Akczht
Copy link

Akczht commented Jul 24, 2024

you have not installed most of the dependencies, in this case ffmpeg, check that all the requires dependencies are properly installed, check here

@pxia
Copy link

pxia commented Jul 24, 2024

I also created a script for this: https://github.com/pxia/mpv-macos-build

@tano70
Copy link

tano70 commented Jul 26, 2024

Ho anche creato uno script per questo: https://github.com/pxia/mpv-macos-build

Has anyone tried this script on Mac OS 14.5 and can tell me if it works?

@pxia
Copy link

pxia commented Jul 27, 2024

@tano70 yes i've built it myself on 14.5

@kotiqueTheMaid
Copy link

Works perfectly on Sonoma 14.6.1

@hvirta
Copy link

hvirta commented Sep 9, 2024

Note that the mpv project itself provides automatic "test builds" of mpv for various systems and architectures, including an ARM build for macOS. They can be found here: https://github.com/mpv-player/mpv/actions/workflows/build.yml?query=event:push+branch:master
and are also linked on the project's website here: https://mpv.io/installation/

In my own limited experience the ARM build appears quite stable, even with gpu-next enabled.

@joeynotjoe
Copy link

@hvirta awesome, thanks for the heads up!

@tano70
Copy link

tano70 commented Sep 17, 2024

@tano70sì, l'ho costruito io stesso su 14.5

thanks!

@alphagumibear
Copy link

Hi, can anyone tell me how I would uninstall if I followed the instructions in the main post? is it simply deleting the mpv folder or is there more to it? Thanks

@joshkerr
Copy link

This worked fine for me on MacOS 15.0.

@ElhemEnohpi
Copy link

@hvirta - thanks, good to know after so many years we can finally download an Apple Silicon binary, including the application bundle, instead of having to go through all this to compile it! It's working well for me, so far. Btw., the direct link to the latest nightly build, as given at https://mpv.io/installation/ is:

https://nightly.link/mpv-player/mpv/workflows/build/master

@alphagumibear - about uninstalling - apart from the mpv folder, the instructions in the main post involve installing Homebrew, and a number of packages within it. If you want to completely remove Homebrew and all the packages, see: Homebrew/install: 📥 Homebrew (un)installer

Otherwise, you'll probably want to remove libplacebo, the mpv formula's dependencies, and possibly dylibbundler and molten-vk, using the brew uninstall [packagename] command. Uninstalling the mpv dependencies is a bit tricky though, because brew uninstall mpv will just tell you that it's not installed. There may be a better way to do it, but I ended up just doing brew install mpv (which downloaded and installed a lot of things) and then brew uninstall mpv. That removed all the unused dependencies.

@alphagumibear
Copy link

@hvirta - thanks, good to know after so many years we can finally download an Apple Silicon binary, including the application bundle, instead of having to go through all this to compile it! It's working well for me, so far. Btw., the direct link to the latest nightly build, as given at https://mpv.io/installation/ is:

https://nightly.link/mpv-player/mpv/workflows/build/master

@alphagumibear - about uninstalling - apart from the mpv folder, the instructions in the main post involve installing Homebrew, and a number of packages within it. If you want to completely remove Homebrew and all the packages, see: Homebrew/install: 📥 Homebrew (un)installer

Otherwise, you'll probably want to remove libplacebo, the mpv formula's dependencies, and possibly dylibbundler and molten-vk, using the brew uninstall [packagename] command. Uninstalling the mpv dependencies is a bit tricky though, because brew uninstall mpv will just tell you that it's not installed. There may be a better way to do it, but I ended up just doing brew install mpv (which downloaded and installed a lot of things) and then brew uninstall mpv. That removed all the unused dependencies.

thank you for your response Elhem!

@giacomorebonato
Copy link

I don't see the OSC anymore and I can't enable it. Do you know what I might miss?

@amnah
Copy link

amnah commented Nov 14, 2024

I don't see the OSC anymore and I can't enable it. Do you know what I might miss?

it looks like they changed the dependencies with the latest v0.39.0 release. you'll need to rerun step 4 of the instructions:

brew install --build-from-source --only-dependencies mpv && brew install libplacebo

(this will install the new mujs and luajit dependencies)

@giacomorebonato
Copy link

I needed to install lua and the osc is now back. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment