Skip to content

Reverse-engineer any video, shot by shot: filmed, AI-generated or coded, and how to remake it. Breakdowns in the open VIDEO.md format. 逆向一切视频,逐个镜头看是拍的、AI 生成的还是代码做的,再告诉你怎么复刻;拆解结果按 VIDEO.md 格式输出。

fix: respect end-only time bounds when correcting shots

Tobin30dfe94bf680
diff --git a/rea_video/memory.py b/rea_video/memory.py
index f684b50..efc0c99 100644
--- a/rea_video/memory.py
+++ b/rea_video/memory.py
@@ -114,9 +114,10 @@ def _top(p: dict | None) -> str | None:
def _select(breakdown: dict, shots: str | None, start: float | None, end: float | None) -> list[dict]:
recs = breakdown["shots"]
- if shots in (None, "", "all") and start is None:
+ if shots in (None, "", "all") and start is None and end is None:
return recs
- if start is not None:
+ if start is not None or end is not None:
+ start = start if start is not None else 0.0
e = end if end is not None else breakdown["source"]["duration"]
return [r for r in recs if min(r["end"], e) - max(r["start"], start) > 0.5 * r["duration"]]
want = set()
diff --git a/tests/test_memory.py b/tests/test_memory.py
index 0771fcf..1af8431 100644
--- a/tests/test_memory.py
+++ b/tests/test_memory.py
@@ -1,6 +1,7 @@
"""User memory: corrections fix the breakdown, persist, re-apply, and surface as hints; prefs set defaults."""
import json
+import pytest
import yaml
from rea_video.cli import main
@@ -8,6 +9,45 @@ from rea_video.memory import load_corrections, patterns
from rea_video.pipeline import _vlm_gate, decompose
[email protected]("bounds, expected", [
+ ({"end": 2.0}, ["shot_001"]),
+ ({"start": 2.0, "end": 4.0}, ["shot_002"]),
+ ({"start": 4.0}, ["shot_003"]),
+ ({}, ["shot_001", "shot_002", "shot_003"]),
+ ({"shots": "2"}, ["shot_002"]),
+])
+def test_correction_bounds_only_modify_and_remember_selected_shots(bounds, expected):
+ from rea_video.memory import correct, reapply
+
+ def breakdown():
+ return {"source": {"filename": "example.mp4", "duration": 6.0, "sha256_head": "example"},
+ "shots": [{"id": f"shot_{i + 1:03d}", "start": i * 2.0, "end": (i + 1) * 2.0,
+ "duration": 2.0, "base": {"label": "live_action", "confidence": 0.8},
+ "deterministic": {"probs": {"live_action": 1.0}, "facts": {}}}
+ for i in range(3)]}
+
+ b = breakdown()
+ correct(b, label="ai_video", **bounds)
+ assert [s["id"] for s in b["shots"] if "user" in s] == expected
+ assert [c["shot"] for c in load_corrections()] == expected
+ fresh = breakdown()
+ reapply(fresh)
+ assert [s["id"] for s in fresh["shots"] if "user" in s] == expected
+
+
+def test_empty_end_only_correction_does_not_change_memory():
+ from rea_video.memory import correct
+
+ b = {"source": {"filename": "example.mp4", "duration": 2.0, "sha256_head": "example"},
+ "shots": [{"id": "shot_001", "start": 0.0, "end": 2.0, "duration": 2.0,
+ "base": {"label": "live_action", "confidence": 0.8},
+ "deterministic": {"probs": {"live_action": 1.0}, "facts": {}}}]}
+ with pytest.raises(ValueError, match="没有选中任何镜头"):
+ correct(b, label="ai_video", end=0.0)
+ assert "user" not in b["shots"][0]
+ assert load_corrections() == []
+
+
def test_correction_fixes_breakdown_and_is_remembered(media, tmp_path, capsys):
out = tmp_path / "o"
b = decompose(media["code"], out, use_vlm=False, ocr=False, workers=1, stems=False)