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 格式输出。

Check tiles arguments up front (#37)

Salman Biswas57e2618f1216
diff --git a/rea_video/cli.py b/rea_video/cli.py
index d31490a..2555ac9 100644
--- a/rea_video/cli.py
+++ b/rea_video/cli.py
@@ -265,8 +265,21 @@ def cmd_tiles(args) -> int:
from .media import extract_frame, video_info
from .visual import shot_sheet
+ # bad numbers used to die deep inside numpy / PIL with a traceback, or silently print an empty result
+ if args.every <= 0:
+ raise SystemExit("rea-video: --every 必须大于 0(两次抽帧的间隔秒数)")
+ if args.start < 0:
+ raise SystemExit("rea-video: --start 不能小于 0")
+ if args.cols < 1:
+ raise SystemExit("rea-video: --cols 至少为 1")
+ if args.max < 1:
+ raise SystemExit("rea-video: --max 至少为 1")
+ if args.cell < 1:
+ raise SystemExit("rea-video: --cell 至少为 1")
info = video_info(args.video)
end = args.end if args.end is not None else info.duration
+ if args.start >= end:
+ raise SystemExit(f"rea-video: --end 必须大于 --start(视频时长 {info.duration:.2f} 秒)")
times = list(np.arange(args.start, end, args.every))[: args.max]
import tempfile
diff --git a/tests/test_robustness.py b/tests/test_robustness.py
index 5af27f3..1db299d 100644
--- a/tests/test_robustness.py
+++ b/tests/test_robustness.py
@@ -97,6 +97,32 @@ def test_tiles_cmd_quotes_paths():
assert "'/a/my video.mp4'" in _tiles_cmd("/a/my video.mp4", 1, 2, 0.2, "out/c.jpg")
+def test_tiles_rejects_bad_numbers(fps10, tmp_path, capsys):
+ import argparse
+ import json
+
+ from rea_video.cli import cmd_tiles
+
+ def args(**kw):
+ base = {"video": str(fps10), "start": 0.0, "end": None, "every": 0.5,
+ "cols": 6, "cell": 320, "max": 48, "out": str(tmp_path / "t.jpg")}
+ base.update(kw)
+ return argparse.Namespace(**base)
+
+ # --every 0 used to raise ZeroDivisionError, --cols 0 ValueError, --cell 0 a PIL error,
+ # and --max 0 / --end <= --start silently printed an empty result with exit 0
+ for bad in ({"every": 0}, {"every": -0.5}, {"start": -1}, {"cols": 0}, {"max": 0},
+ {"cell": 0}, {"end": 0.0}, {"start": 1.0, "end": 1.0}, {"start": 5.0}):
+ with pytest.raises(SystemExit) as exc:
+ cmd_tiles(args(**bad))
+ assert "rea-video: --" in str(exc.value)
+ assert capsys.readouterr().out == "" # a clean one-line error, not a traceback
+ assert cmd_tiles(args()) == 0
+ printed = json.loads(capsys.readouterr().out)
+ assert len(printed["tiles"]) == 1 and len(printed["times"]) == 4
+ assert Path(printed["tiles"][0]).is_file()
+
+
def test_relocalize_rewrites_stored_labels():
from rea_video.i18n import set_lang
from rea_video.packaging import relocalize