From bf59e69ba9b913a28a9536137a42c2ce6cac850e Mon Sep 17 00:00:00 2001 From: Matt Van Horn <455140+mvanhorn@users.noreply.github.com> Date: Wed, 8 Jul 2026 22:16:49 -0700 Subject: [PATCH] feat: let --fps exceed the 2 fps cap on short/fast-action clips --- README.md | 6 +++--- skills/watch/SKILL.md | 6 +++--- skills/watch/scripts/frames.py | 7 +++++++ skills/watch/scripts/watch.py | 4 ++-- tests/test_frames.py | 21 +++++++++++++++++++++ 5 files changed, 36 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 8c44cf24..9832c1dd 100644 --- a/README.md +++ b/README.md @@ -62,7 +62,7 @@ Token cost is dominated by frames. Every frame is an image; image tokens add up | 3 - 10 min | ~80 frames | Sparse but workable | | > 10 min | 100 frames (capped modes) | "Sparse scan" warning — re-run focused, or `--detail token-burner` for full uncapped coverage | -When the user names a moment ("around 2:30", "the last 30 seconds", "from 0:45 to 1:00"), pass `--start` / `--end`. Focused mode gets denser per-second budgets, capped at 2 fps. Far more useful than a sparse pass over the whole thing. +When the user names a moment ("around 2:30", "the last 30 seconds", "from 0:45 to 1:00"), pass `--start` / `--end`. Focused mode gets denser per-second budgets, capped at 2 fps unless an explicit `--fps` override targets a range of 5 seconds or less. Far more useful than a sparse pass over the whole thing. ## Frame deduplication @@ -194,7 +194,7 @@ Other knobs (passed to `scripts/watch.py`): - `--timestamps T1,T2,…` — grab a frame at each absolute timestamp (`SS`/`MM:SS`/`HH:MM:SS`). Claude reads the transcript first, then targets the moments the presenter flags ("look here", "as you can see"). Added on top of the detail frames (reserved against the cap); out-of-window cues are dropped in focus mode; with `--detail transcript` these become the only frames. - `--max-frames N` — lower the frame cap for a tighter token budget. - `--resolution W` — bump frame width to 1024 px when Claude needs to read on-screen text (slides, terminals, code). -- `--fps F` — override the auto-fps calculation (still capped at 2 fps). +- `--fps F` — override the auto-fps calculation (still capped at 2 fps unless the effective clip/range is 5 seconds or shorter; frame caps still apply). - `--whisper groq|openai` — force a specific Whisper backend. - `--no-whisper` — disable transcription entirely; frames only. - `--no-dedup` — keep near-duplicate frames. By default a frame-delta pass drops frames that are visually near-identical to the one before them (held slides, static screen recordings, paused video), so the frame budget is spent on distinct content; this flag turns that off. @@ -203,7 +203,7 @@ Other knobs (passed to `scripts/watch.py`): ## Limits - **Long-video accuracy depends on the detail mode.** On the capped modes (`efficient`, default `balanced`) coverage thins out past ~10 minutes — the frame cap spreads across the whole clip, so the script prints a "sparse scan" warning and you're better off re-running focused with `--start`/`--end`. `token-burner` lifts the cap and keeps *every* scene-change frame across the full video, so it stays complete on longer clips at the cost of more image tokens. The 10-minute mark is guidance for the capped modes, not a hard ceiling. -- **Detail is one dial.** Defaults are balanced: scene-aware frames, 2 fps max, 100-frame cap. Use `--detail efficient` for a fast 50-frame keyframe pass, or `--detail token-burner` for uncapped scene candidates. Set `WATCH_DETAIL` in `~/.config/watch/.env` to change the default. +- **Detail is one dial.** Defaults are balanced: scene-aware frames, auto-fps capped at 2 fps, 100-frame cap. Use `--detail efficient` for a fast 50-frame keyframe pass, `--fps` for explicit sampling control (short clips/ranges of 5 seconds or less can exceed 2 fps), or `--detail token-burner` for uncapped scene candidates. Set `WATCH_DETAIL` in `~/.config/watch/.env` to change the default. ## Structure diff --git a/skills/watch/SKILL.md b/skills/watch/SKILL.md index 7cd78b6a..965b9a64 100644 --- a/skills/watch/SKILL.md +++ b/skills/watch/SKILL.md @@ -114,7 +114,7 @@ Within a single session, you can skip Step 0 on follow-up `/watch` calls — onc ## Recommended limits - **Best accuracy: videos under 10 minutes.** Frame coverage scales inversely with duration. -- **Universal rate cap: 2 fps.** The script never samples faster than 2 fps, even when a budget or `--fps` would imply more. +- **Default rate cap: 2 fps.** Auto-fps never samples faster than 2 fps. An explicit `--fps` can exceed 2 fps only when the effective clip/range is 5 seconds or shorter; the frame cap still limits output. - **The frame ceiling is set by the detail mode** (`WATCH_DETAIL` in `~/.config/watch/.env`, or `--detail`), not a single global cap: - `transcript` → no frames - `efficient` → up to **50** (keyframes) @@ -145,7 +145,7 @@ Optional flags: - `--timestamps T1,T2,…` — grab a frame at each of these absolute timestamps (`SS`, `MM:SS`, or `HH:MM:SS`). Use this after reading the transcript to capture deictic moments the presenter flags ("look here", "as you can see", "notice this") that visual selection alone may miss. See "Transcript-cue frames" below. - `--max-frames N` — override the preset cap for tighter token budget (e.g. `--max-frames 40`) - `--resolution W` — change frame width in px (default 512; bump to 1024 only if the user needs to read on-screen text) -- `--fps F` — override auto-fps (clamped to 2 fps max) +- `--fps F` — override auto-fps (clamped to 2 fps unless the effective clip/range is 5 seconds or shorter; frame caps still apply) - `--out-dir DIR` — keep working files somewhere specific (default: an auto-generated tmp dir) - `--whisper groq|openai` — force a specific Whisper backend (default: prefer Groq if both keys exist) - `--no-whisper` — disable the Whisper fallback entirely (frames-only if no captions) @@ -153,7 +153,7 @@ Optional flags: ### Focusing on a section (higher frame rate) -When the user asks about a specific moment — "what happens at the 2 minute mark?", "zoom into 0:45 to 1:00", "the first 10 seconds" — pass `--start` and/or `--end`. The script switches to focused-mode budgets, which are denser than full-video budgets (still capped at 2 fps, and still bounded by the detail-mode cap — the counts below assume the default `balanced` cap of 100; `efficient` tops out at 50): +When the user asks about a specific moment — "what happens at the 2 minute mark?", "zoom into 0:45 to 1:00", "the first 10 seconds" — pass `--start` and/or `--end`. The script switches to focused-mode budgets, which are denser than full-video budgets (auto-fps is still capped at 2 fps, and frames are still bounded by the detail-mode cap — the counts below assume the default `balanced` cap of 100; `efficient` tops out at 50): - ≤5s → 2 fps (up to 10 frames) - 5-15s → 2 fps (up to 30 frames) diff --git a/skills/watch/scripts/frames.py b/skills/watch/scripts/frames.py index 050ee7ed..edde7a0a 100755 --- a/skills/watch/scripts/frames.py +++ b/skills/watch/scripts/frames.py @@ -17,6 +17,7 @@ MAX_FPS = 2.0 +SHORT_CLIP_SECONDS = 5.0 SCENE_THRESHOLD = 0.20 # Keep scene-detection results once we have at least this many distinct shots. # Below this the video is effectively static (screen recording, talking head), @@ -52,6 +53,12 @@ def _clamp_fps(fps: float, duration_seconds: float, max_frames: int) -> tuple[fl return fps, target +def resolve_fps_override(requested_fps: float, duration_seconds: float) -> float: + if 0 < duration_seconds <= SHORT_CLIP_SECONDS: + return float(requested_fps) + return min(float(requested_fps), MAX_FPS) + + def parse_time(value: str | float | int | None) -> float | None: """Parse SS, MM:SS, or HH:MM:SS (with optional .ms) into seconds.""" if value is None: diff --git a/skills/watch/scripts/watch.py b/skills/watch/scripts/watch.py index f34b51fe..d64ffb75 100755 --- a/skills/watch/scripts/watch.py +++ b/skills/watch/scripts/watch.py @@ -17,7 +17,7 @@ from config import frame_cap, get_config # noqa: E402 from download import download, fetch_captions, is_url # noqa: E402 -from frames import MAX_FPS, auto_fps, auto_fps_focus, extract_at_timestamps, extract_keyframes, extract_scene_or_uniform, format_time, get_metadata, merge_frames, parse_time, parse_timestamps # noqa: E402 +from frames import auto_fps, auto_fps_focus, extract_at_timestamps, extract_keyframes, extract_scene_or_uniform, format_time, get_metadata, merge_frames, parse_time, parse_timestamps, resolve_fps_override # noqa: E402 from transcribe import filter_range, format_transcript, parse_vtt # noqa: E402 from whisper import load_api_key, transcribe_video # noqa: E402 @@ -157,7 +157,7 @@ def main() -> int: else: fps, target = auto_fps(effective_duration, max_frames=budget_cap) if args.fps is not None: - fps = min(args.fps, MAX_FPS) + fps = resolve_fps_override(args.fps, effective_duration) target = max(1, int(round(fps * effective_duration))) if transcript_segments and focused: diff --git a/tests/test_frames.py b/tests/test_frames.py index e53a9078..afb74e2c 100644 --- a/tests/test_frames.py +++ b/tests/test_frames.py @@ -6,6 +6,27 @@ import frames +def test_resolve_fps_override_allows_high_fps_for_subsecond_clip(): + assert frames.resolve_fps_override(25, 0.72) == 25.0 + + +def test_resolve_fps_override_clamps_long_clip(): + assert frames.resolve_fps_override(25, 120) == frames.MAX_FPS + + +def test_resolve_fps_override_preserves_below_cap_short_clip(): + assert frames.resolve_fps_override(1.0, 0.72) == 1.0 + + +def test_resolve_fps_override_short_clip_boundary(): + assert frames.resolve_fps_override(25, 5.0) == 25.0 + assert frames.resolve_fps_override(25, 5.01) == frames.MAX_FPS + + +def test_resolve_fps_override_clamps_zero_duration(): + assert frames.resolve_fps_override(25, 0.0) == frames.MAX_FPS + + def test_keyframe_engine_on_cut_clip(cut_clip: Path, tmp_path: Path): out, meta = frames.extract_keyframes(str(cut_clip), tmp_path / "f", max_frames=50) assert meta["engine"] == "keyframe"