Skip to content

About

Cross-platform MPV video player for .NET and Avalonia with OpenGL implementation

Resources

Stars

0 stars

Watchers

0 watching

Forks

 
 

Latest commit

 

History

41 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

LibMpv for .NET

Cross-platform MPV video player library for .NET, with an Avalonia 12 implementation supporting Windows, macOS, and Linux.

Overview

LibMpv wraps the MPV media player API in a clean, idiomatic .NET interface. It is structured in three layers:

  • MpvApi — low-level static P/Invoke calls to the native libmpv library
  • MpvContextBase — .NET-friendly wrappers around the raw API
  • MpvContext — fully strongly-typed commands, properties, and options

LibMpv targets netstandard2.0 and can be used independently of any UI framework.

LibMpv.Avalonia

An Avalonia 12 implementation is provided via the LibMpv.Avalonia package. Drop MpvVideoView into your view and bind MpvContext from your ViewModel:

<mpv:MpvVideoView MpvContext="{Binding Mpv}" />

Renderers

Platform Default Renderer Zero-Copy GPU
Windows Native w/ AngleEGL Yes
macOS OpenGL No
Linux OpenGL w/ EGL Yes

Software rendering is also available as a fallback on all platforms.

Requirements

  • .NET 10 or later
  • Avalonia 12
  • libmpv 0.40.0 or greater

Native libmpv binaries for Windows, macOS, linux.

Getting Started

  1. Install the NuGet packages:
dotnet add package LibMpv
dotnet add package LibMpv.Avalonia
  1. Add MpvVideoView to your Avalonia view and bind a MpvContext instance from your ViewModel.

  2. Configure per-OS rendering modes in your AppBuilder:

using System.Runtime.InteropServices;
using Avalonia.Win32;
using Avalonia.X11;

public static AppBuilder BuildAvaloniaApp()
{
    var builder = AppBuilder.Configure<App>().UsePlatformDetect();

    if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
        builder.With(new Win32PlatformOptions
        {
            RenderingMode = [Win32RenderingMode.AngleEgl, Win32RenderingMode.Software]
        });
    else if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
        builder.With(new AvaloniaNativePlatformOptions
        {
            RenderingMode = [AvaloniaNativeRenderingMode.OpenGl, AvaloniaNativeRenderingMode.Software]
        });
    else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
        builder.With(new X11PlatformOptions
        {
            RenderingMode = [X11RenderingMode.Egl, X11RenderingMode.Glx, X11RenderingMode.Software]
        });

    return builder.LogToTrace();
}

Windows uses ANGLE (OpenGL ES over D3D11) which is required for the libmpv OpenGL render context to share the same GPU pipeline. macOS uses native OpenGL via Metal. Linux prefers EGL for Wayland compatibility, falling back to GLX for X11.

  1. Use MpvContext to control playback:
Mpv.LoadFile("path/to/video.mp4");
Mpv.Play();

Getting the Native libmpv Libraries

LibMpv requires native libmpv 0.40.0 binaries. Note that mpv does not publish official prebuilt packages — the options below are community-maintained builds.

Windows

Download a prebuilt libmpv-2.dll from one of these community build sources:

macOS

Install via Homebrew (requires macOS 11 or later):

brew install mpv

The dylib will be available at /opt/homebrew/lib/libmpv.dylib (Apple Silicon) or /usr/local/lib/libmpv.dylib (Intel).

Linux (Ubuntu/Debian)

The version of libmpv in the standard Ubuntu repositories may be older than 0.40.0. To get 0.40.0, use the unofficial PPA:

sudo add-apt-repository ppa:ubuntuhandbook1/mpv
sudo apt update
sudo apt install libmpv-dev

For other distros, install via your package manager (e.g. dnf install mpv-libs-devel on Fedora) or build from source using mpv-build.

Sample Project

A sample application is included and has been tested on Windows, Linux, and macOS.

License

This project is licensed under the MIT License.

Originally created by Etienne Charland (mysteryx93) and Vadim Beloborodov (homov).

Maintained by Jeff Baxter (warden-vt).

About

Cross-platform MPV video player for .NET and Avalonia with OpenGL implementation

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages