better autocorrect for poor ffmpeg builds

This commit is contained in:
ed 2022-09-20 23:25:35 +02:00
parent 9d2e390b6a
commit f1e0c44bdd
2 changed files with 21 additions and 11 deletions

View file

@ -45,7 +45,7 @@ class Ico(object):
pb = ImageDraw.Draw(img) pb = ImageDraw.Draw(img)
tw, th = pb.textsize(ext) tw, th = pb.textsize(ext)
pb.text(((w - tw) // 2, (h - th) // 2), ext, fill="#" + c[6:]) pb.text(((w - tw) // 2, (h - th) // 2), ext, fill="#" + c[6:])
img = img.resize((w * 3, h * 3), Image.Resampling.NEAREST) img = img.resize((w * 3, h * 3), Image.NEAREST)
buf = BytesIO() buf = BytesIO()
img.save(buf, format="PNG", compress_level=1) img.save(buf, format="PNG", compress_level=1)

View file

@ -266,13 +266,14 @@ class ThumbSrv(object):
if fun: if fun:
try: try:
fun(abspath, tpath) fun(abspath, tpath)
except: except Exception as ex:
msg = "{} could not create thumbnail of {}\n{}" msg = "{} could not create thumbnail of {}\n{}"
msg = msg.format(fun.__name__, abspath, min_ex()) msg = msg.format(fun.__name__, abspath, min_ex())
c: Union[str, int] = 1 if "<Signals.SIG" in msg else "1;30" c: Union[str, int] = 1 if "<Signals.SIG" in msg else "1;30"
self.log(msg, c) self.log(msg, c)
with open(tpath, "wb") as _: if getattr(ex, "returncode", 0) != 321:
pass with open(tpath, "wb") as _:
pass
with self.mutex: with self.mutex:
subs = self.busy[tpath] subs = self.busy[tpath]
@ -418,21 +419,30 @@ class ThumbSrv(object):
c: Union[str, int] = "1;30" c: Union[str, int] = "1;30"
t = "FFmpeg failed (probably a corrupt video file):\n" t = "FFmpeg failed (probably a corrupt video file):\n"
if cmd[-1].lower().endswith(b".webp") and ( if (
"Error selecting an encoder" in serr (not self.args.th_ff_jpg or time.time() - int(self.args.th_ff_jpg) < 60)
or "Automatic encoder selection failed" in serr and cmd[-1].lower().endswith(b".webp")
or "Default encoder for format webp" in serr and (
or "Please choose an encoder manually" in serr "Error selecting an encoder" in serr
or "Automatic encoder selection failed" in serr
or "Default encoder for format webp" in serr
or "Please choose an encoder manually" in serr
)
): ):
self.args.th_ff_jpg = True self.args.th_ff_jpg = time.time()
t = "FFmpeg failed because it was compiled without libwebp; enabling --th-ff-jpg to force jpeg output:\n" t = "FFmpeg failed because it was compiled without libwebp; enabling --th-ff-jpg to force jpeg output:\n"
ret = 321
c = 1 c = 1
if ( if (
not self.args.th_ff_swr or time.time() - int(self.args.th_ff_swr) < 60
) and (
"Requested resampling engine is unavailable" in serr "Requested resampling engine is unavailable" in serr
or "output pad on Parsed_aresample_" in serr or "output pad on Parsed_aresample_" in serr
): ):
t = "FFmpeg failed because it was compiled without libsox; you must set --th-ff-swr to force swr resampling:\n" self.args.th_ff_swr = time.time()
t = "FFmpeg failed because it was compiled without libsox; enabling --th-ff-swr to force swr resampling:\n"
ret = 321
c = 1 c = 1
lines = serr.strip("\n").split("\n") lines = serr.strip("\n").split("\n")