Skip to content

Commit

Permalink
Improve thumbnail feel with a half-offset
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
TheAMM committed Jan 3, 2018
1 parent a73afc0 commit 2da8546
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
5 changes: 3 additions & 2 deletions src/thumbnailer_server.lua
Original file line number Diff line number Diff line change
Expand Up @@ -177,8 +177,9 @@ function do_worker_job(state_json_string, frames_json_string)
local generate_thumbnail_for_index = function(thumbnail_index)
-- Given a 1-based thumbnail index, generate a thumbnail for it based on the thumbnailer state

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

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

Expand Down
2 changes: 1 addition & 1 deletion src/thumbnailer_shared.lua
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ function Thumbnailer:get_thumbnail_count(delta)
end
local file_duration = mp.get_property_native("duration")

return math.floor(file_duration / delta)
return math.ceil(file_duration / delta)
end

function Thumbnailer:get_closest(thumbnail_index)
Expand Down

0 comments on commit 2da8546

Please sign in to comment.