A modern, Swift Package Manager (SPM) ready wrapper for libmpv on macOS.
This repository provides a pipeline to convert standard libmpv builds and MoltenVK into .xcframework bundles that can be easily consumed by Swift projects, solving the common "linker hell" and dependency issues.
Integrating libmpv into a modern macOS Swift app is notoriously difficult because:
- Framework Format: Most builds are raw
.frameworkbundles, while SPM prefers.xcframework. - Missing Dependencies:
libmpvdepends on dozens of system libraries (FFmpeg, Lua, etc.) that aren't automatically linked. - Vulkan/MoltenVK: Modern MPV uses Vulkan, requiring a MoltenVK translation layer that is often missing or hard to link.
This kit provides:
- Scripts to repackage
libmpvandMoltenVKinto.xcframeworks. - A Package.swift that explicitly links all required system dependencies (
VideoToolbox,zlib,xml2, etc.). - Example Code showing how to embed MPV into a SwiftUI view using a custom OpenGL renderer.
You need mpv and molten-vk installed via Homebrew to get the raw binaries:
brew install mpv molten-vkRun the provided scripts to generate the necessary artifacts:
# Generate MPV.xcframework from your Homebrew installation
./Scripts/create_xcframeworks.sh
# Generate MoltenVK.xcframework from your Homebrew installation
./Scripts/create_moltenvk_xcframework.shThis will create MPV.xcframework and MoltenVK.xcframework in your current directory.
- Drop the generated
.xcframeworkfolders into your project root (or wherever yourPackage.swiftexpects them). - Add this package as a dependency in your
Package.swift. - Ensure your target links against
MPVKit.
See Example/MPVVideoView.swift for a full implementation of a SwiftUI view that:
- Creates an
MPVinstance. - Sets up an
NSOpenGLView. - Renders video directly into the view using
vo=libmpv. - Handles hardware decoding (
hwdec=auto-safe) and high-quality rendering (gpu-hq).
MIT