Skip to content
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

Storyboard fixes #25

Merged
merged 9 commits into from
Nov 3, 2022
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
allow upscaling storyboards
ftk committed Jul 27, 2022
commit c3404967354ba27887393ce7c72ed7ea3576b0fc
2 changes: 2 additions & 0 deletions src/options.lua
Original file line number Diff line number Diff line change
@@ -123,6 +123,8 @@ local thumbnailer_options = {
storyboard_enable = true,
-- Max thumbnails for storyboards. It only skips processing some of the downloaded thumbnails and doesn't make it much faster
storyboard_max_thumbnail_count = 800,
-- Most storyboard thumbnails are 160x90. Enabling this allows upscaling them up to thumbnail_height
storyboard_upscale = false,
}

read_options(thumbnailer_options, SCRIPT_NAME)
16 changes: 11 additions & 5 deletions src/thumbnailer_server.lua
Original file line number Diff line number Diff line change
@@ -55,7 +55,9 @@ function create_thumbnail_mpv(file_path, timestamp, size, output_path, options)
-- Optionally disable subtitles
(thumbnailer_options.mpv_no_sub and "--no-sub" or nil),

(options.no_scale == nil and ("--vf=scale=%d:%d"):format(size.w, size.h) or nil),
(options.relative_scale == nil
and ("--vf=scale=%d:%d"):format(size.w, size.h)
or ("--vf=scale=iw*%d:ih*%d"):format(size.w, size.h)),

"--vf-add=format=bgra",
"--of=rawvideo",
@@ -69,7 +71,7 @@ end
function create_thumbnail_ffmpeg(file_path, timestamp, size, output_path, options)
options = options or {}

local ffmpeg_command = skip_nil({
local ffmpeg_command = {
"ffmpeg",
"-loglevel", "quiet",
"-noaccurate_seek",
@@ -79,13 +81,17 @@ function create_thumbnail_ffmpeg(file_path, timestamp, size, output_path, option
"-frames:v", "1",
"-an",

(options.no_scale == nil and "-vf" or nil), (options.no_scale == nil and ("scale=%d:%d"):format(size.w, size.h) or nil),
"-vf",
(options.relative_scale == nil
and ("scale=%d:%d"):format(size.w, size.h)
or ("scale=iw*%d:ih*%d"):format(size.w, size.h)),

"-c:v", "rawvideo",
"-pix_fmt", "bgra",
"-f", "rawvideo",

"-y", output_path
})
}
return utils.subprocess({args=ffmpeg_command})
end

@@ -225,7 +231,7 @@ function do_worker_job(state_json_string, frames_json_string)
if url == nil then
url = thumb_state.storyboard.fragment_base_url .. "/" .. thumb_state.storyboard.fragments[atlas_idx+1].path
end
local ret = thumbnail_func(url, 0, thumb_state.thumbnail_size, atlas_path, { no_scale=true })
local ret = thumbnail_func(url, 0, { w=thumb_state.storyboard.scale, h=thumb_state.storyboard.scale }, atlas_path, { relative_scale=true })
success = check_output(ret, atlas_path, thumbnail_func == create_thumbnail_mpv)
if success then
split_atlas(atlas_path, cols, thumb_state.thumbnail_size, function(idx)
12 changes: 11 additions & 1 deletion src/thumbnailer_shared.lua
Original file line number Diff line number Diff line change
@@ -108,7 +108,7 @@ function Thumbnailer:check_storyboard_async(callback)
self.state.storyboard.fragment_base_url = sb.fragment_base_url
self.state.storyboard.rows = sb.rows or 5
self.state.storyboard.cols = sb.columns or 5
self.state.thumbnail_size = {w=sb.width, h=sb.height}

if sb.fps then
self.state.thumbnail_count = math.floor(sb.fps * sb.duration + 0.5) -- round
-- hack: youtube always adds 1 black frame at the end...
@@ -122,6 +122,16 @@ function Thumbnailer:check_storyboard_async(callback)
self.state.thumbnail_count = math.floor(sb.duration / self.state.thumbnail_delta)
end

-- Storyboard upscaling factor
local scale = 1
if thumbnailer_options.storyboard_upscale then
-- BUG: sometimes mpv crashes when asked for non-integer scaling and BGRA format (something related to zimg?)
-- use integer scaling for now
scale = math.max(1, math.floor(thumbnailer_options.thumbnail_height / sb.height))
end
self.state.thumbnail_size = {w=sb.width*scale, h=sb.height*scale}
self.state.storyboard.scale = scale

local divisor = 1 -- only save every n-th thumbnail
if thumbnailer_options.storyboard_max_thumbnail_count then
divisor = math.ceil(self.state.thumbnail_count / thumbnailer_options.storyboard_max_thumbnail_count)