Skip to content

Generate clean 2D game sprites & animation atlases — component-row pipeline: state rows, alpha cleanup, frame extraction, runtime atlases. Codex/Claude skill.

feat(video-loop): --overlap-wrap off turns the overlapped wrap off alone, and the gate refuses the cut as filmed

Soohong Kim812047a46e60
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 67bef85..4437977 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -2,6 +2,11 @@
All notable public changes to `sprite-gen` are recorded here. Versions track the `version:` field in `SKILL.md` and `pyproject.toml`.
+## Unreleased
+
+- **New: `video-loop --overlap-wrap off` turns the overlapped wrap off alone.** Each frame the overlapped wrap makes is RIFE's frame read with its sixteen single passes, 34 calls of the binary: where RIFE runs on a CPU that is minutes a frame (on two CPU cores with the augmentation off, 160 to 174 s for a frame of a 960 × 960 synthetic walker), and a wrap refused at its first frame costs minutes a run, so a caller that stops the loop at a deadline stopped it before the loop could fail on its own seam. With `--overlap-wrap off` (the default stays `on`) nothing is read or made for the wrap: the report's `wrap_overlap` says `skipped: "turned off (--overlap-wrap off)"` with no `tries` and `calls` 0, a `warning:` line says the overlapped wrap was not made, and the seam gate refuses the cut as filmed (`video-loop: loop seam ratio … exceeds …`). Nothing else changes: the jump repair, the eased retime and the gate run as with it on, and `--repair off` still turns it off with them.
+- **Tests** — `tests/video/test_loop_overlap.py` (with the overlapped wrap off, the front walker whose tail swings on its own beat has nothing read for its wrap, records it turned off and fails on its seam with the warning line; the closed wrap is the same for the default and an explicit `on`; `video-loop`'s argv carries `--overlap-wrap off` with no RIFE installed, `on` is the default and another word is refused).
+
## v2.45.1 - An eased stretch that stops the legs is refused; the loop keeps the flow repair
**Upgrading from 2.45.0: An eased stretch that puts the body off its beat is refused, its RIFE calls are still spent, and the round records its beat.** Under `video-loop --repair auto` (and `--repair on`), an eased stretch is played only where every window of the rest of the body steps, in each step, as far as it did there in the loop as played, to within a quarter of its usual step (`repair.EASE_BEAT`, 0.25); otherwise it is refused for `the body off its beat` (listed in `rejected_for`), and the loop is delivered as the flow repair left it. RIFE calls made for the retime remain spent (up to 9 calls), the eased round's record gains a `beat` field (`bound`, `off`, `off_max`), and no command-line flags or restoration schemas change: `source-restoration-v5`, repair report `schema_version` 4, comparison `schema_version` 6.
diff --git a/SKILL.md b/SKILL.md
index 0e6e629..e035dfa 100644
--- a/SKILL.md
+++ b/SKILL.md
@@ -160,7 +160,7 @@ Scene creation consumes finished assets and remains optional. Asset metadata own
## RIFE for walk and run loops
-`video-loop` repairs a walk's or run's jump frames, reads a part that rushes on its way at the wrap and eases it only where the rest of the body keeps its own beat (a frame made is the whole picture, so the legs take the part's time: such a loop keeps the flow repair), closes a two-step cut's wrap that a part on its own beat leaves open with the clip's frames a cycle apart, and gives its filmed ghosts way (a half-drawn frame the video model left, `ghost_given_way`), and `video-set` gives a direction set one cycle length, both with RIFE in-betweens. Install it once per machine: `$SPRITE_GEN_ROOT/.venv/bin/sprite-gen rife install` (pinned rife-ncnn-vulkan 20221029 and model rife-v4.6, SHA-256 checked, into the user data directory, ending with a check frame; Linux without a GPU first needs `libvulkan1 mesa-vulkan-drivers`). Every call runs the binary's test-time augmentation `-x -z`; on a CPU it costs 15 to 19 times a plain call, so a CPU-only machine aligning a set may set `SPRITE_GEN_RIFE_TTA=` (none) or `-z`. Without it every loop is still cut — a jump or a rush as filmed, each filmed ghost given way to the clean frame beside it — and what was left unrepaired says so: a `warning:` line on stderr and `jump_repair.rife` with `jump_repair.unmade` (the jump left as filmed) or `jump_repair.ease_skipped` (the rush) in the loop report (`applied` alone is not the sign: a ghost given way reads true), `cycle_align.<state>.applied: false` and `warnings` in `set.report.json`. When that happens, tell the user which loops went unrepaired and offer the install; after it, cut those loops again and run `video-cycle-align`. `video-loop --repair on` and `video-cycle-align` fail without RIFE instead. [loop-repair](docs/loop-repair.md).
+`video-loop` repairs a walk's or run's jump frames, reads a part that rushes on its way at the wrap and eases it only where the rest of the body keeps its own beat (a frame made is the whole picture, so the legs take the part's time: such a loop keeps the flow repair), closes a two-step cut's wrap that a part on its own beat leaves open with the clip's frames a cycle apart (`--overlap-wrap off` turns that alone off where RIFE runs on a CPU; the gate then refuses the cut as filmed), and gives its filmed ghosts way (a half-drawn frame the video model left, `ghost_given_way`), and `video-set` gives a direction set one cycle length, both with RIFE in-betweens. Install it once per machine: `$SPRITE_GEN_ROOT/.venv/bin/sprite-gen rife install` (pinned rife-ncnn-vulkan 20221029 and model rife-v4.6, SHA-256 checked, into the user data directory, ending with a check frame; Linux without a GPU first needs `libvulkan1 mesa-vulkan-drivers`). Every call runs the binary's test-time augmentation `-x -z`; on a CPU it costs 15 to 19 times a plain call, so a CPU-only machine aligning a set may set `SPRITE_GEN_RIFE_TTA=` (none) or `-z`. Without it every loop is still cut — a jump or a rush as filmed, each filmed ghost given way to the clean frame beside it — and what was left unrepaired says so: a `warning:` line on stderr and `jump_repair.rife` with `jump_repair.unmade` (the jump left as filmed) or `jump_repair.ease_skipped` (the rush) in the loop report (`applied` alone is not the sign: a ghost given way reads true), `cycle_align.<state>.applied: false` and `warnings` in `set.report.json`. When that happens, tell the user which loops went unrepaired and offer the install; after it, cut those loops again and run `video-cycle-align`. `video-loop --repair on` and `video-cycle-align` fail without RIFE instead. [loop-repair](docs/loop-repair.md).
## Contracts and advanced tools
diff --git a/docs/loop-repair.md b/docs/loop-repair.md
index 20d2e24..95c9a87 100644
--- a/docs/loop-repair.md
+++ b/docs/loop-repair.md
@@ -617,7 +617,7 @@ frames.
| Rule | Value | Why |
|---|---|---|
-| When | `--repair auto` or `on`; a cut whose two steps the clip's crossings show (`cycle.steps.by: crossings`) and whose wrap the gate reads over `--seam-max` on its frames as corrected (`loop.wrap_on_cells`) | the legs close; what does not is a part on its own beat. A cut whose steps are not counted keeps the gate's word |
+| When | `--repair auto` or `on`, and `--overlap-wrap on` (the default); a cut whose two steps the clip's crossings show (`cycle.steps.by: crossings`) and whose wrap the gate reads over `--seam-max` on its frames as corrected (`loop.wrap_on_cells`) | the legs close; what does not is a part on its own beat. A cut whose steps are not counted keeps the gate's word |
| The frames a cycle apart | the clip's frame a cycle after each of the cut's first frames (`after`), or before each of its last (`before`), one past the widest run, as far as the clip after its lead-in holds them; each moved by the analysis translation between the two — the drift the clip walks over a cycle — and corrected as its cut frame was (`loop.cycle_apart`) | placed where the cut frame is, the in-between moves the part, not the body |
| How many | four frames, then six, eight, ten and twelve (`OVERLAP_WIDTHS`), never past half the loop (`MADE_SHARE`), on the side whose frames a cycle apart differ least from the cut's over the run | the fewer made, the more of the loop is the clip's own; a longer run where a shorter one rushes the part or leaves the body no room, its weights going over in smaller steps |
| Each frame | made by RIFE between its two frames of one time — the late (the clip's frame a cycle after, or the loop's own before the wrap) and the early (the loop's own, or the clip's frame a cycle before) — at the weight of the early the search chooses (`repair.overlap_weights`, below), and read with RIFE's sixteen single passes for a part torn (`rife.Rife.read`, `repair.overlap_frame`, below); a weight of 0 or 1 shows that frame whole, no call, and a frame at one weight is made once, whatever the run | each frame at its own time, the legs where they were on both; next to the wrap near the frame that continues the clip across it |
@@ -692,7 +692,7 @@ body in bound` where the search found none and nothing was made); where a run wa
`width`, `frames` (those shown otherwise than as cut) and `seam_after`; `interpolator`, with the binary's
calls (`binary_calls`) where RIFE was located for it; and `skipped` where none was tried (drawn on twos, a loop too short
for a run that leaves half of it filmed, the clip holds no frames a cycle from the cut's beside the wrap,
-no interpolator). The summary names it; a `warning:` line names the frame that ended each run refused for
+no interpolator, turned off by `--overlap-wrap off`). The summary names it; a `warning:` line names the frame that ended each run refused for
a fault ("fault (torn at frame 3, the rest not made)"). A made frame
that cross-fades two drawings inside its outline is kept and named in a `warning:` line, as for the
jump repair. Without RIFE the wrap is cut as filmed with a warning line (`why`: "RIFE not installed —
@@ -703,6 +703,16 @@ is refused for a part torn costs the frames each run makes up to its first torn
run is made whole and refused for something else at most forty frames, outside the jump repair's — the
first walker above takes ten frames, the second four where it is taken and fifteen where its torso slides.
+**Turned off.** Where RIFE runs on a CPU, those calls take minutes a frame: on two CPU cores with the
+augmentation off (`SPRITE_GEN_RIFE_TTA=`), a frame of a 960 × 960 synthetic walker took 160 to 174 s, its
+sixteen passes nearly all of it — so a wrap refused for a part torn at its first frame costs minutes a run,
+and one made whole up to forty frames. A caller that stops the loop at a deadline would stop it there, and
+the loop would not fail on its own seam. `video-loop --overlap-wrap off` turns the overlapped wrap off
+alone: nothing is read or made for it, `wrap_overlap` says so (`skipped`: "turned off (--overlap-wrap
+off)", no `tries`, `calls` 0) with the `warning:` line every skipped wrap has, and the gate refuses the cut
+as filmed, the loop failing on its seam as where every run is refused. The jump repair, the eased retime and
+the gate are as with it on; `--repair off` turns it off with the rest.
+
## 3. The jolt index — reported on every walk, a gate only when asked
A loop whose steps change unevenly jolts even when no single step is a jump. Every walk or run
diff --git a/docs/video-pipeline.md b/docs/video-pipeline.md
index afcda29..5fede81 100644
--- a/docs/video-pipeline.md
+++ b/docs/video-pipeline.md
@@ -948,7 +948,8 @@ tail is given, and the loop then keeps the flow repair. Before all of it, a cut
leaves open — a tail swinging round on a beat of its own, closing on no cut of two steps — has four
to twelve frames beside its wrap made again between the clip's frames a cycle apart and its own, so
the wrap plays a step the clip filmed, as far as the torso held to the stretch as the loop plays it
-allows (the overlapped wrap, `wrap_overlap`).
+allows (the overlapped wrap, `wrap_overlap`; `--overlap-wrap off` turns it off alone, for a host whose
+RIFE runs on a CPU, and the gate then refuses the cut as filmed).
The report's `jump_repair` names the frames. RIFE
is installed once with `sprite-gen rife install`; without it a loop that needs a frame is cut as
filmed with a warning, each filmed ghost given way to the clean frame beside it (`--repair on`
diff --git a/sprite_gen/video/loop.py b/sprite_gen/video/loop.py
index 49852be..499ad3c 100644
--- a/sprite_gen/video/loop.py
+++ b/sprite_gen/video/loop.py
@@ -111,6 +111,13 @@ FOOT_BAND = legs_mod.FOOT_BAND # fraction of the frame's own height, measured u
# no RIFE fails the loop — a caller that asked for the repair is never handed less; off: the loop
# is cut as filmed, and says so.
REPAIR_MODES = ("auto", "on", "off")
+# The overlapped wrap (docs/loop-repair.md section 2, "The overlapped wrap"), under --repair auto or on. on: a two-step
+# cut whose wrap the gate refuses has the frames beside its wrap made again from the clip's frames a cycle apart, each
+# read with RIFE's sixteen single passes, 34 calls of the binary a frame and up to forty frames; off: it is not tried, the
+# report says so, and the gate refuses the cut as filmed — for a host whose RIFE runs on a CPU, where one frame of a
+# 960 px clip takes minutes and the loop's caller would stop it before it fails on its own.
+OVERLAP_WRAP_MODES = ("on", "off")
+OVERLAP_WRAP_OFF = "turned off (--overlap-wrap off)"
SIZE_HOLD_MODES = ("auto", "off")
FACINGS = ("right", "left")
# Where `video-cycle-align` keeps the cut as filmed (sprite_gen/video/align.py). A new cut makes
@@ -920,8 +927,9 @@ def _repair_jumps(frames: list[Image.Image], interpolate: rife_mod.Interpolate |
`wrap` (the clip's frames a cycle from the cut's beside its wrap, `cycle_apart`, and the gate's `seam_max`) asks
first for the overlapped wrap (`repair_mod.overlap_wrap`) of a cut two steps long whose wrap the gate refuses;
the frames it makes are then neither made from, nor beside, nor again (`overlapped`). Its record is returned
- third, None where it was not asked. The overlapped wrap and the eased retime after it read the body's drift on
- one torso, the cut's as filmed (`repair_mod.Torso`).
+ third, None where it was not asked; a `wrap` with `off` (`--overlap-wrap off`) and no frames records it turned off,
+ nothing read or made. The overlapped wrap and the eased retime after it read the body's drift on one torso, the
+ cut's as filmed (`repair_mod.Torso`).
A frame to make and no RIFE installed: `required` lets `RifeNotInstalled` through; otherwise
each filmed ghost gives way to the clean frame beside it, a jump (a frame off the flow), a rush and a wrap that does
@@ -958,9 +966,9 @@ def _repair_jumps(frames: list[Image.Image], interpolate: rife_mod.Interpolate |
overlapped: list[int] = []
torso = None
if wrap is not None:
- torso = repair_mod.Torso(frames)
- asked = partial(repair_mod.overlap_wrap, others=wrap["others"], seam=wrap_on_cells, steps=ring_steps,
- seam_max=wrap["seam_max"], reads=bool(screen["reads"]), torso=torso)
+ torso = None if "off" in wrap else repair_mod.Torso(frames)
+ asked = partial(repair_mod.overlap_wrap, others=wrap.get("others", {}), seam=wrap_on_cells, steps=ring_steps,
+ seam_max=wrap["seam_max"], reads=bool(screen["reads"]), torso=torso, off=wrap.get("off"))
try:
frames, overlap = asked(frames, read=lazy_read)
except rife_mod.RifeNotInstalled as exc:
@@ -1376,6 +1384,7 @@ def run_loop(
head_step_max: float | None = None,
size_hold: str = "auto",
steps: int | None = None,
+ overlap_wrap: str = "on",
) -> dict[str, Any]:
state = state.strip().lower() if state else state
if state == effect.STATE:
@@ -1403,6 +1412,8 @@ def run_loop(
raise SystemExit(f"video-loop: unknown --size-hold {size_hold!r}; expected one of {', '.join(SIZE_HOLD_MODES)}")
if repair not in REPAIR_MODES:
raise SystemExit(f"video-loop: unknown --repair {repair!r}; expected one of {', '.join(REPAIR_MODES)}")
+ if overlap_wrap not in OVERLAP_WRAP_MODES:
+ raise SystemExit(f"video-loop: unknown --overlap-wrap {overlap_wrap!r}; expected one of {', '.join(OVERLAP_WRAP_MODES)}")
if facing not in FACINGS:
raise SystemExit(f"video-loop: unknown --facing {facing!r}; expected one of {', '.join(FACINGS)}")
if anchor is None:
@@ -1672,9 +1683,11 @@ def run_loop(
wrap = None
if anchor == "motion-auto" and (cycle.get("steps") or {}).get("by") == "crossings" and wrap_on_cells(frames) > seam_max:
# Two steps by the clip's own crossings, and a wrap the gate refuses: a part on a beat of its own closes on no
- # cut of two steps. The clip's frames a cycle from the cut's beside the wrap make it again (the overlapped wrap).
- wrap = {"others": cycle_apart(files, start=i, length=L, skip=skip, analysis=analysis, motion=motion,
- size=frames[0].size), "seam_max": seam_max}
+ # cut of two steps. The clip's frames a cycle from the cut's beside the wrap make it again (the overlapped wrap),
+ # unless it is turned off.
+ wrap = ({"others": cycle_apart(files, start=i, length=L, skip=skip, analysis=analysis, motion=motion,
+ size=frames[0].size), "seam_max": seam_max} if overlap_wrap == "on"
+ else {"off": OVERLAP_WRAP_OFF, "seam_max": seam_max})
try:
frames, report_base["jump_repair"], overlap = _repair_jumps(frames, interpolate, facing=facing, required=repair == "on",
screen=report_base["ghost_screen"], wrap=wrap)
@@ -1952,6 +1965,7 @@ def add_arguments(parser: argparse.ArgumentParser) -> None:
parser.add_argument("--anchor", choices=ANCHOR_MODES, default=None, help="motion-auto: automatic stable regions, local repeat selection and XY ramp (walk/run); motion: fixed cut with explicit regions; body (default for walk/run): measure the last-to-first head-and-torso offset once and spread it as a ramp over the cycle; feet: remove in-canvas drift (a straight-line trend) so every cell stands on the mean foot line; none: leave placement as filmed (default for other states)")
parser.add_argument("--anchor-region", type=motion_anchor.parse_region, action="append", help="motion anchor only: repeat twice with head then torso x0,y0,x1,y1 in the first selected frame; requires --cycle fixed and at least 6 frames")
parser.add_argument("--repair", choices=REPAIR_MODES, default="auto", help="auto (default): take out the frames off the walk's flow (one or two drawings that lie 3x their region's usual step off the line between the frames either side) and make them again with RIFE between those frames, each at its own time, so the loop keeps its length; adopt only without smear/outline faults, at most 3 calls and never made from or beside a frame made (docs/loop-repair.md section 2). A rejected group keeps its frames. Missing RIFE keeps the filmed loop with a warning (`sprite-gen rife install`); on: the same repair, but no RIFE fails the loop; off: cut as filmed")
+ parser.add_argument("--overlap-wrap", choices=OVERLAP_WRAP_MODES, default="on", help="--anchor motion-auto, under --repair auto or on: on (default): a cut two steps long whose wrap a part on its own beat leaves open (the seam gate refuses it) has four to twelve frames beside its wrap made again between the clip's frames a cycle apart and its own, each read with RIFE's single passes for a part torn — 34 calls of the binary a frame, up to forty frames (docs/loop-repair.md section 2, \"The overlapped wrap\"); off: not tried, recorded `wrap_overlap.skipped` with a warning line, and the gate refuses the cut as filmed — for a host whose RIFE runs on a CPU, where one frame of a 960 px clip takes minutes")
parser.add_argument("--jolt-max", type=float, default=None, help=f"walk/run: fail the repaired loop when its jolt index (how far each step strays from its neighbours' mean, over the median step) exceeds this. Default: no gate — the index is reported and a value over {repair_mod.JOLT_REFERENCE} is a warning line")
parser.add_argument("--head-step-max", type=float, default=None, help=f"walk/run: fail the repaired loop when the head's largest sideways move in one frame exceeds this %% of the body height. Default: no gate — reported, and over {repair_mod.HEAD_STEP_REFERENCE} is a warning line")
parser.add_argument("--facing", choices=FACINGS, default="right", help="which way the body faces in the frames (default right): the jolt index's hair, and the size reading video-loop-compare's jump guard reads, are behind it; the jump repair reads the flow either way")
@@ -1981,6 +1995,7 @@ def run(**kwargs: object) -> int:
repair=str(kwargs.get("repair") or "auto"), facing=str(kwargs.get("facing") or "right"),
jolt_max=kwargs.get("jolt_max"), head_step_max=kwargs.get("head_step_max"), # type: ignore[arg-type]
size_hold=str(kwargs.get("size_hold") or "auto"), steps=kwargs.get("steps"), # type: ignore[arg-type]
+ overlap_wrap=str(kwargs.get("overlap_wrap") or "on"),
)
summary = {k: payload[k] for k in ("state", "frames_total", "window", "cycle_seconds", "n_out", "delay_ms", "resampled_seam_ratio", "specks_dropped", "report")}
summary["cycle"] = {k: payload["cycle"].get(k) for k in ("kind", "start", "length", "period_global", "ratio", "review_recommended", "half_period_guard", "fundamental")}
diff --git a/sprite_gen/video/repair.py b/sprite_gen/video/repair.py
index 402fd8f..84cb8d9 100644
--- a/sprite_gen/video/repair.py
+++ b/sprite_gen/video/repair.py
@@ -915,7 +915,8 @@ def overlap_frame(read: Read, a: Image.Image, b: Image.Image, u: float, *, reads
def overlap_wrap(frames: list[Image.Image], others: dict[str, dict[int, Image.Image]], read: Read | None, *,
seam: Callable[[list[Image.Image]], float], steps: Callable[[list[Image.Image]], dict[str, Any]],
- seam_max: float, reads: bool, torso: Torso | None = None) -> tuple[list[Image.Image], dict[str, Any]]:
+ seam_max: float, reads: bool, torso: Torso | None = None, off: str | None = None
+ ) -> tuple[list[Image.Image], dict[str, Any]]:
"""The overlapped wrap (docs/loop-repair.md section 2, "The overlapped wrap") of a loop cut two steps long whose wrap
the seam gate refuses (`seam`: the gate's reading of a loop, over `seam_max`).
@@ -940,10 +941,16 @@ def overlap_wrap(frames: list[Image.Image], others: dict[str, dict[int, Image.Im
than it did over the stretch (`no gain`); no window of the rest of the body steps further than its own largest step
over the stretch as the loop plays it (`the rest faster`); no rush the loop did not have is read across the stretch
(`a new rush`); and no frame of it is read further off the flow than before and at or over the limit. The first run
- taken ends the search. Returns the loop and the record (`frames`: the frames shown otherwise than as cut)."""
+ taken ends the search. Returns the loop and the record (`frames`: the frames shown otherwise than as cut).
+
+ `off` (why, `video-loop --overlap-wrap off`) turns it off: nothing is read or made, the record says so (`skipped`), and
+ the cut is kept as filmed for the gate to refuse."""
n = len(frames)
record: dict[str, Any] = {"seam": round(float(seam(frames)), 4), "seam_max": seam_max, "widths": list(OVERLAP_WIDTHS),
"tries": [], "frames": [], "calls": 0}
+ if off is not None:
+ record["skipped"] = off
+ return frames, record
box = union_box(frames)
flow = _flow(frames, box)
if flow["hold"] > 1: