Mpv: Improve lua support. MPV as application platform

Created on 13 Jan 2017  路  26Comments  路  Source: mpv-player/mpv

Just an semi-crazy idea. MPV as application platform (like browser or node.js) for building complex cursers-like gui-players.

  1. integrate luarocks. No more crap, semi-working, conflicting user scripts, replace them to packages with dependencies, versioning, building, etc. Do not move this functionality to os-specific package managers, like apt. Lua scripts must works everywhere, where mpv works.
  2. Add lua plugin api bus, each lua-plugin can provide some information about supported mpv version, description, etc.
  3. Provide high-level ui toolkit with common api for building custom pseudo-guis: like node.js blessed or ncurses. Do not expose to plugins lowlevel assdraw
  4. Move osc.lua and ytdl_hook.lua to separate lurocks packages. Add ability to script-programmers replace them to own realizations.
  5. Use best-practices for building declarative pseudo-gui interfaces, i meant web/frontend development, js ecosystem, for example react-blessed.
  6. Provide documentation about api and examples

Why text user interface inside mpv is better than libmpv and mpv-wrappers, like smplayer?

  1. Platform and os independed: no gcc, qt, gtk, etc binaries: just compile mpv in pure c and lua (node.js) and run on my china 5$ arm-device.
  2. Text ui (osd) is simpler, easily embeddable and less resource-eating
  3. Simpler to develop: no compiling, no typing, etc
  4. Side developers can build something like kodi, but lightweight.

Yet not many lua-scripts for mpv, may be move to node.js? Why?

  1. Node.js is alive: community really biggest, integration with ide, types via typescript, etc
  2. Node.js is probably faster than stock lua (not luaJIT)
  3. Node.js ecosystem is actively mantained, just look at popular libraries activity in lua and node.js
  4. Already exists tons of libraries for building interfaces: react-blessed, in lua ecosystem i couldn't find libraries like this, only for gui
  5. Compare luarocks.org and npmjs.org packages: lua for simple embeddable-things, not for complex applications and gui-interfaces.

Most helpful comment

Why?

I'll give you the benefit of a doubt and assume you're not trolling (which is really hard to do).

A few reasons come to mind:

1. To what end?

mpv's extensibility is not meant as a platform to develop applications on, if you wish to develop applications using mpv, use libmpv. mpv's lua scripting is for automating small things and covering corner-cases, and essentially making it more configurable for the end user. So why would you bastardise this into an "application platform"?

2. Cost vs. Benefit

Since I (and many others) don't see the benefit, it goes without saying that whatever the cost, it's too high. Especially considering that this needlessly complicates the intended use-cases for mpv's Lua scripting.

3. Why not node.js

node.js is a horrible cargo-cult of people following the trend-of-the-month methodology of copy-pasting shit from stack overflow and medium blogs and throwing it up on npm, where it'll then be incorporated in a Jenga tower of dependencies for two-liners.

4. Out of scope

mpv's intended purpose is a video player, and a library using which video players can be built. It is not an application platform. There is no point in developing it into an application platform, considering people could just write an application using libmpv.

Already exists tons of libraries for building interfaces

mpv's express purpose is not to have a fully-featured interface, if you want a fully-featured interface, build a player around libmpv.

5. Your claims show a lack of knowledge about development in general

Simpler to develop: no compiling, no typing, etc

The current Lua scripting already doesn't need to be compiled. And static typing is a good thing, not a bad thing.

Platform and os independed: no gcc, qt, gtk, etc binaries: just compile mpv in pure c and lua (node.js) and run on my china 5$ arm-device.

mpv already has dependencies in the form of libass, ffmpeg and various other libraries, which need to be compiled too. mpv's requirement for a good GPU also means it won't properly work on your $5 piece of shit chinesium ARM board.

Use best-practices for building declarative pseudo-gui interfaces, i meant web/frontend development, js ecosystem, for example react-blessed.

You seem to believe that modern web-based interfaces are somehow "best-practices", when in reality they're extremely resource-hungry, slow, hacky, and have poor usability.

If you want to build an application around mpv, use libmpv. mpv itself will not provide you with an application platform though, that's just insane.

All 26 comments

That is not semi-crazy, it鈥檚 batshit insane.

No.

Why?

Isn't it a bit early for april fool's?

Why?

I'll give you the benefit of a doubt and assume you're not trolling (which is really hard to do).

A few reasons come to mind:

1. To what end?

mpv's extensibility is not meant as a platform to develop applications on, if you wish to develop applications using mpv, use libmpv. mpv's lua scripting is for automating small things and covering corner-cases, and essentially making it more configurable for the end user. So why would you bastardise this into an "application platform"?

2. Cost vs. Benefit

Since I (and many others) don't see the benefit, it goes without saying that whatever the cost, it's too high. Especially considering that this needlessly complicates the intended use-cases for mpv's Lua scripting.

3. Why not node.js

node.js is a horrible cargo-cult of people following the trend-of-the-month methodology of copy-pasting shit from stack overflow and medium blogs and throwing it up on npm, where it'll then be incorporated in a Jenga tower of dependencies for two-liners.

4. Out of scope

mpv's intended purpose is a video player, and a library using which video players can be built. It is not an application platform. There is no point in developing it into an application platform, considering people could just write an application using libmpv.

Already exists tons of libraries for building interfaces

mpv's express purpose is not to have a fully-featured interface, if you want a fully-featured interface, build a player around libmpv.

5. Your claims show a lack of knowledge about development in general

Simpler to develop: no compiling, no typing, etc

The current Lua scripting already doesn't need to be compiled. And static typing is a good thing, not a bad thing.

Platform and os independed: no gcc, qt, gtk, etc binaries: just compile mpv in pure c and lua (node.js) and run on my china 5$ arm-device.

mpv already has dependencies in the form of libass, ffmpeg and various other libraries, which need to be compiled too. mpv's requirement for a good GPU also means it won't properly work on your $5 piece of shit chinesium ARM board.

Use best-practices for building declarative pseudo-gui interfaces, i meant web/frontend development, js ecosystem, for example react-blessed.

You seem to believe that modern web-based interfaces are somehow "best-practices", when in reality they're extremely resource-hungry, slow, hacky, and have poor usability.

If you want to build an application around mpv, use libmpv. mpv itself will not provide you with an application platform though, that's just insane.

I'll give you the benefit of a doubt and assume you're not trolling (which is really hard to do).

Ok, thank you for the answer.

I am not a trolling, i am a web developer about 10 years and it's my IMHO as a frontend and backend developer. I just try to integrate small filemanager for playing music into mpv and using it in idle mode, it doesn't work properly.

I couldn't find how to use mpv as terminal output (only poor info about mp.osd_message) in mpv documentation, but osc.lua using smart libass kung-fu to drawing gui, including non-removable message at idle startap and logo.

My main intension was to force developers to organize and reuse his scripts. For example, use package managers and lua ecosystem and divide their scripts to separation-concern modules.

lua scripting is for automating small things and covering corner-cases

Looks like artificial restriction. You give to developers posibility to build pseudo-gui and it's not a "small things".

Look at mpv-progressbar, developers builds own highlevel ui toolkits on top of libass. It's good, but i can't reuse it without package manager or duplicating code and some bicycles. And it's not a small thing - it is a gui application, using mpv as output terminal.
All lua-developers reimplments some gui functions, such as drawing boxes, active zones, etc from script to script.

Look at most of all mpv-scripts: mpv-filenavigator, mpv-nextfile, simple-loader, they use posix commands to list directories and read files and it is os-dependend.

Some of them hardcodes "if" windows-detection. Some of them glues some scripts together

They totally use add_key_binding, 2, to bind script commands. And i can't use this commands via ipc, only through keypress command and it's wrong. Unnecessary abstraction on top of command, which breaks if hotkey redefined. Mpv lua api not give abstraction between lua script and keybindings.

I don't want to use mvp buildin osc.lua and i can't replace it to my filemanager. osc is separation concern mpv-plugin, mini-application, why it functionality hardcoded part of mpv?

Developers don't use package managers and libapr or mpv buildin lua api for it, they just do copy-paste and reimplements functionality from script to script.

Since I (and many others) don't see the benefit, it goes without saying that whatever the cost, it's too high.

Too high cost to embed luarocks, improving documentation and give 1-2 examples which demostrates it? Benefit? Deliver some tasks to script-developers community. You don't need to mantain lua-scipts, osc.lua can be side project, etc, just give posibilty.

node.js is a horrible cargo-cult of people following the trend-of-the-month methodology

I don't meant thousands of one-month micro-modules on npm. Today, we have typescript, angluar, react, redux, elm, atom ide + electron and many others long live projects with best practices for building complex uis, such as strong types, SOLID, component composition, jsx, livecycle hooks, data binding, reactive programming, best parctices from oop (angular2) and functional languages (elm), etc.

I don't want holywar. Lua not bad too, using node.js is not important intension. I mentioned node.js due to community. In my imagination one small team develops mpv core and huge community develops scripts and if 5% of them will be good and mantainable, it will be not bad.

of copy-pasting shit from stack overflow and medium blogs and throwing it up on npm, where it'll then be incorporated in a Jenga tower of dependencies for two-liners.

I meant top of npm, not one-day micromodules. Abot copypasting, copy-pasting is about 70% mpv lua scripts and it's not good too. I just want to reduce copypasting.

mpv's express purpose is not to have a fully-featured interface

Mpv core give access to libass and user input handlers. It's a base things for building full featured curses-like interfaces.
Mpv just gives posibility, mpv community decide to build fully-featured interface or not. mpv-progressbar and some others looks like a full featured interface: ui components, composition, mount hooks, mouse handlers.

The current Lua scripting already doesn't need to be compiled. And static typing is a good thing, not a bad thing.

Agree, i use static typing everywhere in web development. In my issue i meant lua as platform-independed language for building mpv-gui.

mpv already has dependencies in the form of libass, ffmpeg and various other libraries, which need to be compiled too. mpv's requirement for a good GPU also means it won't properly work on your $5 piece of shit chinesium ARM board.

Ok, not for $5 piece of shit, for piece of shit where mpv and ffmpeg works out of box and nothing else - no qt, gtk, xserver, etc. Ex., android platform, proprietary smarttv with own mpv builds, etc.

And everywhere on this pieces of shit we can run relatively full-featured libass ui interface without compiling and building something else, just embed package manager and simple libass gui for it to mpv.

You seem to believe that modern web-based interfaces are somehow "best-practices", when in reality they're extremely resource-hungry, slow, hacky, and have poor usability.

Ok, ok, only lua in mpv. But...

Resource-hungry? There are many micro frameworks for web-development, like preact, yo-yo.
Slow? They extremely fast. Bottle neck is browser.
Pure functions 1, 2 dependency injection are not hacky, js used for building native android apps.

Poor usability? What do you meant? Static checking, linting, ide integration with refactoring, scaffolding tools, developer tools 1 2, sites, using this libs?

But i meant not web-part of js, only small related libs, like blessed.

We don't use JS because there's no JS implementation that is as flexible for embedding as Lua, has a small footprint, and is free.

We don't provide a "GUI" toolkit because then we'd have to maintain a GUI toolkit.

What you want is to change the ecosystem of the mpv community towards something you are used (and learned to appreciate) from projects in the webdev space. This is bound to rub almost everyone of the existing mpv community the wrong way. I can see the benefit you imagine it to have, but I can not say that even the best case outcome will be worth the changes. If mpv was to include a JS dependency, there would be a no-JS fork of mpv within 3-4 nanoseconds.

I suggest you take the core of what you would like to have: Better GUI building and organisation of user scripts(?) and re-think how that could be achieved without huge changes or adding some cancerous growths to mpv. There are lots of ways this could be achieved.

Main idea is organisation of user scripts.

Second idea is abstraction from libass, not implementing js, etc. I mentioned web and js for example, it's my mistake.

I don't like libass, it's a bad engine for building uis. I can't find examples, documentation is poor, its specification looks incomplete.

Initially it subtitles rendering library: text with some whistleblowers. But you use it for building some simple ui components: osc, boxes, buttons, progress bars, icons, etc. If you plain grow mpv lua-scripts ecosystem, and using it for building great gui-related ecosystem around mpv it's not a good choice.

I think, good choice is to implement embeddable ui lib, like nuklear into mpv and render everthing ui-related, including subtitles and messages through it.

Hint: libass is not a UI engine. It's not even meant to render UIs.

  1. integrate luarocks. No more crap, semi-working,
    conflicting user scripts

This has never been a real problem.

  1. Add lua plugin api bus, each lua-plugin can provide some
    information about supported mpv version, description, etc.

I don鈥檛 see the benefit.

  1. Provide high-level ui toolkit with common api

Just use libmpv with Qt Quick/QML. It鈥檚 extremely easy to work with
and doesn鈥檛 require recompiling the application in order to change its UI.
You even get your beloved JavaScript. Trust me, it鈥檚 way better than anything
we could come up with in mpv.

There鈥檚 example code here:
https://github.com/mpv-player/mpv-examples/tree/master/libmpv

  1. Move osc.lua and ytdl_hook.lua to separate lurocks packages.

No. This is a major inconvenience to us and our users.

  1. Use best-practices for building declarative pseudo-gui interfaces

Just use QML.

  1. Provide documentation about api and examples

See libmpv.

I am not a trolling, i am a web developer about 10 years

Oh I鈥檓 sorry to hear that. The brain damage must be quite severe.

A tool to update user scripts would be nice, but I don't think we want to use luarocks for that. I doubt luarocks is suitable for plugin-like scripts anyway.

A tool to update user scripts would be nice, but I don't think we want to use luarocks for that. I doubt luarocks is suitable for plugin-like scripts anyway.

Yes, if only we had some something like git or package managers

@wm4

Absolutely agree, libass is not a UI engine. But used in mpv and related scripts as low-level ui rendering engine.

In mpv osc.lua you using buttons, bars, and other ui-controls for human interaction, it's ui. Used mp.set_osd_ass.

simple-loader

draw_dir - proto ui component, it using colors formating dir list and pass formatted string to mp.osd_message.

mpv-progressbar

This complex app has buildin ui framework: ui elements, zones, event loops, hooks, looks like 5-6 yeas old marionette library, it's oldschool, but it's highlevel ui toolkit. It using mp.set_osd_ass for positional element rendering.

@haasn

I meant embeded tool with simple interface for end-user, like kodi addons installer in kodi itself

Yes, if only we had some something like git or package managers

Not sure how that can help updating files in ~/.config/mpv/scripts/ that the user downloaded from random sources.

Absolutely agree, libass is not a UI engine. But used in mpv and related scripts as low-level ui rendering engine.

Which is why using it is at most an inofficial feature. It's not documented or encouraged. We use it in osc.lua because of it saves us from requiring complex dependencies.

Also please change your avatar, it's the fucking ugliest I've seen yet.

So this is slowly taking shape and now boils down to:

  • libass being used for UI rendering in lua.osc is not ideal
  • There is no centralised way to update user scripts besides the source repo
  • You want to replace this solution with something the user can interact with through the UI

Correct?

@lamarpavel
Yes, correct.

@wm4
Sorry for avatar.

Not sure how that can help updating files in ~/.config/mpv/scripts/ that the user downloaded from random sources.

Well I can only speak for myself, but all of the scripts I downloaded are either from a git repo or a gist, both of which can be updated by using git pull.

@zerkalica

simple-loader
draw_dir - proto ui component, it using colors formating dir list and pass formatted string to mp.osd_message.

Just as an example, as long as you mentioned my script.
I made it for my personal case -- to lauch videos on my HTPC box with MCE IR remote only, without hell of DMs, WMs, Kodies, keyboards or mices. It took me several days from learning some Lua at lua.org from zero to having a working script -- provided that I'm a full-time accountant, not a coder. And I don't even add scrolling to it because a) I actually don't need it much, and b) coding scrollings is kinda beyond my Lua skills at the moment. Honestly, I wish I could learn how to create such things with Qt or "application platform", but have neither time nor energy for that (and wouldn't till retirement, I'm afraid).
What I'm saying is that if your proposed changes will allow doing more useful things in the same simple way -- I'd say such changes quite may have some value. But if the only output will be that I will have to learn Qt -- then I object it, sorry.

@fhlfibh

to lauch videos on my HTPC box with MCE IR remote only

Yes, a talking about osd ui, embeddable, simple, ir-remotes oriented ui toolkit. That looks fine on tv screen.

without hell of DMs, WMs, Kodies, keyboards or mices

On my system i launch xserver, mpv, lirc and nothing else.

I wish I could learn how to create such things with Qt or "application platform"

Qt is good for full featured gui. But too fat relatively nuklear, imgui, libui, fltk, etc.
IMHO, this is not necessary for building slim gui for tv screen and ir-remote.

How to use qt widgets in osd inside mpv? I need only osd gui, mpv has no protocol or interface for rendering uis in osd.

That's the point you don't get: the OSD is not supposed to be used as GUI/for complex GUIs with user interaction. Libass is not the right choice for UIs. It is slow and leads to framedrops.

How to use qt widgets in osd inside mpv?

There are libmpv examples that demonstrate how to put QML widgets over the video. For classic Qt widgets it's much more complex.

Just to clarify: that would never work with plain mpv, just UIs which use libmpv as backend.

@zerkalica
Sorry, but personally I still don't actually understand what improvements your proposed changes should bring to _ordinary users_ (i.e. me)...

Ok. I don't know about libmpv osd rendering. I try to investigate this.

I investigate libmpv examples, how to abstract application from video output: opengl, sdl, vdpau? Just framebuffer needed. Mpv uses sdl, drm, va and provides abstraction for lua-scripts, but not libmpv. May be some external libraries?

Was this page helpful?
0 / 5 - 0 ratings

Related issues

lightonflux picture lightonflux  路  4Comments

yuvadm picture yuvadm  路  3Comments

laichiaheng picture laichiaheng  路  3Comments

ghost picture ghost  路  3Comments

532910 picture 532910  路  3Comments