Skip to content

Commit 2da8546

Browse files
committed
Improve thumbnail feel with a half-offset
Previously, thumbnails were created precisely on the mark. Thumbnail 1 (0) would be at 0 seconds, thumbnail 2 at 5 seconds, 3 at 10 etc. This meant that when the user hovered over a thumbnail, it was already a past event. This felt off, because the visible thumbnail was never properly accurate. Now, we take thumbnails half a delta later. Thumbnail 1 will be at 2.5 seconds, 2 at 7.5, 3 at 12.5. This means that when moving the mouse from left to right, the thumbnail changes 2.5 seconds "before" the the thumbnailed timestamp. The thumbnail is no longer guaranteed to be a past event, and feels much better. A random flick towards the seekbar means a 50% chance that the seek will be before the displayed moment. We *could* always generate/display the "next" moment (1 = 5s, 2 = 10s, etc), but this sort of offset feels slightly wrong as well. For now, we'll make do with the 50% offset. Fixes #7.
1 parent a73afc0 commit 2da8546

File tree

2 files changed

+4
-3
lines changed

2 files changed

+4
-3
lines changed

src/thumbnailer_server.lua

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -177,8 +177,9 @@ function do_worker_job(state_json_string, frames_json_string)
177177
local generate_thumbnail_for_index = function(thumbnail_index)
178178
-- Given a 1-based thumbnail index, generate a thumbnail for it based on the thumbnailer state
179179

180-
local thumbnail_path = thumb_state.thumbnail_template:format(thumbnail_index - 1)
181-
local timestamp = math.min(file_duration, (thumbnail_index - 1) * thumb_state.thumbnail_delta)
180+
local thumbnail_path = thumb_state.thumbnail_template:format(thumbnail_index-1)
181+
-- Grab the "middle" of the thumbnail duration instead of the very start, and leave some margin in the end
182+
local timestamp = math.min(file_duration - 0.25, (thumbnail_index - 1 + 0.5) * thumb_state.thumbnail_delta)
182183

183184
mp.commandv("script-message", "mpv_thumbnail_script-progress", tostring(thumbnail_index))
184185

src/thumbnailer_shared.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ function Thumbnailer:get_thumbnail_count(delta)
183183
end
184184
local file_duration = mp.get_property_native("duration")
185185

186-
return math.floor(file_duration / delta)
186+
return math.ceil(file_duration / delta)
187187
end
188188

189189
function Thumbnailer:get_closest(thumbnail_index)

0 commit comments

Comments
 (0)