Something went wrong. Try again.
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899"""Per-shot keyframe prompts → keyframes.json (the input of scripts/kfreq.py, vidreq.py and roughcut.py).
Each shot lists the characters to attach (`cast`) and a scene description of its first frame; shots with a cameramove or action also get an end frame (and optional in-between frames). The shared style, every character's look inwords, the set layout, continuity values and prop scales are appended here, so every prompt restates the designs.
python3 examples/keyframes_template.py [--shots shots.json] [--out keyframes.json]
shots.json (from scripts/retime.py) is a list of {id, t0, t1, dur, lyric}; without it, placeholder timings are used."""import argparse, json, pathlib
ROOT = pathlib.Path(__file__).resolve().parentap = argparse.ArgumentParser()ap.add_argument("--shots", default=ROOT / "shots.json", type=pathlib.Path)ap.add_argument("--out", default=ROOT / "keyframes.json", type=pathlib.Path)args = ap.parse_args()
# Character code -> (reference name in the image tool, the words every prompt repeats for them). From the style bible.CAST = { "L": ("Lead (singer)", "the lead singer: tall, curly red hair, round glasses, mustard corduroy jacket over a white tee, " "black jeans, white sneakers, absolutely NO necktie"), "D": ("Drummer", "the drummer: woman in her 50s, silver buzz cut, green work shirt with rolled sleeves"), "P": ("Puppet", "the hand puppet: a crisp-edged flat blue slab about 1.4 times as wide as tall, NOT a cube and not plush, " "two small square black eyes set high and wide, NO mouth, NO legs, worked from below on a puppeteer's " "hand with a black sleeve visible, loaf-of-bread sized"),}# Recurring props: keyword -> (reference name, scale sentence). Auto-attached when a scene mentions the keyword.PROPS = { "lamp": ("Prop: desk lamp", "the desk lamp is a green-shaded brass desk lamp about 45 cm tall"), "gauge": ("Prop: stage gauge", "the gauge is a 2.5 m tall painted stage gauge (taller than a door) with percentage " "labels every 10 % and a red column"),}# Fixed layout sentences for recurring sets, appended to every shot on that set.LAYOUT = { "workshop": ("S02 S03", "Workshop layout, identical in every workshop shot: the workbench centred against the back wall, " "the desk lamp at its left end, a pegboard of tools above it, a tall window on the right"),}# Continuity values per shot (e.g. a gauge that only rises): written into the prompt as an exact value.GAUGE = {"S03": 10}# Extra reference images per frame id, uploaded and attached by the worker (inspiration photos, earlier frames).UPLOADS = {"S01": ["inspiration/stage.jpg"]}STYLE = ("Live-action still frame from a practical music video, 16:9. Hand-built, brightly painted set; practical puppets " "with visible felt/foam texture; real camera, 35mm, nothing CGI. No captions, no subtitles, no logos.")
K = {} # shot id -> (cast codes, start scene, end scene or None, camera move/action or None, in-between scenes)def shot(sid, cast, start, end=None, move=None, mids=()): K[sid] = (cast.split(), start, end, move, list(mids))
# ---- placeholder shots: replace with the storyboardshot("S01", "L D", "A dark theatre stage in front of closed red velvet curtains; one spotlight on the curtain seam; the lead " "singer's white sneakers visible under the curtain hem.")shot("S02", "L P", "The workshop at night: the lead singer bent over the workbench under the desk lamp, a cardboard box on the bench.", "Same framing, slightly closer: the hand puppet has popped up out of the box, arms out; the lead singer leans back, startled.", "slow push-in; the puppet pops up on the downbeat")shot("S03", "L P D", "The workshop: the drummer taps a rhythm on the workbench, the puppet sways on the lead singer's hand, the gauge on the wall.", "The same scene from the right: all three dance in a line past the window.", "camera arcs right around the bench", mids=["The camera has arced halfway: the three turn toward the window, mid-step."])
if args.shots.exists(): SHOTS = {s["id"]: s for s in json.load(open(args.shots))} assert set(K) == set(SHOTS), set(SHOTS) ^ set(K)else: # placeholder timings, 3 s per shot SHOTS = {sid: dict(id=sid, t0=3.0 * i, t1=3.0 * (i + 1), dur=3.0, lyric="") for i, sid in enumerate(K)}
out = []def frame(sid, fid, cast, scene, role): if sid in GAUGE: scene += f" The gauge is visible and reads exactly {GAUGE[sid]} %: its red column reaches the {GAUGE[sid]} % label and no higher." for ids, layout in LAYOUT.values(): if sid in ids.split(): scene += f" {layout}." looks = " ".join(f"Character look: {CAST[c][1]}." for c in dict.fromkeys(cast)) props = [v for k, v in PROPS.items() if k.lower() in scene.lower()] looks += "".join(f" Prop scale: {d}." for _, d in props) s = SHOTS[sid] out.append(dict(id=fid, shot=sid, role=role, uploads=UPLOADS.get(fid, []), t0=s["t0"], t1=s["t1"], dur=s["dur"], lyric=s.get("lyric", ""), attach=sorted({CAST[c][0] for c in cast} | {n for n, _ in props}), prompt=f"{STYLE} Scene: {scene} {looks}".strip()))
for sid, (cast, start, end, move, mids) in K.items(): if end: frame(sid, sid, cast, f"START frame of a shot whose camera move is: {move}. {start}", "start") for i, mid in enumerate(mids, 1): frame(sid, f"{sid}_m{i}", cast, f"IN-BETWEEN frame {i} of the same shot as {sid}, during the camera move " f"({move}); same set, same lighting, same characters and outfits. {mid}", "mid") frame(sid, sid + "_end", cast, f"END frame of the same shot as {sid}, after the camera move ({move}); same set, " f"same lighting, same characters and outfits. {end}", "end") for o in out[-(2 + len(mids)):]: o["move"] = move else: frame(sid, sid, cast, start, "single")
json.dump(out, open(args.out, "w"), indent=1, ensure_ascii=False)print(len(K), "shots,", len(out), "frames;", sum(o["role"] == "end" for o in out), "with an end frame ->", args.out)