Skip to main content
libmpv provides a C API for embedding mpv’s playback engine into other applications. The API is licensed under ISC, while the mpv core itself is GPLv2+ by default (or LGPLv2.1+ when built with -Dgpl=false).
The API version is encoded as MPV_CLIENT_API_VERSION. The current version is MPV_MAKE_VERSION(2, 5). Changes to the C API are documented in DOCS/client-api-changes.rst.

Usage modes

The client API can be used in two ways:

Internal (scripting)

Used inside mpv itself — Lua scripts access the same API through an internal handle. No library linking is required.

External (embedding)

Link against libmpv and call mpv_create() to embed mpv as a playback backend in your own application.

API lifecycle

1

Create an instance

Call mpv_create() to allocate a new mpv instance. The instance is in a pre-initialized state — no playback occurs yet.
2

Set options

Use mpv_set_property() or mpv_set_property_string() to configure the instance before initialization. Some options (e.g. config, config-dir, input-conf, load-scripts, script, player-operation-mode) must be set before mpv_initialize().
3

Initialize

Call mpv_initialize() to start the player. After this point, most API functions become available.
4

Send commands

Load files and control playback with mpv_command() or mpv_command_string().
5

Run the event loop

Process events with mpv_wait_event(). This drives the player’s interaction with your code.
6

Destroy the instance

Call mpv_terminate_destroy() to shut down the player and free all resources, or mpv_destroy() to detach the handle without forcing shutdown.

Core function signatures

Instance management

Commands

Properties

Properties are runtime variables that control and report playback state. Writing to pause pauses playback; reading time-pos returns the current position.

Options

Event loop

Hooks

Hooks are synchronous events that block the player until your code calls mpv_hook_continue().

Time and memory

Property formats

The mpv_format enum describes the data type used when getting or setting properties and options.

Event types

mpv_wait_event() returns a pointer to an mpv_event struct. Check event->event_id against the mpv_event_id enum.

Error handling

All API functions that can fail return int. A return value >= 0 indicates success; negative values are mpv_error codes.

Minimal example

Compile with:

Rendering API

The render API (render.h) lets you drive video rendering from your own OpenGL (or software) context instead of letting mpv create its own window.

Key functions

OpenGL rendering

Include render_gl.h and use MPV_RENDER_API_TYPE_OPENGL. You must supply a get_proc_address callback so mpv can resolve GL function pointers without linking to a GL library directly.
Render on a dedicated thread. Calling normal libmpv API functions from the render thread can cause deadlocks. See the Threading section in render.h for the full list of safe functions.

Stream callbacks

stream_cb.h lets you register a custom URL protocol backed by your own read/seek/size/close callbacks, so mpv can play from any data source.
Your open_fn receives the URI and fills an mpv_stream_cb_info struct with callback pointers:
Custom stream callbacks must not call libmpv API functions — doing so will deadlock.

Thread safety

The client API is fully thread-safe unless otherwise noted. However, only one thread may call mpv_wait_event() on a given handle at a time. Functions that are explicitly safe to call from the render thread are annotated with “Safe to be called from mpv render API threads” in client.h.

Environment requirements

  • LC_NUMERIC must be set to "C". If you call setlocale(LC_ALL, ...), reset it: setlocale(LC_NUMERIC, "C").
  • The FPU precision must be at least double.
  • On Windows, mpv calls timeBeginPeriod(1).
  • Do not override SIGCHLD or call wait() for all PIDs — mpv manages its own child processes.
  • If your code sets signal handlers, use the SA_RESTART flag.

Language bindings

Community-maintained bindings are available for several languages:

Python

python-mpv — ctypes-based bindings

Rust

libmpv-rs — safe Rust bindings

Go

mpvipc — Go IPC client
See the mpv wiki for a more complete list of bindings and example projects.