agentic-video 0.1.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (43) hide show
  1. agentic_video-0.1.0/.gitignore +30 -0
  2. agentic_video-0.1.0/LICENSE +21 -0
  3. agentic_video-0.1.0/PKG-INFO +219 -0
  4. agentic_video-0.1.0/README.md +192 -0
  5. agentic_video-0.1.0/pyproject.toml +43 -0
  6. agentic_video-0.1.0/requirements-visual.txt +6 -0
  7. agentic_video-0.1.0/requirements.txt +6 -0
  8. agentic_video-0.1.0/src/adapters/mcp_definitions.legacy.ts +367 -0
  9. agentic_video-0.1.0/src/adapters/mcp_definitions.ts +295 -0
  10. agentic_video-0.1.0/src/adapters/mcp_schemas.json +2745 -0
  11. agentic_video-0.1.0/src/adapters/model_adapter.py +132 -0
  12. agentic_video-0.1.0/src/core/__init__.py +43 -0
  13. agentic_video-0.1.0/src/core/cache.py +240 -0
  14. agentic_video-0.1.0/src/core/config.py +56 -0
  15. agentic_video-0.1.0/src/core/errors.py +46 -0
  16. agentic_video-0.1.0/src/core/types.py +167 -0
  17. agentic_video-0.1.0/src/executor/mcp_server.py +1007 -0
  18. agentic_video-0.1.0/src/executor/types.d.ts +1247 -0
  19. agentic_video-0.1.0/src/jev.py +103 -0
  20. agentic_video-0.1.0/src/loop.py +1886 -0
  21. agentic_video-0.1.0/src/media/__init__.py +23 -0
  22. agentic_video-0.1.0/src/media/audio.py +3715 -0
  23. agentic_video-0.1.0/src/media/contact_sheet.py +368 -0
  24. agentic_video-0.1.0/src/media/fetch.py +186 -0
  25. agentic_video-0.1.0/src/media/frames.py +252 -0
  26. agentic_video-0.1.0/src/media/overlay.py +93 -0
  27. agentic_video-0.1.0/src/media/probe.py +169 -0
  28. agentic_video-0.1.0/src/media/sampling.py +380 -0
  29. agentic_video-0.1.0/src/media/scene.py +782 -0
  30. agentic_video-0.1.0/src/media/seeking.py +140 -0
  31. agentic_video-0.1.0/src/media/timing.py +170 -0
  32. agentic_video-0.1.0/src/media/visual_timing.py +885 -0
  33. agentic_video-0.1.0/src/retrieval/__init__.py +4 -0
  34. agentic_video-0.1.0/src/retrieval/engine.py +1269 -0
  35. agentic_video-0.1.0/src/retrieval/occurrence.py +835 -0
  36. agentic_video-0.1.0/src/retrieval/ocr.py +74 -0
  37. agentic_video-0.1.0/src/retrieval/periodicity.py +164 -0
  38. agentic_video-0.1.0/src/retrieval/repetition.py +590 -0
  39. agentic_video-0.1.0/src/retrieval/visual.py +459 -0
  40. agentic_video-0.1.0/src/transcript/__init__.py +9 -0
  41. agentic_video-0.1.0/src/transcript/asr.py +1454 -0
  42. agentic_video-0.1.0/src/transcript/repeats.py +40 -0
  43. agentic_video-0.1.0/src/transcript/search.py +113 -0
@@ -0,0 +1,30 @@
1
+ __pycache__/
2
+ *.py[cod]
3
+ *$py.class
4
+ .pytest_cache/
5
+ *.tmp
6
+ *.log
7
+
8
+ # Local virtual environments.
9
+ .venv/
10
+ .python-runtime/
11
+
12
+ # Temporary test and benchmark workspaces.
13
+ .tmp/
14
+ .tmp-*/
15
+
16
+ # Default output of `python -m src.loop check`.
17
+ .agentic-video-check/
18
+
19
+ # Credentials and machine-local authentication files.
20
+ .env
21
+ .env.*
22
+ **/auth.json
23
+ **/credentials*.json
24
+ **/*.pem
25
+ **/*.key
26
+ **/*.p12
27
+ **/.netrc
28
+
29
+ # Local session markers.
30
+ :memory:*
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 tlq5l
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,219 @@
1
+ Metadata-Version: 2.5
2
+ Name: agentic-video
3
+ Version: 0.1.0
4
+ Summary: Local video tools for AI agents that read text and images but not video: contact sheets, transcripts, cut, loudness and sync checks, served over MCP.
5
+ Project-URL: Homepage, https://github.com/tlq5l/agentic-video
6
+ Project-URL: Repository, https://github.com/tlq5l/agentic-video
7
+ Project-URL: Issues, https://github.com/tlq5l/agentic-video/issues
8
+ Author: tlq5l
9
+ License-Expression: MIT
10
+ License-File: LICENSE
11
+ Keywords: agents,contact-sheet,ffmpeg,mcp,video,whisper
12
+ Classifier: Development Status :: 3 - Alpha
13
+ Classifier: Intended Audience :: Developers
14
+ Classifier: Programming Language :: Python :: 3
15
+ Classifier: Topic :: Multimedia :: Video
16
+ Requires-Python: >=3.10
17
+ Requires-Dist: av<19
18
+ Requires-Dist: faster-whisper>=1.0
19
+ Requires-Dist: numpy>=1.21
20
+ Requires-Dist: pillow>=10
21
+ Provides-Extra: visual
22
+ Requires-Dist: pillow>=10; extra == 'visual'
23
+ Requires-Dist: pyobjc-framework-vision>=10; (sys_platform == 'darwin') and extra == 'visual'
24
+ Requires-Dist: torch<3,>=2.6; extra == 'visual'
25
+ Requires-Dist: transformers<5,>=4.45; extra == 'visual'
26
+ Description-Content-Type: text/markdown
27
+
28
+ # agentic-video
29
+
30
+ agentic-video lets an AI agent that reads text and images, but not video, work with video files on your own machine. It is a Python library plus a stdio MCP server. The agent asks small, targeted questions ("show me 12 frames from 0:40 to 1:10", "when is 'launch' spoken?") and gets back measurements, transcripts and contact sheets: grids of frames, each with its timestamp burned into the pixels. Nothing is uploaded; everything runs locally with FFmpeg, Whisper and optional local models.
31
+
32
+ **Install:** `brew install ffmpeg`, then add it to Claude Code with `claude mcp add -s user agentic-video -- uvx agentic-video` (or `pipx install agentic-video`). Other clients: [Run the MCP server](#run-the-mcp-server).
33
+
34
+ ![A contact sheet made by agentic-video from a 5-second clip: six frames, each with its timestamp burned in](https://raw.githubusercontent.com/tlq5l/agentic-video/main/docs/images/contact-sheet.jpg)
35
+
36
+ *One `contact_sheet` call on a 5-second clip: six frames, each stamped with its time, as a single image the agent can read.*
37
+
38
+ In 2 minutes (macOS) your agent can answer "what happens in this video?" and "when is X said?" for a local video file. You get the length and size, a contact sheet image with timestamps, the cuts, a loudness summary and searchable speech. Nothing leaves your machine. Setup for Claude Code:
39
+
40
+ ```sh
41
+ brew install ffmpeg uv
42
+ git clone https://github.com/tlq5l/agentic-video.git && cd agentic-video
43
+ uv venv --python 3.12 .venv && uv pip install --python .venv/bin/python -r requirements.txt
44
+ claude mcp add -s user agentic-video -e PYTHONPATH="$PWD" -- "$PWD/.venv/bin/python" -m src.executor.mcp_server
45
+ ```
46
+
47
+ Then ask: "Use agentic-video to review `/path/to/video.mp4`." Other clients and details: [Run the MCP server](#run-the-mcp-server).
48
+
49
+ **Status:** experimental. The author uses it every day; support is best-effort. Issues and pull requests are welcome, but expect slow replies.
50
+
51
+ ## What it gives an agent
52
+
53
+ The MCP server exposes 22 tools (full schemas in `src/adapters/mcp_schemas.json`):
54
+
55
+ - **Look:** `review_video` (first look in one call: metadata, contact sheet, cuts and a loudness summary), `probe_video` (duration, fps, size, codecs, audio), `contact_sheet`, `overview_chunks` (consecutive sheets across a long video), `inspect_window` / `inspect_windows` (dense frames for short ranges), `inspect_moments` (frames around given instants), `refine_temporal_beam` (zoom into candidate windows).
56
+ - **Listen:** `transcribe` (timestamped speech, cached), `search_transcript` (find when words are spoken).
57
+ - **Find:** `detect_cuts` (hard cuts and animated scene changes), `check_frame_cadence` (stretches where frames repeat so the picture updates less often than the frame rate, such as 30 fps padded to 60), `build_visual_index` + `search_visual` (local CLIP search for things that are visible, optional).
58
+ - **Count and track:** `count_occurrences` (separate appearances of an object or on-screen text), `count_repetitions` (cycles of a repeated action), `track_region_changes` / `track_region_events` (changes inside one fixed rectangle).
59
+ - **Audio and sync:** `audio_onsets`, `loudness_timeline`, `spectrogram_window`, `sync_check` (cuts and sound cues against measured audio).
60
+
61
+ There is also a command-line checker for rendered videos: `python -m src.loop check <video>` measures sync, loudness, onsets, cuts and some picture faults, then writes `report.md` plus evidence images. `python -m src.loop cadence <video>` prints the `check_frame_cadence` result as JSON.
62
+
63
+ `AGENTS.md` is a guide for agents on which tool to use when. `FEATURES.md` maps each feature to its code and tests.
64
+
65
+ ## Install (macOS)
66
+
67
+ You need Homebrew, FFmpeg, Git and [uv](https://docs.astral.sh/uv/). Tested with Python 3.12 on Apple silicon.
68
+
69
+ ```sh
70
+ brew install ffmpeg uv
71
+ git clone https://github.com/tlq5l/agentic-video.git
72
+ cd agentic-video
73
+ uv venv --python 3.12 .venv
74
+ uv pip install --python .venv/bin/python -r requirements.txt pytest
75
+ .venv/bin/python -m pytest -q # optional: about 3 minutes
76
+ ```
77
+
78
+ The test run is optional for users.
79
+
80
+ To lint before every commit (`uvx ruff check .`, the core rules in `ruff.toml`), turn the hook on once per clone: `git config core.hooksPath .githooks`.
81
+
82
+ What is macOS-only:
83
+
84
+ - On-screen text matching in `count_occurrences` (`text=`) uses Apple Vision through pyobjc.
85
+ - The bench-v1 harness uses `sandbox-exec`; some tests and generators use `say`. Tests that need a missing tool skip themselves.
86
+
87
+ The core tools should also work on Linux with FFmpeg installed, but the author has not tested that.
88
+
89
+ ### Optional: faster, more accurate speech (whisper.cpp turbo)
90
+
91
+ By default `transcribe` uses faster-whisper on the CPU (`tiny`, `base` or `small`; weights are downloaded on first use). On Apple silicon, whisper.cpp with the large-v3-turbo model is much faster and more accurate:
92
+
93
+ ```sh
94
+ brew install whisper-cpp
95
+ mkdir -p ~/.cache/whisper.cpp
96
+ curl -L -o ~/.cache/whisper.cpp/ggml-large-v3-turbo-q5_0.bin \
97
+ https://huggingface.co/ggerganov/whisper.cpp/resolve/main/ggml-large-v3-turbo-q5_0.bin
98
+ ```
99
+
100
+ Set `AGENTIC_VIDEO_WHISPER_CPP_MODEL` if you keep the model somewhere else. When it is installed, `turbo` becomes the default model.
101
+
102
+ ### Optional: visual search (CLIP) and on-screen text
103
+
104
+ ```sh
105
+ uv pip install --python .venv/bin/python -r requirements-visual.txt
106
+ .venv/bin/python -c 'from huggingface_hub import snapshot_download; snapshot_download(repo_id="openai/clip-vit-base-patch32", revision="3d74acf9a28c67741b2f4f2ea7635f0aaf6f0268", allow_patterns=["*.json", "*.txt", "pytorch_model.bin"])'
107
+ ```
108
+
109
+ This installs PyTorch, Transformers and (on macOS) the Apple Vision bindings, and downloads about 605 MB of CLIP weights. The server only loads local files and never calls a paid API. Without these, `search_visual` and `build_visual_index` return an error that explains the setup.
110
+
111
+ ## Run the MCP server
112
+
113
+ The server speaks MCP over stdio, one JSON message per line:
114
+
115
+ ```sh
116
+ .venv/bin/python -m src.executor.mcp_server
117
+ ```
118
+
119
+ To add it to an MCP client (Claude Code, Claude Desktop, Cursor and others), use the venv's Python and put the repository on `PYTHONPATH`, so the server starts from any folder:
120
+
121
+ ```json
122
+ {
123
+ "mcpServers": {
124
+ "agentic-video": {
125
+ "command": "/absolute/path/to/agentic-video/.venv/bin/python",
126
+ "args": ["-m", "src.executor.mcp_server"],
127
+ "env": { "PYTHONPATH": "/absolute/path/to/agentic-video" }
128
+ }
129
+ }
130
+ }
131
+ ```
132
+
133
+ Give tools absolute video paths. Results are cached under `~/.cache/agentic-video` (change it with `AGENTIC_VIDEO_CACHE_DIR`).
134
+
135
+ ### Add it to Claude Code (one command)
136
+
137
+ Run this from the cloned folder (it uses the current folder's path). `-s user` makes the tool available in every project, not only this folder:
138
+
139
+ ```sh
140
+ claude mcp add -s user agentic-video -e PYTHONPATH="$PWD" -- "$PWD/.venv/bin/python" -m src.executor.mcp_server
141
+ ```
142
+
143
+ By default results stay small enough for Claude Code: images are saved as JPEG files and the result gives their `file_path` (the agent opens the file), and a long `transcribe` result lists the first part of the transcript plus a `transcript_path` file for the rest. A client that renders images from the result itself can add `-e AGENTIC_VIDEO_INLINE_IMAGES=1`; results then carry base64 images and can pass 1 MB. Changed: earlier versions included base64 images by default; if you relied on that, set `AGENTIC_VIDEO_INLINE_IMAGES=1` to restore it.
144
+
145
+ ### Tell your agent to use it (paste into your AGENTS.md or CLAUDE.md)
146
+
147
+ An always-loaded note works better than hoping the agent finds the tool:
148
+
149
+ ```md
150
+ ## Video files (agentic-video MCP)
151
+ You cannot watch video. For any .mp4/.mov/.webm question, use the agentic-video MCP tools; never guess from the filename.
152
+ - First look: `review_video` with an absolute path. It returns metadata, a contact sheet, cuts and loudness. Open the JPEG at `file_path` to see the frames.
153
+ - Spoken words: `search_transcript` (when is X said) or `transcribe`. Do this before looking at frames.
154
+ - A short range: `inspect_window` (start_sec, end_sec). Counting: `count_occurrences`. Sync and audio faults: `sync_check`, `loudness_timeline`.
155
+ - Sampling can miss brief events and a missing hit is not proof. Quote the burned-in timestamps. Full guide: AGENTS.md in the agentic-video repo.
156
+ ```
157
+
158
+ ### Five-line example
159
+
160
+ From the repository folder: a handshake, the video's metadata, and a 6-frame contact sheet (its JPEG path is in `file_path`):
161
+
162
+ ```sh
163
+ printf '%s\n' \
164
+ '{"jsonrpc":"2.0","id":1,"method":"initialize","params":{}}' \
165
+ '{"jsonrpc":"2.0","id":2,"method":"tools/call","params":{"name":"probe_video","arguments":{"source":"fixtures/reference_videos/flower.mp4"}}}' \
166
+ '{"jsonrpc":"2.0","id":3,"method":"tools/call","params":{"name":"contact_sheet","arguments":{"source":"fixtures/reference_videos/flower.mp4","samples":6,"cols":3}}}' \
167
+ | .venv/bin/python -m src.executor.mcp_server
168
+ ```
169
+
170
+ The same from Python:
171
+
172
+ ```python
173
+ from src.retrieval.engine import AgenticVideoEngine
174
+
175
+ engine = AgenticVideoEngine("fixtures/reference_videos/flower.mp4")
176
+ print(engine.metadata.duration_sec) # 5.005
177
+ print(engine.overview(samples=6, cols=3).file_path) # contact sheet JPEG
178
+ ```
179
+
180
+ ## Results so far
181
+
182
+ These are the author's own small tests, not independent benchmarks. The raw runs are not part of this repository.
183
+
184
+ - **Planted faults:** in promo videos with 20 deliberately planted faults, the checker (`python -m src.loop check`) found 14 of 20, with 2 false alarms. Gemini in agentic video mode found 4 of 20.
185
+ - **bench-v1 (`benchmarks/bench_v1`):** on the author's small benchmark, Claude using these tools beat Gemini's agentic video mode at counting, finding moments and long-video search.
186
+ - **LVBench (public long-video benchmark):** it scored about 86%. Gemini's published score is 88.6%, so it does not beat Gemini there.
187
+
188
+ It does not beat Gemini's video understanding in general.
189
+
190
+ ## Limits
191
+
192
+ - **Images come back as files.** Image tools return `file_path`, not an MCP image content block; the base64 copy in `structuredContent` is off by default (set `AGENTIC_VIDEO_INLINE_IMAGES=1` to include it). Many clients show the agent only the JSON text, so the agent has to open the JPEG at `file_path` itself (for example with its file-reading tool).
193
+ - **Sampling can miss things.** Contact sheets and visual search look at sampled frames; something brief between samples can be missed, and a missing hit does not prove absence. Visual search runs CLIP on the CPU and is slow on long videos.
194
+ - **Transcripts can invent lines.** Whisper (especially turbo) can invent lines over music or silence. A line repeated 3 or more times in a row is flagged `suspect`; a single invented line is not.
195
+ - **Cuts can be missed.** A hard cut between two similar pictures that scores under the 0.25 threshold can be missed.
196
+ - **Counting and sync use heuristics** tuned on the author's videos. Treat their output as evidence to check, not as ground truth.
197
+ - **The fix loop needs extra tools.** `python -m src.loop run` calls the Codex CLI as its fixer (default model ladder in `src/loop.py`). The optional `--judge jev` needs `TYPESAFE_API_KEY` or `OPENROUTER_API_KEY` in the environment.
198
+ - **bench-v1 needs accounts.** Running it needs the Codex CLI, `GEMINI_API_KEY` in the environment, Node.js and macOS `sandbox-exec`; see `benchmarks/bench_v1/README.md`.
199
+ - **No stable API.** Tool names and outputs may change between commits.
200
+
201
+ ## Repository layout
202
+
203
+ - `src/`: the library (`media/`, `transcript/`, `retrieval/`, `core/`), the MCP server (`executor/mcp_server.py`), the checker (`loop.py`) and tool schemas (`adapters/`).
204
+ - `tests/`: the pytest suite. `evals/adversarial_runner.py` holds the failure-injection checks that `tests/test_adversarial_failures.py` runs.
205
+ - `benchmarks/bench_v1/`: the blind three-contestant benchmark harness. Its data and answer key live outside the repo.
206
+ - `benchmarks/dev/count_dev/`: a small development set for the counting tools.
207
+ - `scripts/generate_synthetic_benchmark.py`: regenerates the synthetic fixture video.
208
+ - `fixtures/`: small test videos (see Media credits).
209
+ - `docs/`: architecture notes and per-feature pages.
210
+
211
+ ## Media credits
212
+
213
+ - `fixtures/reference_videos/sample_10s.mp4`: a 10-second excerpt, with no audio, of *Big Buck Bunny* (Sunflower version). (c) 2008 Blender Foundation, www.bigbuckbunny.org / peach.blender.org; Sunflower version by Janus Bager Kristensen, 2013 (bbb3d.renderfarming.net). Licensed under [Creative Commons Attribution 3.0](https://creativecommons.org/licenses/by/3.0/).
214
+ - `fixtures/reference_videos/flower.mp4`: a sample video from MDN Web Docs, released under CC0 (public domain).
215
+ - `fixtures/synthetic_bench_60s.mp4` with `.srt`, `.vtt` and `fixtures/synthetic_ground_truth.json`: generated by this repository's `scripts/generate_synthetic_benchmark.py`. Same license as the code.
216
+
217
+ ## License
218
+
219
+ MIT. See `LICENSE`.
@@ -0,0 +1,192 @@
1
+ # agentic-video
2
+
3
+ agentic-video lets an AI agent that reads text and images, but not video, work with video files on your own machine. It is a Python library plus a stdio MCP server. The agent asks small, targeted questions ("show me 12 frames from 0:40 to 1:10", "when is 'launch' spoken?") and gets back measurements, transcripts and contact sheets: grids of frames, each with its timestamp burned into the pixels. Nothing is uploaded; everything runs locally with FFmpeg, Whisper and optional local models.
4
+
5
+ **Install:** `brew install ffmpeg`, then add it to Claude Code with `claude mcp add -s user agentic-video -- uvx agentic-video` (or `pipx install agentic-video`). Other clients: [Run the MCP server](#run-the-mcp-server).
6
+
7
+ ![A contact sheet made by agentic-video from a 5-second clip: six frames, each with its timestamp burned in](https://raw.githubusercontent.com/tlq5l/agentic-video/main/docs/images/contact-sheet.jpg)
8
+
9
+ *One `contact_sheet` call on a 5-second clip: six frames, each stamped with its time, as a single image the agent can read.*
10
+
11
+ In 2 minutes (macOS) your agent can answer "what happens in this video?" and "when is X said?" for a local video file. You get the length and size, a contact sheet image with timestamps, the cuts, a loudness summary and searchable speech. Nothing leaves your machine. Setup for Claude Code:
12
+
13
+ ```sh
14
+ brew install ffmpeg uv
15
+ git clone https://github.com/tlq5l/agentic-video.git && cd agentic-video
16
+ uv venv --python 3.12 .venv && uv pip install --python .venv/bin/python -r requirements.txt
17
+ claude mcp add -s user agentic-video -e PYTHONPATH="$PWD" -- "$PWD/.venv/bin/python" -m src.executor.mcp_server
18
+ ```
19
+
20
+ Then ask: "Use agentic-video to review `/path/to/video.mp4`." Other clients and details: [Run the MCP server](#run-the-mcp-server).
21
+
22
+ **Status:** experimental. The author uses it every day; support is best-effort. Issues and pull requests are welcome, but expect slow replies.
23
+
24
+ ## What it gives an agent
25
+
26
+ The MCP server exposes 22 tools (full schemas in `src/adapters/mcp_schemas.json`):
27
+
28
+ - **Look:** `review_video` (first look in one call: metadata, contact sheet, cuts and a loudness summary), `probe_video` (duration, fps, size, codecs, audio), `contact_sheet`, `overview_chunks` (consecutive sheets across a long video), `inspect_window` / `inspect_windows` (dense frames for short ranges), `inspect_moments` (frames around given instants), `refine_temporal_beam` (zoom into candidate windows).
29
+ - **Listen:** `transcribe` (timestamped speech, cached), `search_transcript` (find when words are spoken).
30
+ - **Find:** `detect_cuts` (hard cuts and animated scene changes), `check_frame_cadence` (stretches where frames repeat so the picture updates less often than the frame rate, such as 30 fps padded to 60), `build_visual_index` + `search_visual` (local CLIP search for things that are visible, optional).
31
+ - **Count and track:** `count_occurrences` (separate appearances of an object or on-screen text), `count_repetitions` (cycles of a repeated action), `track_region_changes` / `track_region_events` (changes inside one fixed rectangle).
32
+ - **Audio and sync:** `audio_onsets`, `loudness_timeline`, `spectrogram_window`, `sync_check` (cuts and sound cues against measured audio).
33
+
34
+ There is also a command-line checker for rendered videos: `python -m src.loop check <video>` measures sync, loudness, onsets, cuts and some picture faults, then writes `report.md` plus evidence images. `python -m src.loop cadence <video>` prints the `check_frame_cadence` result as JSON.
35
+
36
+ `AGENTS.md` is a guide for agents on which tool to use when. `FEATURES.md` maps each feature to its code and tests.
37
+
38
+ ## Install (macOS)
39
+
40
+ You need Homebrew, FFmpeg, Git and [uv](https://docs.astral.sh/uv/). Tested with Python 3.12 on Apple silicon.
41
+
42
+ ```sh
43
+ brew install ffmpeg uv
44
+ git clone https://github.com/tlq5l/agentic-video.git
45
+ cd agentic-video
46
+ uv venv --python 3.12 .venv
47
+ uv pip install --python .venv/bin/python -r requirements.txt pytest
48
+ .venv/bin/python -m pytest -q # optional: about 3 minutes
49
+ ```
50
+
51
+ The test run is optional for users.
52
+
53
+ To lint before every commit (`uvx ruff check .`, the core rules in `ruff.toml`), turn the hook on once per clone: `git config core.hooksPath .githooks`.
54
+
55
+ What is macOS-only:
56
+
57
+ - On-screen text matching in `count_occurrences` (`text=`) uses Apple Vision through pyobjc.
58
+ - The bench-v1 harness uses `sandbox-exec`; some tests and generators use `say`. Tests that need a missing tool skip themselves.
59
+
60
+ The core tools should also work on Linux with FFmpeg installed, but the author has not tested that.
61
+
62
+ ### Optional: faster, more accurate speech (whisper.cpp turbo)
63
+
64
+ By default `transcribe` uses faster-whisper on the CPU (`tiny`, `base` or `small`; weights are downloaded on first use). On Apple silicon, whisper.cpp with the large-v3-turbo model is much faster and more accurate:
65
+
66
+ ```sh
67
+ brew install whisper-cpp
68
+ mkdir -p ~/.cache/whisper.cpp
69
+ curl -L -o ~/.cache/whisper.cpp/ggml-large-v3-turbo-q5_0.bin \
70
+ https://huggingface.co/ggerganov/whisper.cpp/resolve/main/ggml-large-v3-turbo-q5_0.bin
71
+ ```
72
+
73
+ Set `AGENTIC_VIDEO_WHISPER_CPP_MODEL` if you keep the model somewhere else. When it is installed, `turbo` becomes the default model.
74
+
75
+ ### Optional: visual search (CLIP) and on-screen text
76
+
77
+ ```sh
78
+ uv pip install --python .venv/bin/python -r requirements-visual.txt
79
+ .venv/bin/python -c 'from huggingface_hub import snapshot_download; snapshot_download(repo_id="openai/clip-vit-base-patch32", revision="3d74acf9a28c67741b2f4f2ea7635f0aaf6f0268", allow_patterns=["*.json", "*.txt", "pytorch_model.bin"])'
80
+ ```
81
+
82
+ This installs PyTorch, Transformers and (on macOS) the Apple Vision bindings, and downloads about 605 MB of CLIP weights. The server only loads local files and never calls a paid API. Without these, `search_visual` and `build_visual_index` return an error that explains the setup.
83
+
84
+ ## Run the MCP server
85
+
86
+ The server speaks MCP over stdio, one JSON message per line:
87
+
88
+ ```sh
89
+ .venv/bin/python -m src.executor.mcp_server
90
+ ```
91
+
92
+ To add it to an MCP client (Claude Code, Claude Desktop, Cursor and others), use the venv's Python and put the repository on `PYTHONPATH`, so the server starts from any folder:
93
+
94
+ ```json
95
+ {
96
+ "mcpServers": {
97
+ "agentic-video": {
98
+ "command": "/absolute/path/to/agentic-video/.venv/bin/python",
99
+ "args": ["-m", "src.executor.mcp_server"],
100
+ "env": { "PYTHONPATH": "/absolute/path/to/agentic-video" }
101
+ }
102
+ }
103
+ }
104
+ ```
105
+
106
+ Give tools absolute video paths. Results are cached under `~/.cache/agentic-video` (change it with `AGENTIC_VIDEO_CACHE_DIR`).
107
+
108
+ ### Add it to Claude Code (one command)
109
+
110
+ Run this from the cloned folder (it uses the current folder's path). `-s user` makes the tool available in every project, not only this folder:
111
+
112
+ ```sh
113
+ claude mcp add -s user agentic-video -e PYTHONPATH="$PWD" -- "$PWD/.venv/bin/python" -m src.executor.mcp_server
114
+ ```
115
+
116
+ By default results stay small enough for Claude Code: images are saved as JPEG files and the result gives their `file_path` (the agent opens the file), and a long `transcribe` result lists the first part of the transcript plus a `transcript_path` file for the rest. A client that renders images from the result itself can add `-e AGENTIC_VIDEO_INLINE_IMAGES=1`; results then carry base64 images and can pass 1 MB. Changed: earlier versions included base64 images by default; if you relied on that, set `AGENTIC_VIDEO_INLINE_IMAGES=1` to restore it.
117
+
118
+ ### Tell your agent to use it (paste into your AGENTS.md or CLAUDE.md)
119
+
120
+ An always-loaded note works better than hoping the agent finds the tool:
121
+
122
+ ```md
123
+ ## Video files (agentic-video MCP)
124
+ You cannot watch video. For any .mp4/.mov/.webm question, use the agentic-video MCP tools; never guess from the filename.
125
+ - First look: `review_video` with an absolute path. It returns metadata, a contact sheet, cuts and loudness. Open the JPEG at `file_path` to see the frames.
126
+ - Spoken words: `search_transcript` (when is X said) or `transcribe`. Do this before looking at frames.
127
+ - A short range: `inspect_window` (start_sec, end_sec). Counting: `count_occurrences`. Sync and audio faults: `sync_check`, `loudness_timeline`.
128
+ - Sampling can miss brief events and a missing hit is not proof. Quote the burned-in timestamps. Full guide: AGENTS.md in the agentic-video repo.
129
+ ```
130
+
131
+ ### Five-line example
132
+
133
+ From the repository folder: a handshake, the video's metadata, and a 6-frame contact sheet (its JPEG path is in `file_path`):
134
+
135
+ ```sh
136
+ printf '%s\n' \
137
+ '{"jsonrpc":"2.0","id":1,"method":"initialize","params":{}}' \
138
+ '{"jsonrpc":"2.0","id":2,"method":"tools/call","params":{"name":"probe_video","arguments":{"source":"fixtures/reference_videos/flower.mp4"}}}' \
139
+ '{"jsonrpc":"2.0","id":3,"method":"tools/call","params":{"name":"contact_sheet","arguments":{"source":"fixtures/reference_videos/flower.mp4","samples":6,"cols":3}}}' \
140
+ | .venv/bin/python -m src.executor.mcp_server
141
+ ```
142
+
143
+ The same from Python:
144
+
145
+ ```python
146
+ from src.retrieval.engine import AgenticVideoEngine
147
+
148
+ engine = AgenticVideoEngine("fixtures/reference_videos/flower.mp4")
149
+ print(engine.metadata.duration_sec) # 5.005
150
+ print(engine.overview(samples=6, cols=3).file_path) # contact sheet JPEG
151
+ ```
152
+
153
+ ## Results so far
154
+
155
+ These are the author's own small tests, not independent benchmarks. The raw runs are not part of this repository.
156
+
157
+ - **Planted faults:** in promo videos with 20 deliberately planted faults, the checker (`python -m src.loop check`) found 14 of 20, with 2 false alarms. Gemini in agentic video mode found 4 of 20.
158
+ - **bench-v1 (`benchmarks/bench_v1`):** on the author's small benchmark, Claude using these tools beat Gemini's agentic video mode at counting, finding moments and long-video search.
159
+ - **LVBench (public long-video benchmark):** it scored about 86%. Gemini's published score is 88.6%, so it does not beat Gemini there.
160
+
161
+ It does not beat Gemini's video understanding in general.
162
+
163
+ ## Limits
164
+
165
+ - **Images come back as files.** Image tools return `file_path`, not an MCP image content block; the base64 copy in `structuredContent` is off by default (set `AGENTIC_VIDEO_INLINE_IMAGES=1` to include it). Many clients show the agent only the JSON text, so the agent has to open the JPEG at `file_path` itself (for example with its file-reading tool).
166
+ - **Sampling can miss things.** Contact sheets and visual search look at sampled frames; something brief between samples can be missed, and a missing hit does not prove absence. Visual search runs CLIP on the CPU and is slow on long videos.
167
+ - **Transcripts can invent lines.** Whisper (especially turbo) can invent lines over music or silence. A line repeated 3 or more times in a row is flagged `suspect`; a single invented line is not.
168
+ - **Cuts can be missed.** A hard cut between two similar pictures that scores under the 0.25 threshold can be missed.
169
+ - **Counting and sync use heuristics** tuned on the author's videos. Treat their output as evidence to check, not as ground truth.
170
+ - **The fix loop needs extra tools.** `python -m src.loop run` calls the Codex CLI as its fixer (default model ladder in `src/loop.py`). The optional `--judge jev` needs `TYPESAFE_API_KEY` or `OPENROUTER_API_KEY` in the environment.
171
+ - **bench-v1 needs accounts.** Running it needs the Codex CLI, `GEMINI_API_KEY` in the environment, Node.js and macOS `sandbox-exec`; see `benchmarks/bench_v1/README.md`.
172
+ - **No stable API.** Tool names and outputs may change between commits.
173
+
174
+ ## Repository layout
175
+
176
+ - `src/`: the library (`media/`, `transcript/`, `retrieval/`, `core/`), the MCP server (`executor/mcp_server.py`), the checker (`loop.py`) and tool schemas (`adapters/`).
177
+ - `tests/`: the pytest suite. `evals/adversarial_runner.py` holds the failure-injection checks that `tests/test_adversarial_failures.py` runs.
178
+ - `benchmarks/bench_v1/`: the blind three-contestant benchmark harness. Its data and answer key live outside the repo.
179
+ - `benchmarks/dev/count_dev/`: a small development set for the counting tools.
180
+ - `scripts/generate_synthetic_benchmark.py`: regenerates the synthetic fixture video.
181
+ - `fixtures/`: small test videos (see Media credits).
182
+ - `docs/`: architecture notes and per-feature pages.
183
+
184
+ ## Media credits
185
+
186
+ - `fixtures/reference_videos/sample_10s.mp4`: a 10-second excerpt, with no audio, of *Big Buck Bunny* (Sunflower version). (c) 2008 Blender Foundation, www.bigbuckbunny.org / peach.blender.org; Sunflower version by Janus Bager Kristensen, 2013 (bbb3d.renderfarming.net). Licensed under [Creative Commons Attribution 3.0](https://creativecommons.org/licenses/by/3.0/).
187
+ - `fixtures/reference_videos/flower.mp4`: a sample video from MDN Web Docs, released under CC0 (public domain).
188
+ - `fixtures/synthetic_bench_60s.mp4` with `.srt`, `.vtt` and `fixtures/synthetic_ground_truth.json`: generated by this repository's `scripts/generate_synthetic_benchmark.py`. Same license as the code.
189
+
190
+ ## License
191
+
192
+ MIT. See `LICENSE`.
@@ -0,0 +1,43 @@
1
+ [build-system]
2
+ requires = ["hatchling", "hatch-requirements-txt"]
3
+ build-backend = "hatchling.build"
4
+
5
+ [project]
6
+ name = "agentic-video"
7
+ version = "0.1.0"
8
+ description = "Local video tools for AI agents that read text and images but not video: contact sheets, transcripts, cut, loudness and sync checks, served over MCP."
9
+ readme = "README.md"
10
+ license = "MIT"
11
+ license-files = ["LICENSE"]
12
+ requires-python = ">=3.10"
13
+ authors = [{ name = "tlq5l" }]
14
+ keywords = ["mcp", "video", "agents", "ffmpeg", "whisper", "contact-sheet"]
15
+ classifiers = [
16
+ "Development Status :: 3 - Alpha",
17
+ "Intended Audience :: Developers",
18
+ "Programming Language :: Python :: 3",
19
+ "Topic :: Multimedia :: Video",
20
+ ]
21
+ dynamic = ["dependencies", "optional-dependencies"]
22
+
23
+ [project.urls]
24
+ Homepage = "https://github.com/tlq5l/agentic-video"
25
+ Repository = "https://github.com/tlq5l/agentic-video"
26
+ Issues = "https://github.com/tlq5l/agentic-video/issues"
27
+
28
+ [project.scripts]
29
+ agentic-video = "src.executor.mcp_server:main"
30
+ agentic-video-check = "src.loop:main"
31
+
32
+ # Dependencies stay in requirements*.txt so the README install and the package agree.
33
+ [tool.hatch.metadata.hooks.requirements_txt]
34
+ files = ["requirements.txt"]
35
+
36
+ [tool.hatch.metadata.hooks.requirements_txt.optional-dependencies]
37
+ visual = ["requirements-visual.txt"]
38
+
39
+ [tool.hatch.build.targets.wheel]
40
+ packages = ["src"]
41
+
42
+ [tool.hatch.build.targets.sdist]
43
+ include = ["src", "/README.md", "LICENSE", "requirements.txt", "requirements-visual.txt"]
@@ -0,0 +1,6 @@
1
+ # Optional local visual retrieval; CLIP weights are approximately 605 MB.
2
+ torch>=2.6,<3
3
+ transformers>=4.45,<5
4
+ Pillow>=10
5
+ # On-screen text matching (count_occurrences text=) uses Apple Vision through pyobjc; macOS only, fully offline.
6
+ pyobjc-framework-Vision>=10; sys_platform == "darwin"
@@ -0,0 +1,6 @@
1
+ numpy>=1.21
2
+ Pillow>=10
3
+ # Local speech-to-text for the tiny, base and small models (turbo uses whisper.cpp instead; see README).
4
+ faster-whisper>=1.0
5
+ # faster-whisper 1.2.1 passes av.open(metadata_errors=...), which PyAV 19 removed.
6
+ av<19