Cross-platform MPV video player library for .NET, with an Avalonia 12 implementation supporting Windows, macOS, and Linux.
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.
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}" />| 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.
- .NET 10 or later
- Avalonia 12
- libmpv 0.40.0 or greater
Native libmpv binaries for Windows, macOS, linux.
- Install the NuGet packages:
dotnet add package LibMpv
dotnet add package LibMpv.Avalonia
-
Add
MpvVideoViewto your Avalonia view and bind aMpvContextinstance from your ViewModel. -
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.
- Use
MpvContextto control playback:
Mpv.LoadFile("path/to/video.mp4");
Mpv.Play();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:
- shinchiro/mpv-winbuild-cmake — download
mpv-dev-x86_64-<date>.7z, extract and placelibmpv-2.dllalongside your application. - zhongfly/mpv-winbuild — alternative CI builds;
mpv-dev-x86_64-<date>.7zcontains the samelibmpv-2.dll.
macOS
Install via Homebrew (requires macOS 11 or later):
brew install mpvThe 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-devFor other distros, install via your package manager (e.g. dnf install mpv-libs-devel on Fedora) or build from source using mpv-build.
A sample application is included and has been tested on Windows, Linux, and macOS.
This project is licensed under the MIT License.
Originally created by Etienne Charland (mysteryx93) and Vadim Beloborodov (homov).
Maintained by Jeff Baxter (warden-vt).