Skip to content

player/lua: implement OSD layer in Lua#18097

Open
Xano-verse wants to merge 4 commits into
mpv-player:masterfrom
Xano-verse:lua-osd
Open

player/lua: implement OSD layer in Lua#18097
Xano-verse wants to merge 4 commits into
mpv-player:masterfrom
Xano-verse:lua-osd

Conversation

@Xano-verse

Copy link
Copy Markdown

As requested by #16991 this implements a Lua script that draws every visual component of the OSD and provides several user options for easy customization just like osc.lua does. Configuration file for the Lua OSD goes in ~/.config/mpv/script-opts/osd.conf

An additional command line option was created, --osd-lua, with default value false. The Lua OSD script suppresses the OSD written in C when it is run and is only loaded into mpv when the option --osd-lua is provided with yes.

Tests were created to ensure proper behaviour of this feature

Fixes: #16991

Xano-verse and others added 4 commits May 29, 2026 15:21
Add a command line option to activate the Lua OSD.
--osd-lua=yes to activate, --osd-lua=no to deactivate, same as
other similar options. Default value is false.

Signed-off-by: Alexandre Delgado <alexandre.delgado@tecnico.ulisboa.pt>
Co-authored-by: Ricardo Fonseca <ricardofonseca94321@tecnico.ulisboa.pt>
A Lua script that draws every visual component of the
OSD and provides several user options for easy customization
just like osc.lua does.
Configuration file for the Lua OSD goes in
~/.config/mpv/script-opts/osd.conf

This script suppresses the OSD written in C when it is run.

Signed-off-by: Alexandre Delgado <alexandre.delgado@tecnico.ulisboa.pt>
Co-authored-by: Ricardo Fonseca <ricardofonseca94321@tecnico.ulisboa.pt>
Minor changes so that mpv's code recognizes and loads
the Lua script for the OSD. This script is only loaded
and run if the --osd-lua option is provided with "yes".

Signed-off-by: Alexandre Delgado <alexandre.delgado@tecnico.ulisboa.pt>
Co-authored-by: Ricardo Fonseca <ricardofonseca94321@tecnico.ulisboa.pt>
Created two tests to ensure proper behaviour of the
Lua OSD. One test ensures that mpv is able to load
a video file with the Lua OSD running and the other
simulates both OSDs and compares values like volume
or paused state to ensure no value of the video
is being changed by the Lua OSD.

Closes mpv-player#16991

Signed-off-by: Alexandre Delgado <alexandre.delgado@tecnico.ulisboa.pt>
Co-authored-by: Ricardo Fonseca <ricardofonseca94321@tecnico.ulisboa.pt>
@llyyr

llyyr commented Jun 8, 2026

Copy link
Copy Markdown
Contributor

Why is this needed? Third party OSC scripts can already disable the OSD and implement their own if they like. Why does mpv need to carry this redundant built in script?

@kasper93

kasper93 commented Jun 8, 2026

Copy link
Copy Markdown
Member

I don't think the idea is bad in isolation, but the current OSD is working without lua support compiled into mpv. While there is argument, that such builds are not common/useful, as lua vm is pretty small and portable. The "reimplement in script" strategy is actually against the design of mpv as established for years.

@Xano-verse

Copy link
Copy Markdown
Author

Why is this needed? Third party OSC scripts can already disable the OSD and implement their own if they like. Why does mpv need to carry this redundant built in script?

The idea was to make it easier for third party users to customize the already existing OSD without having to implement something from scratch, like the feature proposal mentions. It would require less technical knowledge to make the OSD match their custom OSC, or to even just have their own OSD.

I don't think the idea is bad in isolation, but the current OSD is working without lua support compiled into mpv. While there is argument, that such builds are not common/useful, as lua vm is pretty small and portable. The "reimplement in script" strategy is actually against the design of mpv as established for years.

That makes sense, it's good that someone is able compile mpv without needing Lua at all and have the OSD working perfectly. I hope I'm not mistaken but these changes don't impact the existing OSD in any way so it should still be working as before without Lua support compiled into mpv

This was just to provide an additional option, in case Lua support was active, to be able to interact with it in Lua. It doesn't change the existing implementation of the OSD, just suppresses it with --osd-level=0

@Traneptora

Traneptora commented Jun 8, 2026

Copy link
Copy Markdown
Member

Where is ctx defined? Line 40 of this diff in test/libmpv_test_lua_osd.c: c17c4cd

@Andarwinux

Copy link
Copy Markdown
Contributor

That makes sense, it's good that someone is able compile mpv without needing Lua at all and have the OSD working perfectly. I hope I'm not mistaken but these changes don't impact the existing OSD in any way so it should still be working as before without Lua support compiled into mpv

This would introduce maintenance costs. If someone makes a change in C OSD, should they also synchronize it to Lua OSD?

@hooke007

hooke007 commented Jun 9, 2026

Copy link
Copy Markdown
Contributor

It's really odd to keep two versions.
If most users want easier customization, just drop the C version.
But IMO, that issue is just a niche requirement. And I don't understand actually. When you need to redesign the OSD to match with your OSC. You have rewritten the OSC script. Why not including these elements too? Just like any other osc-like scripts do.

@Xano-verse

Copy link
Copy Markdown
Author

Yes the C version could be dropped but it's like kasper said, OSD working without Lua support compiled into mpv is how things are currently and it seems like a good approach to not require Lua.

From the point of view of a third-party developer, I imagine one could want only the OSD working for a more minimalistic look, since OSD and OSC are seperate things and the OSC can be disabled with command line options. So in those cases they'd only need to configure the OSD, and it'd be simpler. I think keeping the OSC and OSD as seperate things in the customization side of things makes sense and allows to cover a wider range of specific use cases for customization

@kako94321

Copy link
Copy Markdown
Contributor

Where is ctx defined? Line 40 of this diff in test/libmpv_test_lua_osd.c: c17c4cd

ctx is used like a global variable and is defined in libmpv_common.h, which we include at the beginning. The context is then assigned on line 296 with ctx = mpv_create(); and assigned again on line 317 for the Lua OSD test. I believe this follows the same pattern as other existing tests.

This would introduce maintenance costs. If someone makes a change in C OSD, should they also synchronize it to Lua OSD?

About the maintenance, that is a very good point. We made the OSD in Lua have a similar default appearance to the one in C because it's a good starting point for customization but the OSD in Lua is functionally independent. So it wouldn't be strictly necessary to update the Lua OSD if the one in C was changed. Only if there was a desire to keep them always looking alike, or if there were changes to the hooks, but I take that would affect other Lua scripts as well

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

OSD - Offer a Lua file for customization similar to the one for OSC

7 participants