Generate clean 2D game sprites & animation atlases — component-row pipeline: state rows, alpha cleanup, frame extraction, runtime atlases. Codex/Claude skill.
fix(video): a published clip whose every frame is the canvas alone is not read (`held` read false, with why), where it read as one hold the motion means and said nothing
Soohong Kimb0ab67aab57e
diff --git a/sprite_gen/gen/video.py b/sprite_gen/gen/video.pyindex 92e3d28..733e917 100644--- a/sprite_gen/gen/video.py+++ b/sprite_gen/gen/video.py@@ -436,7 +436,7 @@ def read_held(clip: Path) -> dict[str, Any]:where the engine keeps such a run as the motion's own — longer than `held_fill.HOLD_MAX`, or the clip's opening orclosing pose — and none where `video-loop` would make its frames again between the poses beside them. Nothing ischanged: the provider's frames are the clip, and the material its loops are cut from. A clip ffmpeg cannot read is- `read` false, with `why`."""+ `read` false, with `why`, and so is one whose every frame is the canvas alone (no subject: nothing was read)."""from PIL import Imagefrom sprite_gen._deps import np@@ -458,6 +458,7 @@ def read_held(clip: Path) -> dict[str, Any]:same: list[bool] = []background = Noneprevious = None+ subject = Falseassert proc.stdout is not Nonewhile len(data := proc.stdout.read(size)) == size:rgba = np.frombuffer(data, np.uint8).reshape(height, width, 4).copy()@@ -466,6 +467,7 @@ def read_held(clip: Path) -> dict[str, Any]:if background is not None:off = np.abs(rgba[..., :3].astype(np.float32) / 255 - np.asarray(background, np.float32)).max(axis=-1)rgba[off <= BACKGROUND_TOL, 3] = 0+ subject = subject or bool(rgba[..., 3].any())frame = Image.fromarray(rgba, "RGBA")if previous is not None:same.append(held_fill.same_steps([previous, frame])[0])@@ -474,6 +476,12 @@ def read_held(clip: Path) -> dict[str, Any]:if proc.wait() != 0 or previous is None:return {"read": False, "why": f"ffmpeg could not read its frames ({error[:200] or 'no frame'})"}n = len(same) + 1+ if not subject:+ # Two frames of the canvas alone are one picture to the rule: read so, a clip of nothing would be one long hold+ # the motion means, and say nothing. No subject is no reading.+ return {"read": False, "frames": n, "background": background,+ "why": f"no frame of the {n} shows a subject: every pixel is within {BACKGROUND_TOL} of the colour it is "+ f"filmed on ({', '.join(map(str, background or []))})"}rows = []for run in held_fill.runs(same):why = (f"held {run['length']} frames, longer than a drawing on threes ({held_fill.HOLD_MAX}): a hold the motion means"diff --git a/tests/gen/test_video_held.py b/tests/gen/test_video_held.pyindex 7c7debc..96da551 100644--- a/tests/gen/test_video_held.py+++ b/tests/gen/test_video_held.py@@ -87,6 +87,22 @@ def test_a_file_ffmpeg_cannot_read_is_named_not_read(tmp_path):assert video.held_lines(clip, record)[0].startswith("fake.mp4: its frames were not read for a picture shown again — ")+def test_a_clip_of_the_canvas_alone_is_named_not_read(tmp_path):+ """Every frame the green canvas, no subject: two frames of the canvas alone are one picture to the rule, so read on,+ the clip was one hold of eight frames the motion means, and nothing was said. No subject is no reading."""+ folder = tmp_path / "blank"+ folder.mkdir()+ for i in range(8):+ Image.new("RGB", (W, H), GREEN).save(folder / f"{i:04d}.png")+ clip = tmp_path / "blank.mp4"+ subprocess.run([shutil.which("ffmpeg"), "-v", "error", "-y", "-framerate", "24", "-i", str(folder / "%04d.png"),+ "-c:v", "libx264", "-crf", "18", "-pix_fmt", "yuv420p", str(clip)], check=True)+ record = video.read_held(clip)+ assert record["read"] is False and record["frames"] == 8 and record["background"] is not None+ assert record["why"].startswith("no frame of the 8 shows a subject: every pixel is within 0.12 of the colour")+ assert video.held_lines(clip, record) == [f"blank.mp4: its frames were not read for a picture shown again — {record['why']}"]++def _run(tmp_path: Path, monkeypatch, payload: bytes) -> tuple[dict, Path]:api = _FakeApi()api.payload = payload