Skip to content

Extending mpv and mpv.net via Lua scripting

stax76 edited this page Jun 14, 2022 · 8 revisions

Learn what Lua is in 100 seconds here.

Lua scripting is documented in the mpv manual here.

A very large collection of user scripts can be found in the mpv wiki here.

On GitHub, mpv scripts are tagged as mpv-script.

Lua scripts written by me.

Development Guide

In Visual Studio Code install:

The debugger works when the code is error free, if there is a Lua error the debugger exits at the error location without giving a trace or hint about the error. The debugger allows stepping through code, watch variables and table contents.

In your debug configuration defined in launch.json you can use 3 profiles:

  1. Lua without mpv using VS Code terminal output and debugging.
  2. Debugging with mpv.exe, you have to compile a mpv debug build, which is described here and here.
  3. Show mpv and Lua errors via external terminal output from mpv.com.

VS Code launch.json configuration

{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "lua",
            "program": "${file}",
            "request": "launch",
            "console": "integratedTerminal",
            "stopOnEntry": false,
            "type": "lua"
        },
        {
            "type": "lua",
            "request": "launch",
            "name": "mpv lua",
            "console": "internalConsole",
            "runtimeExecutable": "D:/Software/Development/MSYS2/mingw64/bin/mpv.exe",
            "runtimeArgs": ["--quiet", "--script=${file}", "D:/Samples/LG New York HDR UHD 4K Demo.mkv"],
            "stopOnEntry": false,
            "luaVersion": "5.1"
        },
        {
            "type": "lua",
            "request": "launch",
            "name": "mpv lua term",
            "console": "externalTerminal",
            "runtimeExecutable": "D:/Software/Development/MSYS2/mingw64/bin/mpv.com",
            "runtimeArgs": ["--quiet", "--script=${file}", "D:/Samples/LG New York HDR UHD 4K Demo.mkv"],
            "stopOnEntry": false,
            "luaVersion": "5.1"
        }
    ]
}

Resources

To read resources in dark mode, there is Dark Reader.