Skip to content

media-kit/libmpv-darwin-build

Repository files navigation

libmpv build

Provides builds of libmpv for macOS & iOS, used by media_kit, compatible with commercial use for playback, and GPL use for encoding.

Heavily inspired by Homebrew and IINA.

Setup

Build

$ echo \"v0.0.1\" > nix/utils/default/version.nix
$ nix build -v
$ tree result
result
├── libmpv-libs_v0.0.1_ios-arm64-audio-default.tar.gz
├── libmpv-libs_v0.0.1_ios-arm64-audio-encodersgpl.tar.gz
├── libmpv-libs_v0.0.1_ios-arm64-audio-full.tar.gz
├── libmpv-libs_v0.0.1_ios-arm64-video-default.tar.gz
├── libmpv-libs_v0.0.1_ios-arm64-video-encodersgpl.tar.gz
├── libmpv-libs_v0.0.1_ios-arm64-video-full.tar.gz
├── libmpv-libs_v0.0.1_iossimulator-amd64-audio-default.tar.gz
├── libmpv-libs_v0.0.1_iossimulator-amd64-audio-encodersgpl.tar.gz
├── libmpv-libs_v0.0.1_iossimulator-amd64-audio-full.tar.gz
├── libmpv-libs_v0.0.1_iossimulator-amd64-video-default.tar.gz
├── libmpv-libs_v0.0.1_iossimulator-amd64-video-encodersgpl.tar.gz
├── libmpv-libs_v0.0.1_iossimulator-amd64-video-full.tar.gz
├── libmpv-libs_v0.0.1_iossimulator-arm64-audio-default.tar.gz
├── libmpv-libs_v0.0.1_iossimulator-arm64-audio-encodersgpl.tar.gz
├── libmpv-libs_v0.0.1_iossimulator-arm64-audio-full.tar.gz
├── libmpv-libs_v0.0.1_iossimulator-arm64-video-default.tar.gz
├── libmpv-libs_v0.0.1_iossimulator-arm64-video-encodersgpl.tar.gz
├── libmpv-libs_v0.0.1_iossimulator-arm64-video-full.tar.gz
├── libmpv-libs_v0.0.1_iossimulator-universal-audio-default.tar.gz
├── libmpv-libs_v0.0.1_iossimulator-universal-audio-encodersgpl.tar.gz
├── libmpv-libs_v0.0.1_iossimulator-universal-audio-full.tar.gz
├── libmpv-libs_v0.0.1_iossimulator-universal-video-default.tar.gz
├── libmpv-libs_v0.0.1_iossimulator-universal-video-encodersgpl.tar.gz
├── libmpv-libs_v0.0.1_iossimulator-universal-video-full.tar.gz
├── libmpv-libs_v0.0.1_macos-amd64-audio-default.tar.gz
├── libmpv-libs_v0.0.1_macos-amd64-audio-encodersgpl.tar.gz
├── libmpv-libs_v0.0.1_macos-amd64-audio-full.tar.gz
├── libmpv-libs_v0.0.1_macos-amd64-video-default.tar.gz
├── libmpv-libs_v0.0.1_macos-amd64-video-encodersgpl.tar.gz
├── libmpv-libs_v0.0.1_macos-amd64-video-full.tar.gz
├── libmpv-libs_v0.0.1_macos-arm64-audio-default.tar.gz
├── libmpv-libs_v0.0.1_macos-arm64-audio-encodersgpl.tar.gz
├── libmpv-libs_v0.0.1_macos-arm64-audio-full.tar.gz
├── libmpv-libs_v0.0.1_macos-arm64-video-default.tar.gz
├── libmpv-libs_v0.0.1_macos-arm64-video-encodersgpl.tar.gz
├── libmpv-libs_v0.0.1_macos-arm64-video-full.tar.gz
├── libmpv-libs_v0.0.1_macos-universal-audio-default.tar.gz
├── libmpv-libs_v0.0.1_macos-universal-audio-encodersgpl.tar.gz
├── libmpv-libs_v0.0.1_macos-universal-audio-full.tar.gz
├── libmpv-libs_v0.0.1_macos-universal-video-default.tar.gz
├── libmpv-libs_v0.0.1_macos-universal-video-encodersgpl.tar.gz
├── libmpv-libs_v0.0.1_macos-universal-video-full.tar.gz
├── libmpv-xcframeworks_v0.0.1_ios-universal-audio-default.tar.gz
├── libmpv-xcframeworks_v0.0.1_ios-universal-audio-encodersgpl.tar.gz
├── libmpv-xcframeworks_v0.0.1_ios-universal-audio-full.tar.gz
├── libmpv-xcframeworks_v0.0.1_ios-universal-video-default.tar.gz
├── libmpv-xcframeworks_v0.0.1_ios-universal-video-encodersgpl.tar.gz
├── libmpv-xcframeworks_v0.0.1_ios-universal-video-full.tar.gz
├── libmpv-xcframeworks_v0.0.1_macos-universal-audio-default.tar.gz
├── libmpv-xcframeworks_v0.0.1_macos-universal-audio-encodersgpl.tar.gz
├── libmpv-xcframeworks_v0.0.1_macos-universal-audio-full.tar.gz
├── libmpv-xcframeworks_v0.0.1_macos-universal-video-default.tar.gz
├── libmpv-xcframeworks_v0.0.1_macos-universal-video-encodersgpl.tar.gz
└── libmpv-xcframeworks_v0.0.1_macos-universal-video-full.tar.gz

Build a specific target

$ nix flake show
$ nix build -v .#mk-out-archive-libs-macos-universal-video-default
$ open result

Naming convention

libmpv-<format>_<version>_<os>-<arch>-<variant>-<flavor>.tar.gz
Component Notes Value
format Output format of built files libs, xcframeworks
version Semantic version v0.0.1, …
os Operating system ios, iossimulator, macos
arch Architecture arm64, amd64, universal
variant Usage context audio, video
flavor Available decoders and encoders default, full, encodersgpl

Inclusion:

  • Variants: $audio \subset video$
  • Flavors: $audio \subset full \subset encodersgpl$

Minimum versions

Platform Arch Min Version Notes
macOS amd64 10.9 Required by uchardet
arm64
iOS arm64 9.0 Required by ffmpeg
iOS Simulator amd64 9.0 Required by ffmpeg
arm64 12.0 Required by xcodebuild -create-xcframework

Dependencies

flowchart LR
    subgraph legend[Legend]
        direction TB
        subgraph links
            Q(node):::decoders -- "required" --> R(node):::decoders
            S(node):::decoders -. "optional" .-> T(node):::decoders
        end

        subgraph variants
            U(audio & video):::decoders
            V{{video only}}:::decoders
        end

        subgraph flavors
            W(default, full):::decoders
            X(encodersgpl):::encoders
        end
    end

    subgraph content[ ]
        direction LR
        A(mpv):::decoders -.-> B{{uchardet}}:::decoders
        A                 -.-> C{{libass}}:::decoders
        A                 -->  D(ffmpeg):::decoders

        E(fftools-ffi):::encoders --> D

        %% libass
        G -.-> F{{libpng}}:::decoders
        C -->  G{{freetype}}:::decoders
        C -->  H{{fribidi}}:::decoders
        C -->  I{{harfbuzz}}:::decoders
        G -.-> I

        %% ffmpeg
        D -.-> J(mbedtls):::decoders
        D -.-> K{{dav1d}}:::decoders
        D -.-> L{{libxml2}}:::decoders
        D -.-> M(libvorbis):::encoders
        D -.-> N{{libvpx}}:::encoders
        D -.-> O{{libx264}}:::encoders
        M -->  P(libogg):::encoders
    end

    classDef decoders stroke:#888
    classDef encoders stroke:#14a,stroke-width:3px
    classDef legend fill:transparent,stroke:#8882
    classDef content fill:transparent,stroke:transparent
    classDef card fill:transparent,stroke:#888a

    legend:::legend
    content:::content
    links:::card
    variants:::card
    flavors:::card
Loading
  • mpv: A free (as in freedom) media player for the command line. It supports a wide variety of media file formats, audio and video codecs, and subtitle types

  • ffmpeg: A cross-platform solution for converting, streaming, and recording audio and video, with support for a wide range of codecs and formats

  • fftools-ffi: FFmpeg's command-line interface exposed as a shared library for FFI usage

  • libass: A library for rendering subtitles in videos, with support for advanced text formatting and positioning features (made optional with a patch)

  • fribidi: A library for handling bidirectional text (such as Arabic or Hebrew) in Unicode strings, with support for complex shaping and layout

  • freetype: A library for rendering high-quality text in graphics applications, with support for a wide range of font formats and glyph rendering techniques

  • harfbuzz: A library for shaping and laying out text in multiple languages and scripts, with support for advanced typography features such as ligatures and kerning

  • libpng: A library for reading and writing PNG (Portable Network Graphics) images, providing efficient image compression and lossless data handling

  • dav1d: A library for cross-platform AV1 decoding

  • libogg: Reference implementation of the Ogg media container

  • libvorbis: Reference implementation of the Ogg Vorbis audio format

  • libvpx: Reference implementation of the VP8 and VP9 video formats

  • libx264: Free software library for encoding video streams into the H.264/MPEG-4 AVC compression format

  • mbedtls: An open source, portable, easy to use, readable and flexible TLS library

  • libxml2: A library for processing XML data, used by ffmpeg to support the Dash protocol

  • uchardet: A C++ port of the Universal Character Encoding Detector (used by Mozilla Firefox and Thunderbird) for detecting the encoding of input text

Commercial use

Default, Full flavors

Dependency Licence Commercial use
mpv LGPL-2.1 (-Dgpl=false)
ffmpeg LGPL-2.1 (--enable-gpl & --enable-nonfree omitted)
libass ISC
freetype FreeType
harfbuzz MIT
fribidi LGPL-2.1
libpng zlib/libpng
mbedtls Apache 2.0
uchardet MPL-1.1, GPL-2, LGPL-2.1
libxml2 MIT
dav1d BSD-2-clause

Encoders-GPL flavor

Dependency Licence Commercial use
mpv LGPL-2.1 (-Dgpl=false)
ffmpeg GPL-2.1 (--enable-nonfree omitted)
libass ISC
freetype FreeType
harfbuzz MIT
fribidi LGPL-2.1
libpng zlib/libpng
mbedtls Apache 2.0
uchardet MPL-1.1, GPL-2, LGPL-2.1
libxml2 MIT
dav1d BSD-2-clause
fftools-ffi LGPL-2.1
libx264 GPL-2.0+
libvpx BSD-3-clause
libvorbis BSD-3-clause
libogg BSD-3-clause

Notes

  • Some dependencies, which are not needed at the moment, may be added in the future:

    • libbluray: A library for reading and parsing Blu-ray discs, with support for advanced features such as BD-J menus and seamless branching

    • libarchive: A library for reading various archive formats, including tar and zip, with support for compression and metadata, and a flexible API for reading and extracting archive contents

  • We use meson as much as possible in order to simplify cross-compilation, at the cost of some heaviness regarding legacy packages

How the libass optional patch was created

As the dependency of mpv on libass is deeply embedded in the code, the simplest solution was to:

  1. Remove the dynamic linking in meson.build.
  2. Include the ass/ass.h and ass/ass_types.h headers directly in the code
  3. Remove the call to ass_library_version in player/command.c
  4. Remove the calls to ass_library_init, called by mp_ass_init, in sub/osd_libass.c and sub/sd_ass.c

Resources