111111
112112
113113function do_worker_job (state_json_string , frames_json_string )
114+ msg .debug (" Handling given job" )
114115 local thumb_state , err = utils .parse_json (state_json_string )
115116 if err then
116117 msg .error (" Failed to parse state JSON" )
@@ -128,23 +129,28 @@ function do_worker_job(state_json_string, frames_json_string)
128129 if ExecutableFinder :get_executable_path (" ffmpeg" ) then
129130 thumbnail_func = create_thumbnail_ffmpeg
130131 else
131- msg .warning (" Could not find ffmpeg in PATH! Falling back on mpv." )
132+ msg .warn (" Could not find ffmpeg in PATH! Falling back on mpv." )
132133 end
133134 end
134135
135136 local file_duration = mp .get_property_native (" duration" )
136137 local file_path = thumb_state .worker_input_path
137138
138139 if thumb_state .is_remote then
140+ if (thumbnail_func == create_thumbnail_ffmpeg ) then
141+ msg .warn (" Thumbnailing remote path, falling back on mpv." )
142+ end
139143 thumbnail_func = create_thumbnail_mpv
140144 end
141145
142146 local generate_thumbnail_for_index = function (thumbnail_index )
143147 -- Given a 1-based thumbnail index, generate a thumbnail for it based on the thumbnailer state
148+ local thumb_idx = thumbnail_index - 1
149+ msg .debug (" Starting work on thumbnail" , thumb_idx )
144150
145- local thumbnail_path = thumb_state .thumbnail_template :format (thumbnail_index - 1 )
151+ local thumbnail_path = thumb_state .thumbnail_template :format (thumb_idx )
146152 -- Grab the "middle" of the thumbnail duration instead of the very start, and leave some margin in the end
147- local timestamp = math.min (file_duration - 0.25 , (thumbnail_index - 1 + 0.5 ) * thumb_state .thumbnail_delta )
153+ local timestamp = math.min (file_duration - 0.25 , (thumb_idx + 0.5 ) * thumb_state .thumbnail_delta )
148154
149155 mp .commandv (" script-message" , " mpv_thumbnail_script-progress" , tostring (thumbnail_index ))
150156
@@ -161,7 +167,7 @@ function do_worker_job(state_json_string, frames_json_string)
161167 local existing_thumbnail_filesize = thumbnail_file :seek (" end" )
162168 if existing_thumbnail_filesize ~= thumbnail_raw_size then
163169 -- Size doesn't match, so (re)generate
164- msg .warn (" Thumbnail" , thumbnail_index - 1 , " did not match expected size, regenerating" )
170+ msg .warn (" Thumbnail" , thumb_idx , " did not match expected size, regenerating" )
165171 need_thumbnail_generation = true
166172 end
167173 thumbnail_file :close ()
@@ -173,12 +179,15 @@ function do_worker_job(state_json_string, frames_json_string)
173179
174180 if success == nil then
175181 -- Killed by us, changing files, ignore
182+ msg .debug (" Changing files, subprocess killed" )
176183 return true
177184 elseif not success then
178- -- Failure
185+ -- Real failure
179186 mp .osd_message (" Thumbnailing failed, check console for details" , 3.5 )
180187 return true
181188 end
189+ else
190+ msg .debug (" Thumbnail" , thumb_idx , " already done!" )
182191 end
183192
184193 -- Verify thumbnail size
@@ -207,19 +216,21 @@ function do_worker_job(state_json_string, frames_json_string)
207216 thumbnail_file :close ()
208217 end
209218
219+ msg .debug (" Finished work on thumbnail" , thumb_idx )
210220 mp .commandv (" script-message" , " mpv_thumbnail_script-ready" , tostring (thumbnail_index ), thumbnail_path )
211221 end
212222
213- for i , thumbnail_index in ipairs (thumbnail_indexes ) do
214- local bail = generate_thumbnail_for_index (thumbnail_index )
215- if bail then return end
216- end
217-
218223 msg .debug ((" Generating %d thumbnails @ %dx%d for %q" ):format (
219224 # thumbnail_indexes ,
220225 thumb_state .thumbnail_size .w ,
221226 thumb_state .thumbnail_size .h ,
222227 file_path ))
228+
229+ for i , thumbnail_index in ipairs (thumbnail_indexes ) do
230+ local bail = generate_thumbnail_for_index (thumbnail_index )
231+ if bail then return end
232+ end
233+
223234end
224235
225236-- Set up listeners and keybinds
0 commit comments