-
Notifications
You must be signed in to change notification settings - Fork 70
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: render thumbnails on uosc side #353
base: main
Are you sure you want to change the base?
Conversation
If we end up going down this route it would make sense to send the updated time to thumbfast in a |
2c58823
to
74c9a43
Compare
Rebased on master and cleaned up commits. Waiting for ideas on how to implement this in a less silly way. @tomasklaen |
Fine, I didn't notice I was using this PR before. |
So if I understand it correctly, when we send In any case, I can see how requesting thumbnail inside Thumbfast informs uosc about thumbnail dimensions via
function Timeline:set_thumbnail(path)
self.thumbnail_path = path
request_render()
end And inside
This way we don't have to pass dimensions, coordinates, and other stuff back and forth and parse json on every thumbnail change. We just need the path to the thumbnail. Does this sound good? Or am I missing something? |
The dimension of the thumbnail can change over time. In theory every thumbnail can have a different dimension (we calculate the real thumbnail dimension each time a file got generated), so the size certainly has to be part of |
99.9% time it'll be the same no? So just send |
Sure, I just don't see the upside in having two separate messages for path and dimensions. function(width, height, path)
width = tonumber(width)
height = tonumber(height)
...
end The path parameter can be optional. When using client rendering it sends the path, otherwise it only sends the dimensions. That would be a breaking change to the API, but since there hasn't been a release yet, I don't think anyone expects a stable API yet. |
I don't understand this proposition, since the thumbnail path is unchanging for the current instance. The thing we do need to update is accurate dimensions, and it's required that uosc knows the exact size of the thumbnail, else in the case that it thinks the thumbnail resolution is higher than it actually is, The reason it currently uses a single JSON argument instead of multiple string ones is to not burden clients with more state management logic than is necessary. That's less relevant in a script that uses the full render control feature, I suppose. If the idea of skipping JSON parsing is from a performance concern, We can get rid of the |
Ah sorry, I assumed the path changes to prevent some potential caching. Too much web dev in my life. So, how often do dimensions change? Is there some noise where thumbnails differ from the previous by 1px or something? If there's no noise and thumbnail dimensions change happens only on new files, or weird videos that change size sometimes, than I guess the best would be to just have these messages: Receiving:
Sending:
I think that's all that UI needs to implement thumbnails. Any issues with this? For example, does mpv guarantee that the order of received messages matches the order in which they were sent? It'd be bad if |
I did some testing on this a while back and the messages were always received in the correct order, but I don't think there is any guarantee for that in the documentation, so that may change in the future. Afaik po5 would like to implement caching at some point, so the path will always change when a different thumbnail should be displayed. Sending a |
All right, but since it's not just info, but also a call to render now, lets name it something like:
|
@po5 so where do you stand on this? Is this API something you'd implement? Thumbfast receiving:
Thumbfast sending:
Thumbnail cleaning can than happen in the background on file close. |
I am worried about how easy it may be to crash the player with the overlay managed by the UI, and how related bugfixes may have to be implemented in each UI script instead of just thumbfast. I've only had the player crash once under normal conditions with this really naive implementation despite much fooling around on random videos, but it's enough for me to believe that thumbfast's -- in thumbfast.lua draw()
mp.commandv("script-message-to", "uosc", "thumbfast-thumbnail", options.thumbnail..".bgra", display_w, display_h, (4*display_w)) -- in uosc.lua
mp.register_script_message('thumbfast-thumbnail', function(path, width, height, stride)
mp.command_native({"overlay-add", 12, 0, 0, path, 0, "bgra", width, height, stride})
end) In reality a UI script wouldn't be calling The solution that doesn't involve somehow injecting code from thumbfast into the UI would be to write each thumbnail to its own file, and only tell the UI about thumbnails after they've passed the I think this is the less dumb approach, it does introduce some latency to displaying the thumbnail (script-message dispatch + UI script render loop), but that's necessary if we want synced ASS and overlay updates. An idea I had very early on was to have UI script send thumbfast its desired border styling (any arbitrary ASS), which would solve our issue but it introduces friction and may not fit all use cases. I propose this API. thumbfast replies: When a thumbnail needs to be hidden, the UI script calls This requires minimal additions to existing scripts. |
The problem I see with that is that unless you wait between sending seek commands until the new file is written out, there is no way of knowing to which timestamp that new file belongs. I suspect that waiting between requests will make the thumbnail generation noticeably slower, so that seems rather counterproductive for timeline thumbnails. Also if thumbfast develops in to a more general thumbnail provider it would make sense to differentiate between fast and exact seeks in the request, because both can be useful depending on the application. Regarding cleanup I don't think it's a problem to keep all thumbnail files around until mpv exits, because those files are pretty small anyway. As long as those thumbnails get stored in a ram disk (like they already are afaik) there is no need to deal with unclean shutdowns. |
Not all distros have |
Seems fine to me. And yes, |
Idea for dealing with unclean shutdowns: thumbfast stores its thumbnails in a directory with the current process id. |
I've isolated what causes the occasional thumbnail/thumbnail border desync.
It's not a performance problem of either thumbfast or uosc.
It's simply because the two don't update at the same time.
I had anticipated this and provided the
thumbfast-render
script message for those who wanted to implement it.Turns out it was unusable because mpv wouldn't let you pass the arguments it expects, and the clear command would remove the overlay straight away (undesirable in script render mode).
With these issues fixed, I've implemented it (in a hacky way) in uosc.
What this does is move all thumbnail and border rendering to
render()
.That way, the overlay is always updated at the same time (or as close to it as mpv will allow) as its border.
This seems to fix any lags between the two elements on my end, be it when moving really fast or when clearing the thumbnail.
Make sure you are on the latest thumbfast commit.
Is this something you would consider doing, or are you fine with the current slightly inaccurate thumbnails with a simpler implementation?