Skip to content

The best way to test mpv user scripts

stax76 edited this page Jan 2, 2024 · 4 revisions

I want to share a method on how to easily test mpv user scripts.

The problem is many user scripts require many different files in many different folders. Making the necessary changes in the main config directory has several problems, it's better to use a separate config directory for every user script to test. This can be achieved using the mpv command line option --config-dir or with the mpv environment variable MPV_HOME. In this guide, I use the --config-dir option and Windows Batch files, .bat files can be executed directly without context menu and the startup time is very fast, there isn't much script code used in this guide, just 3 environment variables defined and a command line.

Environment variables are used to define global mpv command line options and 2 test videos to play. Now Windows has a GUI to define environment variables (it can be invoked from command line with rundll32.exe sysdm.cpl,EditEnvironmentVariables), instead, I describe how to define the variables in a .bat file and make this .bat file used whenever cmd runs. In most shells the principle is known as profile. So how does it work with cmd/batch? It requires adding a registry entry:

Windows Registry Editor Version 5.00

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Command Processor]
"AutoRun"="C:\\foo\\bar\\autorun.bat"

In the profile, I've defined the environment variables like so:

@echo off

set TEST_VIDEOS="E:\foo\bar1.mkv" "E:\foo\bar2.mkv"
set MPV_PLAYGROUND_OPTS=--quiet --keep-open=always --script-opts-append=osc-scalewindowed=2 --idle=yes --force-window=yes --autofit=50%%x50%% --geometry=99%%:50%%
set MPVNET_PLAYGROUND_OPTS=--quiet --keep-open=always --script-opts-append=osc-scalewindowed=2 --autofit=50 --geometry=100:50

For mpv.net I've defined separate options as its implementation for --autofit and --geometry isn't 100% mpv compatible.

To test a script or plugin I create a folder, in there I do the configuration, at minimum a scripts folder with a script or plugin.

The last step is creating a run.bat file in the folder containing:

@echo off

mpv --config-dir="%~dp0\" %MPV_PLAYGROUND_OPTS% %TEST_VIDEOS%

Using a relative path (--config-dir=.) doesn't work with C plugins.

That's it, run.bat can now be executed to test the script/plugin, I keep the configurations for the case I want to test the same scripts some time later.