mpv is a media player based on MPlayer and mplayer2. It supports a wide variety of videofile formats, audio and video codecs, and subtitle types. Special input URLtypes are available to read input from a variety of sources other than diskfiles. Depending on platform, a variety of different video and audio outputmethods are supported.
mpv has a fully configurable, command-driven control layer which allows youto control mpv using keyboard, mouse, or remote control (there is noLIRC support - configure remotes as input devices instead).
(The following keybindings open a selector in the console that lets you choosefrom a list of items by typing part of the desired item and/or by navigatingthem with keybindings: Down and Ctrl+n go down, Up and Ctrl+p goup, Page down and Ctrl+f scroll down one page, and Page up andCtrl+b scroll up one page.)
Command line arguments starting with - are interpreted as options,everything else as filenames or URLs. All options except flag options (orchoice options which include yes) require a parameter in the form--option=value.
One exception is the lone - (without anything else), which means media datawill be read from stdin. Also, -- (without anything else) will make theplayer interpret all following arguments as filenames, even if they start with-. (To play a file named -, you need to use ./-.)
The --option=value syntax is not strictly enforced, and the alternativelegacy syntax -option value and -option=value will also work. This ismostly for compatibility with MPlayer. Using these should be avoided. Theirsemantics can change any time in the future.
For example, the alternative syntax will consider an argument following theoption a filename. mpv -fs no will attempt to play a file named no,because --fs is a flag option that requires no parameter. If an optionchanges and its parameter becomes optional, then a command line using thealternative syntax will break.
Until mpv 0.31.0, there was no difference whether an option started with --or a single -. Newer mpv releases strictly expect that you pass the optionvalue after a =. For example, before mpv --log-file f.txt would writea log to f.txt, but now this command line fails, as --log-file expectsan option value, and f.txt is simply considered a normal file to be played(as in mpv f.txt).
It gets more complicated if the suboption parser is involved. The suboptionparser puts several options into a single string, and passes them to acomponent at once, instead of using multiple options on the level of thecommand line.
This passes option1 and option3 to the foo filter, with option2as flag (implicitly option2=yes), and adds a bar filter after that. Ifan option contains spaces or characters like , or :, you need to quotethem:
The [...] form of quotes wraps everything between [ and ]. It'suseful with shells that don't interpret these characters in the middle ofan argument (like bash). These quotes are balanced (since mpv 0.9.0): the [and ] nest, and the quote terminates on the last ] that has no matching[ within the string. (For example, [a[b]c] results in a[b]c.)
Suboptions passed to the client API are also subject to escaping. Usingmpv_set_option_string() is exactly like passing --name=data to thecommand line (but without shell processing of the string). Some optionssupport passing values in a more structured way instead of flat strings, andcan avoid the suboption parsing mess. For example, --vf supportsMPV_FORMAT_NODE, which lets you pass suboptions as a nested data structureof maps and arrays.
Some care must be taken when passing arbitrary paths and filenames to mpv. Forexample, paths starting with - will be interpreted as options. Likewise,if a path contains the sequence ://, the string before that might beinterpreted as protocol prefix, even though :// can be part of a legalUNIX path. To avoid problems with arbitrary paths, you should be sure thatabsolute paths passed to mpv start with /, and prefix relative paths with./.
For paths passed to suboptions, the situation is further complicated by theneed to escape special characters. To work this around, the path can beadditionally wrapped in the fixed-length syntax, e.g. %n%string_of_length_n(see above).
Additionally, any file-local option changed at runtime is reset when the currentfile stops playing. If option --c is changed during playback offile2.mkv, it is reset when advancing to file3.mkv. This only affectsfile-local options. The option --a is never reset here.
Some options which store lists of option values can have action suffixes. Forexample, the --display-tags option takes a ,-separated list of tags, butthe option also allows you to append a single tag with --display-tags-append,and the tag name can for example contain a literal , without the need forescaping.
A key/value list is a list of key/value string pairs. In programming languages,this type of data structure is often called a map or a dictionary. The ordernormally does not matter, although in some cases the order might matter.
If you want to pass a value without interpreting it for escapes or ,, it isrecommended to use the -append variant. When using libmpv, prefer usingMPV_FORMAT_NODE_MAP; when using a scripting backend or the JSON IPC, use anappropriate structured data type.
Although some operations allow specifying multiple items, using this is stronglydiscouraged and deprecated, except for -set. There is a chance thatoperations like -add and -pre will work like -append and accept asingle, unescaped item only (so the , separator will not be interpreted andis passed on as part of the value).
User-specific options override system-wide options and options given on thecommand line override both. The syntax of the configuration files isoption=value. Everything after a # is considered a comment. Options thatwork without values can be enabled by setting them to yes and disabled bysetting them to no, and if the value is omitted, yes is implied. Evensuboptions can be specified in this way.
This is done like with command line options. A config entry can be quoted with", ', as well as with the fixed-length syntax (%n%) mentionedbefore. This is like passing the exact contents of the quoted string as acommand line option. C-style escapes are currently _not_ interpreted on thislevel, although some options do this manually (this is a mess and shouldprobably be changed at some point). The shell is not involved here, so optionvalues only need to be quoted to escape # anywhere in the value, ",' or % at the beginning of the value, and leading and trailingwhitespace.
To ease working with different configurations, profiles can be defined in theconfiguration files. A profile starts with its name in square brackets,e.g. [my-profile]. All following options will be part of the profile. Adescription (shown by --profile=help) can be defined with theprofile-desc option. To end the profile, start another one or use theprofile name default to continue with normal options.
You can list profiles with --profile=help, and show the contents of aprofile with --show-profile= (replace with the profilename). You can apply profiles on start with the --profile= option,or at runtime with the apply-profile command.
Profiles can be set at runtime with apply-profile command. Since thisoperation is "destructive" (every item in a profile is simply set as anoption, overwriting the previous value), you can't just enable and disableprofiles again.
As a partial remedy, there is a way to make profiles save old option valuesbefore overwriting them with the profile values, and then restoring the oldvalues at a later point using apply-profile restore.
Every profile has its own list of backed up values. If the backupalready exists (e.g. if apply-profile name was called more thanonce in a row), the existing backup is no changed. The restore operationwill remove the backup.
It's important to know that restoring does not "undo" setting an option,but simply copies the old option value. Consider for example vf-add,appends an entry to vf. This mechanism will simply copy the entirevf list, and does _not_ execute the inverse of vf-add (thatwould be vf-remove) on restoring.
Profiles which have the profile-cond option set are applied automaticallyif the associated condition matches (unless auto profiles are disabled). Theoption takes a string, which is interpreted as Lua expression. If theexpression evaluates as truthy, the profile is applied. If the expressionerrors or evaluates as falsy, the profile is not applied. This Lua codeexecution is not sandboxed.
Any variables in condition expressions can reference properties. If anidentifier is not already defined by Lua or mpv, it is interpreted as property.For example, pause would return the current pause status. You cannotreference properties with - this way since that would denote a subtraction,but if the variable name contains any _ characters, they are turned into-. For example, playback_time would return the propertyplayback-time.
A more robust way to access properties is using p.property_name orget("property-name", default_value). The automatic variable to propertymagic will break if a new identifier with the same name is introduced (forexample, if a function named pause() were added, pause would return afunction value instead of the value of the pause property).
This mechanism tries to "unapply" profiles once the condition changes fromtruthy to falsy or error. If you want to use this, you need to setprofile-restore for the profile. Another possibility it to create anotherprofile with an inverse condition to undo the other profile.
This appends the rotate filter to the video filter chain when enteringfullscreen. When leaving fullscreen, the vf option is set to the valueit had before entering fullscreen. Note that this would also remove anyother filters that were added during fullscreen mode by the user. Avoidingthis is trickier, and could for example be solved by adding a second profilewith an inverse condition and operation:
The environment does "magic" accesses to mpv properties. If an identifieris not already defined in _G, it retrieves the mpv property of the samename. Any occurrences of _ in the name are replaced with - beforereading the property. The returned value is as retrieved bymp.get_property_native(name). Internally, a cache of property values,updated by observing the property is used instead, so properties that arenot observable will be stuck at the initial value forever.
c80f0f1006