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

set default values of 'duration', 'max_duration' and 'file_duration' to 0 if it is nil for avoid errors when performing arithmetic operations #76

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
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
3 changes: 2 additions & 1 deletion src/thumbnailer_server.lua
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ function do_worker_job(state_json_string, frames_json_string)
end

local file_duration = mp.get_property_native("duration")
if file_duration == nil then file_duration = 0 end
local file_path = thumb_state.worker_input_path

if thumb_state.is_remote then
Expand Down Expand Up @@ -270,4 +271,4 @@ register_timer = mp.add_periodic_timer(0.1, register_function)
mp.register_script_message("mpv_thumbnail_script-slaved", function()
msg.debug("Successfully registered with master")
register_timer:stop()
end)
end)
4 changes: 4 additions & 0 deletions src/thumbnailer_shared.lua
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,7 @@ end
function Thumbnailer:get_delta()
local file_path = mp.get_property_native("path")
local file_duration = mp.get_property_native("duration")
if file_duration == nil then file_duration = 0 end
local is_seekable = mp.get_property_native("seekable")

-- Naive url check
Expand Down Expand Up @@ -202,6 +203,7 @@ function Thumbnailer:get_thumbnail_count(delta)
return 0
end
local file_duration = mp.get_property_native("duration")
if file_duration == nil then file_duration = 0 end

return math.ceil(file_duration / delta)
end
Expand Down Expand Up @@ -278,7 +280,9 @@ function Thumbnailer:register_client()
-- This will be executed after the on_video_change (because it's registered after it)
mp.observe_property("video-dec-params", "native", function()
local duration = mp.get_property_native("duration")
if duration == nil then duration = 0 end
local max_duration = thumbnailer_options.autogenerate_max_duration
if max_duration == nil then max_duration = 0 end

if duration ~= nil and self.state.available and thumbnailer_options.autogenerate then
-- Notify if autogenerate is on and video is not too long
Expand Down