111
111
112
112
113
113
function do_worker_job (state_json_string , frames_json_string )
114
+ msg .debug (" Handling given job" )
114
115
local thumb_state , err = utils .parse_json (state_json_string )
115
116
if err then
116
117
msg .error (" Failed to parse state JSON" )
@@ -128,23 +129,28 @@ function do_worker_job(state_json_string, frames_json_string)
128
129
if ExecutableFinder :get_executable_path (" ffmpeg" ) then
129
130
thumbnail_func = create_thumbnail_ffmpeg
130
131
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." )
132
133
end
133
134
end
134
135
135
136
local file_duration = mp .get_property_native (" duration" )
136
137
local file_path = thumb_state .worker_input_path
137
138
138
139
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
139
143
thumbnail_func = create_thumbnail_mpv
140
144
end
141
145
142
146
local generate_thumbnail_for_index = function (thumbnail_index )
143
147
-- 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 )
144
150
145
- local thumbnail_path = thumb_state .thumbnail_template :format (thumbnail_index - 1 )
151
+ local thumbnail_path = thumb_state .thumbnail_template :format (thumb_idx )
146
152
-- 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 )
148
154
149
155
mp .commandv (" script-message" , " mpv_thumbnail_script-progress" , tostring (thumbnail_index ))
150
156
@@ -161,7 +167,7 @@ function do_worker_job(state_json_string, frames_json_string)
161
167
local existing_thumbnail_filesize = thumbnail_file :seek (" end" )
162
168
if existing_thumbnail_filesize ~= thumbnail_raw_size then
163
169
-- 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" )
165
171
need_thumbnail_generation = true
166
172
end
167
173
thumbnail_file :close ()
@@ -173,12 +179,15 @@ function do_worker_job(state_json_string, frames_json_string)
173
179
174
180
if success == nil then
175
181
-- Killed by us, changing files, ignore
182
+ msg .debug (" Changing files, subprocess killed" )
176
183
return true
177
184
elseif not success then
178
- -- Failure
185
+ -- Real failure
179
186
mp .osd_message (" Thumbnailing failed, check console for details" , 3.5 )
180
187
return true
181
188
end
189
+ else
190
+ msg .debug (" Thumbnail" , thumb_idx , " already done!" )
182
191
end
183
192
184
193
-- Verify thumbnail size
@@ -207,19 +216,21 @@ function do_worker_job(state_json_string, frames_json_string)
207
216
thumbnail_file :close ()
208
217
end
209
218
219
+ msg .debug (" Finished work on thumbnail" , thumb_idx )
210
220
mp .commandv (" script-message" , " mpv_thumbnail_script-ready" , tostring (thumbnail_index ), thumbnail_path )
211
221
end
212
222
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
-
218
223
msg .debug ((" Generating %d thumbnails @ %dx%d for %q" ):format (
219
224
# thumbnail_indexes ,
220
225
thumb_state .thumbnail_size .w ,
221
226
thumb_state .thumbnail_size .h ,
222
227
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
+
223
234
end
224
235
225
236
-- Set up listeners and keybinds
0 commit comments