Run an mpv command: its name, then its arguments, as mpv's manual lists
them. Resolves with the command's result (null for most).
The command's name and its arguments: strings, numbers
or booleans. The first is the command itself: mpv would take a
prefix word (no-osd, async, raw…) off the front and run what
follows, so the channel refuses one there (invalid). Arguments are
not expanded (${property} stays text).
What the command returns.
A plugin sharpens the picture with an FFmpeg filter the typed chain does not offer, and takes it out when the user switches it off. The label makes the filter the plugin's: the player removes it by itself when the plugin stops.
await plugin.mpv.command(["vf", "add", "@crisp:lavfi=[cas=strength=0.6]"]);
// later
await plugin.mpv.command(["vf", "remove", "@crisp"]);
Read an mpv property now.
The property, as mpv names it ("estimated-vf-fps",
"video-params/w").
Its value.
A statistics panel reads which hardware decoder mpv uses now.
get resolves with mpv's value: here a string, "no" without one.
const decoder = await plugin.mpv.get("hwdec-current");
await plugin.osd.show("Decoder: {}", [String(decoder)]);
Set an mpv property (or option). It keeps the value after the plugin stops, until the player quits.
The property, as mpv names it.
Its new value, in the type mpv has for it.
A plugin switches mpv's scaler and puts the old one back when its
panel closes. The value is read first, since set does not undo
itself.
const before = await plugin.mpv.get("scale");
await plugin.mpv.set("scale", "ewa_lanczossharp");
// when the panel closes
await plugin.mpv.set("scale", before);
Hear an mpv property's value now and after each change. The player sends the newest value at most every 100 ms. From the first listener on the player keeps the plugin running for the rest of the run, also after the handle is disposed. As after every handler, an update pass follows each call of the listener.
The property, as mpv names it.
Receives the value: first the current one, then
each change. A listener added while the plugin already observes the
property gets its current value too, just after observe returns.
A handle that stops listening; it is disposed with the scope.
A panel shows the frame rate mpv measures behind its filter chain.
The listener runs with the current value and again whenever it
changes; a failure to observe goes to plugin.onError.
plugin.mpv.observe("estimated-vf-fps", (fps) => {
panel.set({ fps: typeof fps === "number" ? fps.toFixed(1) : "—" });
});
plugin.mpv: mpv's own commands and properties, sent to the player's mpv as they are.Example: Turn mpv's debanding on and show whether it took effect
A plugin offers mpv's
debandoption, which the plugin API has no member for.setwrites the property andgetreads it back; the names and the values are mpv's.Remarks
The channel is the SDK's contract: four members, their errors, what is refused and who owns what. The names, the arguments and what they do are mpv's, as its manual describes them for the mpv the player ships (commands, properties, options); they can change with a player version, which the SDK does not track. Prefer a typed member where one exists (Player, Scope.video, Scope.subtitles): it is checked, tested by TestHost and reaches snapshots and exports, which a filter added here does not.
Refused with code
refused(the message names the command or property and why): what starts a program, loads scripts or configuration, opens a control channel, makes the player write or delete files, ends the player, drives its keyboard and mouse, reaches the clipboard, or changes what the player manages itself (the source and the playlist, the position, the tracks, the output, the window, the subtitle style, the renderer options of Scope.video, its own filters). A plugin does the first four with Node; the last has a typed member. Reading is not refused, except the clipboard. The full table is in mpv.Filters:
["vf", "add", "@label:…"](andaf;add,pre,toggle,remove) with a label of the plugin's own, not starting withvestra-and notall. A labelled filter belongs to the plugin that added it: another plugin cannot change it (conflict), and the player removes it when the plugin stops. The player's own filters (the typed chains of Scope.video, the upscaler, motion smoothing) stay in the chain beside it.A property a plugin set keeps its value after the plugin stops, until the player quits; a plugin that wants it back sets it back. Observers end with the plugin. A filter or an observer keeps the plugin running from the moment it is added for the rest of that run, also after it is removed: the player judges again at the plugin's next start.
See
mpv
Since
1.8.0