"""Side-by-side of option encodes: source | 32X baseline (320, 25 fps, 675 B/f) | option. Option 2 (12.5 fps) plays each frame twice as long; option 3 (narrower) is centred with black borders, as the 32X would show it. Animated WebP at 25 fps. py -3.12 study/preview_opts.py out32/c1v_0 out32/opt2_0 out32/preview_opt2_0 "12.5 fps, 1,350 B/f" """ import json import sys from pathlib import Path import numpy as np from PIL import Image, ImageDraw sys.path.insert(0, str(Path(__file__).resolve().parents[1])) from rrmd.encode import load_picture # noqa: E402 FIELDS = Path(r"D:\dev\rick-roll-md\fields") LH = 16 def panel(img, text): im = Image.new("RGB", (320, 224 + LH)) x = (320 - img.shape[1]) // 2 im.paste(Image.fromarray(img), (x, LH)) ImageDraw.Draw(im).text((4, 2), text, fill=(255, 255, 255)) return im base, opt, out, label = Path(sys.argv[1]), Path(sys.argv[2]), Path(sys.argv[3]), sys.argv[4] out.mkdir(parents=True, exist_ok=True) sb = json.loads((base / "summary.json").read_text()) so = json.loads((opt / "summary.json").read_text()) step = so.get("step", 1) paths = sorted(FIELDS.glob("f*.png")) frames = [] shown = None for i in range(sb["first"], sb["first"] + sb["count"]): if (i - so["first"]) % step == 0 and (opt / "expected" / f"e{i:05d}.png").exists(): shown = np.asarray(Image.open(opt / "expected" / f"e{i:05d}.png").convert("RGB")) sheet = Image.new("RGB", (960, 224 + LH)) sheet.paste(panel(load_picture(paths[i]), f"source {i}"), (0, 0)) sheet.paste(panel(np.asarray(Image.open(base / "expected" / f"e{i:05d}.png").convert("RGB")), "32X 320 wide, 25 fps, 675 B/f"), (320, 0)) sheet.paste(panel(shown, "32X " + label), (640, 0)) if (i - sb["first"]) % 75 == 0: sheet.save(out / f"s{i:05d}.png") frames.append(sheet) frames[0].save(out / "preview.webp", save_all=True, append_images=frames[1:], duration=40, loop=0, quality=90, method=4) print(out / "preview.webp")