-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 topause pauses playback; reading time-pos returns the current position.
Options
Event loop
Hooks
Hooks are synchronous events that block the player until your code callsmpv_hook_continue().
Time and memory
Property formats
Thempv_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 returnint. A return value >= 0 indicates success; negative values are mpv_error codes.
Minimal example
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
Includerender_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.
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.
open_fn receives the URI and fills an mpv_stream_cb_info struct with callback pointers:
Thread safety
The client API is fully thread-safe unless otherwise noted. However, only one thread may callmpv_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_NUMERICmust be set to"C". If you callsetlocale(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
SIGCHLDor callwait()for all PIDs — mpv manages its own child processes. - If your code sets signal handlers, use the
SA_RESTARTflag.
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