videolyzer 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.
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright [yyyy] [name of copyright owner]
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
200
+ implied. See the License for the specific language governing
201
+ permissions and limitations under the License.
@@ -0,0 +1,183 @@
1
+ Metadata-Version: 2.4
2
+ Name: videolyzer
3
+ Version: 0.1.0
4
+ Summary: give agents the ability to understand and deep analyze videos
5
+ Author: Neguiolidas
6
+ License: Apache-2.0
7
+ Project-URL: Homepage, https://github.com/Neguiolidas/videolyzer
8
+ Project-URL: Repository, https://github.com/Neguiolidas/videolyzer
9
+ Project-URL: Issues, https://github.com/Neguiolidas/videolyzer/issues
10
+ Keywords: video,video-analysis,ai-agents,multimodal,gemini
11
+ Classifier: Development Status :: 3 - Alpha
12
+ Classifier: Intended Audience :: Developers
13
+ Classifier: Programming Language :: Python :: 3
14
+ Classifier: Programming Language :: Python :: 3.10
15
+ Classifier: Programming Language :: Python :: 3.11
16
+ Classifier: Programming Language :: Python :: 3.12
17
+ Classifier: Topic :: Multimedia :: Video
18
+ Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
19
+ Requires-Python: >=3.10
20
+ Description-Content-Type: text/markdown
21
+ License-File: LICENSE
22
+ Requires-Dist: opencv-python>=4.8
23
+ Requires-Dist: numpy>=1.24
24
+ Dynamic: license-file
25
+
26
+ # Videolyzer
27
+
28
+ **Give agents the ability to understand and deep analyze videos.**
29
+
30
+ A single CLI that turns a video (YouTube URL or local file) into a structured Markdown report: detected scenes with timestamps, transcript aligned per scene, key moments, tone/emotion, and temporal verification. Built for agents that need to *watch* video, not just transcribe it.
31
+
32
+ ## Quick start
33
+
34
+ ```bash
35
+ pip install -r requirements.txt # opencv + numpy (only needed for the subtle-motion pass)
36
+
37
+ export VIDEOLYZER_API_KEY="your-key"
38
+
39
+ # URL mode (gemini only, no download)
40
+ python videolyzer.py "https://www.youtube.com/watch?v=..." --out report.md
41
+
42
+ # Local file mode
43
+ python videolyzer.py ./my-video.mp4 --out report.md
44
+
45
+ # Any OpenAI-compatible provider (Groq, Together, OpenAI, ...)
46
+ python videolyzer.py ./my-video.mp4 --provider openai --model gpt-4o \
47
+ --base-url https://api.groq.com/openai/v1 --out report.md
48
+
49
+ # Auxiliary model (any OpenAI-compatible vision endpoint)
50
+ export VIDEOLYZER_AUX_MODEL="your-vision-model"
51
+ export VIDEOLYZER_AUX_BASE_URL="https://your-endpoint/v1"
52
+ export VIDEOLYZER_AUX_API_KEY="your-key"
53
+
54
+ # Modo Rapido: fast keyframe analysis on the aux model (no full upload)
55
+ python videolyzer.py ./my-video.mp4 --fast --out report.md
56
+
57
+ # Second opinion: primary analysis + aux model cross-check
58
+ python videolyzer.py ./my-video.mp4 --verify --out report.md
59
+ ```
60
+
61
+ ## Modes: URL vs local file
62
+
63
+ | | URL mode | Local file mode |
64
+ |---|---|---|
65
+ | Providers | `gemini` only | `gemini` and `openai` |
66
+ | Download | None. The URL goes straight to the model (`file_data`) | None for gemini (full upload via Files API); keyframes extracted locally for openai |
67
+ | Temporal understanding | Native: the model samples the timeline itself | Native (gemini) / keyframe-based (openai) |
68
+ | Subtle-motion detection | **Not available** (would require downloading the video) | Available: optical-flow pass flags small-amplitude motion segments and injects them into the prompt as an explicit hint |
69
+ | Cut detection | **Not available** (would require downloading the video) | Available: ffmpeg scene detection finds exact hard-cut timestamps (`--cut-threshold`, default 0.4); they go into the prompt as scene-boundary anchors |
70
+ | Speed | Fastest | Slower (upload + optional motion/cut passes) |
71
+
72
+ ### URL mode (gemini only)
73
+
74
+ No download, no frame extraction. The video URL is passed to the model and it does its own temporal sampling. Best for quick overviews of online videos. Limitation: subtle motion (small-amplitude movement) can be missed, because the pre-analysis optical-flow pass cannot run without the pixels.
75
+
76
+ ### Local file mode
77
+
78
+ The file is validated with `ffprobe` (codec, duration, integrity — no frames extracted), then two deterministic passes run locally before the model sees anything:
79
+
80
+ - **Cut detection** (ffmpeg scene detection, `--cut-threshold` default 0.4, skip with `--no-cuts`): finds exact hard-cut timestamps. They go into the prompt as scene-boundary anchors ("a new scene starts at each cut timestamp — do NOT merge scenes across a cut"), so the model aligns on measured cuts instead of guessing approximate boundaries.
81
+ - **Subtle-motion pass** (Farneback optical flow, 2 fps sampling, 3×3 grid): measures motion magnitude per segment and flags anything above background noise (median + 4·1.4826·MAD, robust to outliers). The flagged timestamps, region and dominant axis go into the prompt as an explicit hint ("do NOT say these segments are static").
82
+
83
+ Then:
84
+
85
+ - **gemini:** the whole file is uploaded through the Files API; the model samples the timeline itself.
86
+ - **openai (any OpenAI-compatible API):** `N` evenly spaced keyframes (`--keyframes`, default 8) are extracted with ffmpeg and sent as images through `/v1/chat/completions` (vision). URL input is not supported with this provider.
87
+
88
+ ## Auxiliary model & Modo Rapido
89
+
90
+ The auxiliary model is a second, independent multimodal model — any OpenAI-compatible vision endpoint (no provider hardcoded). It plays three roles:
91
+
92
+ | Role | How |
93
+ |---|---|
94
+ | **Second opinion** (`--verify`) | After the primary analysis, the aux model reviews the report against keyframes: agrees/disagrees per scene, flags temporal-order mistakes. Appended as a "Second opinion" section. |
95
+ | **Temporal verifier** | Built into every aux pass: the prompt forces motion verbs and event-order checks across keyframes. |
96
+ | **Fallback** | If the primary analysis fails and an aux model is configured, Videolyzer automatically retries with the aux model on keyframes. |
97
+
98
+ **Modo Rapido** (`--fast`) skips the full video upload entirely and runs the whole analysis on the auxiliary model with evenly spaced keyframes (+ the optical-flow subtle-motion hints). Much faster and cheaper than the native path — best when only "what appears" matters and fine motion detail is not critical. Requires the aux model to be configured.
99
+
100
+ Configuration (flags take precedence over env vars):
101
+
102
+ | Flag | Env var | Default |
103
+ |---|---|---|
104
+ | `--aux-model` | `VIDEOLYZER_AUX_MODEL` | — (required to enable) |
105
+ | `--aux-base-url` | `VIDEOLYZER_AUX_BASE_URL` | `https://api.openai.com/v1` |
106
+ | `--aux-api-key` | `VIDEOLYZER_AUX_API_KEY` | — (required) |
107
+
108
+ ```bash
109
+ # One-off
110
+ python videolyzer.py video.mp4 --fast \
111
+ --aux-model my-vision-model \
112
+ --aux-base-url https://my-endpoint/v1 \
113
+ --aux-api-key sk-...
114
+
115
+ # Or via env vars (then just --fast / --verify)
116
+ export VIDEOLYZER_AUX_MODEL="my-vision-model"
117
+ export VIDEOLYZER_AUX_BASE_URL="https://my-endpoint/v1"
118
+ export VIDEOLYZER_AUX_API_KEY="sk-..."
119
+ ```
120
+
121
+ ## CLI reference
122
+
123
+ ```
124
+ videolyzer.py <source> [--provider gemini|openai] [--model NAME]
125
+ [--base-url URL] [--api-key KEY]
126
+ [--aux-model NAME] [--aux-base-url URL] [--aux-api-key KEY]
127
+ [--fast] [--verify]
128
+ [--out report.md] [--prompt "..."] [--no-motion] [--no-cuts]
129
+ [--cut-threshold 0.4] [--keyframes 8]
130
+ ```
131
+
132
+ | Flag | Default | Description |
133
+ |---|---|---|
134
+ | `source` | — | YouTube URL (gemini only) or local file path |
135
+ | `--provider` | `gemini` | `gemini` (Google AI Studio) or `openai` (any OpenAI-compatible API) |
136
+ | `--model` | `gemini-3.1-flash-lite` | Model name. For `openai`, pass a vision-capable model of your provider |
137
+ | `--base-url` | — | Custom API base URL (openai provider). Default `https://api.openai.com/v1` |
138
+ | `--api-key` | — | API key. Or set `VIDEOLYZER_API_KEY` (`GEMINI_API_KEY` / `OPENAI_API_KEY` also work) |
139
+ | `--aux-model` | — | Aux multimodal model name (any OpenAI-compatible vision endpoint; or `VIDEOLYZER_AUX_MODEL`) |
140
+ | `--aux-base-url` | `https://api.openai.com/v1` | Aux model endpoint (or `VIDEOLYZER_AUX_BASE_URL`) |
141
+ | `--aux-api-key` | — | Aux model key (or `VIDEOLYZER_AUX_API_KEY`) |
142
+ | `--fast` | off | **Modo Rapido**: full analysis on the aux model via keyframes (no upload). Requires `--aux-model` |
143
+ | `--verify` | off | Second opinion: aux model cross-checks the primary report. Requires `--aux-model` |
144
+ | `--out` | stdout | Output `.md` file |
145
+ | `--prompt` | built-in | Custom analysis prompt (overrides the default) |
146
+ | `--no-motion` | off | Skip the optical-flow subtle-motion pass |
147
+ | `--cut-threshold` | 0.4 | Scene-detection threshold for deterministic cut detection. Lower = more sensitive |
148
+ | `--no-cuts` | off | Skip deterministic cut detection |
149
+ | `--keyframes` | 8 | Keyframes for the openai provider / aux model |
150
+
151
+ ## Requirements
152
+
153
+ - Python 3.10+
154
+ - `ffmpeg` / `ffprobe` on PATH (system package)
155
+ - `pip install -r requirements.txt` → `opencv-python`, `numpy` (only needed for the subtle-motion pass; the tool degrades gracefully without them)
156
+
157
+ ## Report format
158
+
159
+ ```markdown
160
+ # Video Analysis
161
+ ## Summary
162
+ ## Scenes (| # | Start | End | Visual description | Audio/speech |)
163
+ ## Aligned transcript
164
+ ## Key moments
165
+ ## Tone and emotion
166
+ ## Temporal verification (motion described with action verbs, cause-effect order checked)
167
+ ```
168
+
169
+ ## How it differs from frame extraction
170
+
171
+ Classic pipelines extract N frames and ask a vision model about each still image. That loses motion: a bouncing ball becomes "ball at left" / "ball at right", and anything between sampled frames is invisible (or hallucinated).
172
+
173
+ Videolyzer instead hands the *video* to the model:
174
+
175
+ 1. **Native temporal sampling** — the model, not our code, decides what to look at along the timeline.
176
+ 2. **Temporal verification** — the prompt forces motion verbs per scene and cause-effect order checks, plus an explicit "motion undetermined" escape hatch instead of invention.
177
+ 3. **Hybrid subtle-motion pass** (local files) — classical CV finds what the model's sampling might skip, and the model is told exactly where to look.
178
+
179
+ See `docs/` for the comparative tests that motivated this design.
180
+
181
+ ## License
182
+
183
+ Apache 2.0 — see [LICENSE](LICENSE).
@@ -0,0 +1,158 @@
1
+ # Videolyzer
2
+
3
+ **Give agents the ability to understand and deep analyze videos.**
4
+
5
+ A single CLI that turns a video (YouTube URL or local file) into a structured Markdown report: detected scenes with timestamps, transcript aligned per scene, key moments, tone/emotion, and temporal verification. Built for agents that need to *watch* video, not just transcribe it.
6
+
7
+ ## Quick start
8
+
9
+ ```bash
10
+ pip install -r requirements.txt # opencv + numpy (only needed for the subtle-motion pass)
11
+
12
+ export VIDEOLYZER_API_KEY="your-key"
13
+
14
+ # URL mode (gemini only, no download)
15
+ python videolyzer.py "https://www.youtube.com/watch?v=..." --out report.md
16
+
17
+ # Local file mode
18
+ python videolyzer.py ./my-video.mp4 --out report.md
19
+
20
+ # Any OpenAI-compatible provider (Groq, Together, OpenAI, ...)
21
+ python videolyzer.py ./my-video.mp4 --provider openai --model gpt-4o \
22
+ --base-url https://api.groq.com/openai/v1 --out report.md
23
+
24
+ # Auxiliary model (any OpenAI-compatible vision endpoint)
25
+ export VIDEOLYZER_AUX_MODEL="your-vision-model"
26
+ export VIDEOLYZER_AUX_BASE_URL="https://your-endpoint/v1"
27
+ export VIDEOLYZER_AUX_API_KEY="your-key"
28
+
29
+ # Modo Rapido: fast keyframe analysis on the aux model (no full upload)
30
+ python videolyzer.py ./my-video.mp4 --fast --out report.md
31
+
32
+ # Second opinion: primary analysis + aux model cross-check
33
+ python videolyzer.py ./my-video.mp4 --verify --out report.md
34
+ ```
35
+
36
+ ## Modes: URL vs local file
37
+
38
+ | | URL mode | Local file mode |
39
+ |---|---|---|
40
+ | Providers | `gemini` only | `gemini` and `openai` |
41
+ | Download | None. The URL goes straight to the model (`file_data`) | None for gemini (full upload via Files API); keyframes extracted locally for openai |
42
+ | Temporal understanding | Native: the model samples the timeline itself | Native (gemini) / keyframe-based (openai) |
43
+ | Subtle-motion detection | **Not available** (would require downloading the video) | Available: optical-flow pass flags small-amplitude motion segments and injects them into the prompt as an explicit hint |
44
+ | Cut detection | **Not available** (would require downloading the video) | Available: ffmpeg scene detection finds exact hard-cut timestamps (`--cut-threshold`, default 0.4); they go into the prompt as scene-boundary anchors |
45
+ | Speed | Fastest | Slower (upload + optional motion/cut passes) |
46
+
47
+ ### URL mode (gemini only)
48
+
49
+ No download, no frame extraction. The video URL is passed to the model and it does its own temporal sampling. Best for quick overviews of online videos. Limitation: subtle motion (small-amplitude movement) can be missed, because the pre-analysis optical-flow pass cannot run without the pixels.
50
+
51
+ ### Local file mode
52
+
53
+ The file is validated with `ffprobe` (codec, duration, integrity — no frames extracted), then two deterministic passes run locally before the model sees anything:
54
+
55
+ - **Cut detection** (ffmpeg scene detection, `--cut-threshold` default 0.4, skip with `--no-cuts`): finds exact hard-cut timestamps. They go into the prompt as scene-boundary anchors ("a new scene starts at each cut timestamp — do NOT merge scenes across a cut"), so the model aligns on measured cuts instead of guessing approximate boundaries.
56
+ - **Subtle-motion pass** (Farneback optical flow, 2 fps sampling, 3×3 grid): measures motion magnitude per segment and flags anything above background noise (median + 4·1.4826·MAD, robust to outliers). The flagged timestamps, region and dominant axis go into the prompt as an explicit hint ("do NOT say these segments are static").
57
+
58
+ Then:
59
+
60
+ - **gemini:** the whole file is uploaded through the Files API; the model samples the timeline itself.
61
+ - **openai (any OpenAI-compatible API):** `N` evenly spaced keyframes (`--keyframes`, default 8) are extracted with ffmpeg and sent as images through `/v1/chat/completions` (vision). URL input is not supported with this provider.
62
+
63
+ ## Auxiliary model & Modo Rapido
64
+
65
+ The auxiliary model is a second, independent multimodal model — any OpenAI-compatible vision endpoint (no provider hardcoded). It plays three roles:
66
+
67
+ | Role | How |
68
+ |---|---|
69
+ | **Second opinion** (`--verify`) | After the primary analysis, the aux model reviews the report against keyframes: agrees/disagrees per scene, flags temporal-order mistakes. Appended as a "Second opinion" section. |
70
+ | **Temporal verifier** | Built into every aux pass: the prompt forces motion verbs and event-order checks across keyframes. |
71
+ | **Fallback** | If the primary analysis fails and an aux model is configured, Videolyzer automatically retries with the aux model on keyframes. |
72
+
73
+ **Modo Rapido** (`--fast`) skips the full video upload entirely and runs the whole analysis on the auxiliary model with evenly spaced keyframes (+ the optical-flow subtle-motion hints). Much faster and cheaper than the native path — best when only "what appears" matters and fine motion detail is not critical. Requires the aux model to be configured.
74
+
75
+ Configuration (flags take precedence over env vars):
76
+
77
+ | Flag | Env var | Default |
78
+ |---|---|---|
79
+ | `--aux-model` | `VIDEOLYZER_AUX_MODEL` | — (required to enable) |
80
+ | `--aux-base-url` | `VIDEOLYZER_AUX_BASE_URL` | `https://api.openai.com/v1` |
81
+ | `--aux-api-key` | `VIDEOLYZER_AUX_API_KEY` | — (required) |
82
+
83
+ ```bash
84
+ # One-off
85
+ python videolyzer.py video.mp4 --fast \
86
+ --aux-model my-vision-model \
87
+ --aux-base-url https://my-endpoint/v1 \
88
+ --aux-api-key sk-...
89
+
90
+ # Or via env vars (then just --fast / --verify)
91
+ export VIDEOLYZER_AUX_MODEL="my-vision-model"
92
+ export VIDEOLYZER_AUX_BASE_URL="https://my-endpoint/v1"
93
+ export VIDEOLYZER_AUX_API_KEY="sk-..."
94
+ ```
95
+
96
+ ## CLI reference
97
+
98
+ ```
99
+ videolyzer.py <source> [--provider gemini|openai] [--model NAME]
100
+ [--base-url URL] [--api-key KEY]
101
+ [--aux-model NAME] [--aux-base-url URL] [--aux-api-key KEY]
102
+ [--fast] [--verify]
103
+ [--out report.md] [--prompt "..."] [--no-motion] [--no-cuts]
104
+ [--cut-threshold 0.4] [--keyframes 8]
105
+ ```
106
+
107
+ | Flag | Default | Description |
108
+ |---|---|---|
109
+ | `source` | — | YouTube URL (gemini only) or local file path |
110
+ | `--provider` | `gemini` | `gemini` (Google AI Studio) or `openai` (any OpenAI-compatible API) |
111
+ | `--model` | `gemini-3.1-flash-lite` | Model name. For `openai`, pass a vision-capable model of your provider |
112
+ | `--base-url` | — | Custom API base URL (openai provider). Default `https://api.openai.com/v1` |
113
+ | `--api-key` | — | API key. Or set `VIDEOLYZER_API_KEY` (`GEMINI_API_KEY` / `OPENAI_API_KEY` also work) |
114
+ | `--aux-model` | — | Aux multimodal model name (any OpenAI-compatible vision endpoint; or `VIDEOLYZER_AUX_MODEL`) |
115
+ | `--aux-base-url` | `https://api.openai.com/v1` | Aux model endpoint (or `VIDEOLYZER_AUX_BASE_URL`) |
116
+ | `--aux-api-key` | — | Aux model key (or `VIDEOLYZER_AUX_API_KEY`) |
117
+ | `--fast` | off | **Modo Rapido**: full analysis on the aux model via keyframes (no upload). Requires `--aux-model` |
118
+ | `--verify` | off | Second opinion: aux model cross-checks the primary report. Requires `--aux-model` |
119
+ | `--out` | stdout | Output `.md` file |
120
+ | `--prompt` | built-in | Custom analysis prompt (overrides the default) |
121
+ | `--no-motion` | off | Skip the optical-flow subtle-motion pass |
122
+ | `--cut-threshold` | 0.4 | Scene-detection threshold for deterministic cut detection. Lower = more sensitive |
123
+ | `--no-cuts` | off | Skip deterministic cut detection |
124
+ | `--keyframes` | 8 | Keyframes for the openai provider / aux model |
125
+
126
+ ## Requirements
127
+
128
+ - Python 3.10+
129
+ - `ffmpeg` / `ffprobe` on PATH (system package)
130
+ - `pip install -r requirements.txt` → `opencv-python`, `numpy` (only needed for the subtle-motion pass; the tool degrades gracefully without them)
131
+
132
+ ## Report format
133
+
134
+ ```markdown
135
+ # Video Analysis
136
+ ## Summary
137
+ ## Scenes (| # | Start | End | Visual description | Audio/speech |)
138
+ ## Aligned transcript
139
+ ## Key moments
140
+ ## Tone and emotion
141
+ ## Temporal verification (motion described with action verbs, cause-effect order checked)
142
+ ```
143
+
144
+ ## How it differs from frame extraction
145
+
146
+ Classic pipelines extract N frames and ask a vision model about each still image. That loses motion: a bouncing ball becomes "ball at left" / "ball at right", and anything between sampled frames is invisible (or hallucinated).
147
+
148
+ Videolyzer instead hands the *video* to the model:
149
+
150
+ 1. **Native temporal sampling** — the model, not our code, decides what to look at along the timeline.
151
+ 2. **Temporal verification** — the prompt forces motion verbs per scene and cause-effect order checks, plus an explicit "motion undetermined" escape hatch instead of invention.
152
+ 3. **Hybrid subtle-motion pass** (local files) — classical CV finds what the model's sampling might skip, and the model is told exactly where to look.
153
+
154
+ See `docs/` for the comparative tests that motivated this design.
155
+
156
+ ## License
157
+
158
+ Apache 2.0 — see [LICENSE](LICENSE).
@@ -0,0 +1,38 @@
1
+ [build-system]
2
+ requires = ["setuptools>=61"]
3
+ build-backend = "setuptools.build_meta"
4
+
5
+ [project]
6
+ name = "videolyzer"
7
+ version = "0.1.0"
8
+ description = "give agents the ability to understand and deep analyze videos"
9
+ readme = "README.md"
10
+ authors = [{name = "Neguiolidas"}]
11
+ license = {text = "Apache-2.0"}
12
+ requires-python = ">=3.10"
13
+ keywords = ["video", "video-analysis", "ai-agents", "multimodal", "gemini"]
14
+ classifiers = [
15
+ "Development Status :: 3 - Alpha",
16
+ "Intended Audience :: Developers",
17
+ "Programming Language :: Python :: 3",
18
+ "Programming Language :: Python :: 3.10",
19
+ "Programming Language :: Python :: 3.11",
20
+ "Programming Language :: Python :: 3.12",
21
+ "Topic :: Multimedia :: Video",
22
+ "Topic :: Scientific/Engineering :: Artificial Intelligence",
23
+ ]
24
+ dependencies = [
25
+ "opencv-python>=4.8",
26
+ "numpy>=1.24",
27
+ ]
28
+
29
+ [project.urls]
30
+ Homepage = "https://github.com/Neguiolidas/videolyzer"
31
+ Repository = "https://github.com/Neguiolidas/videolyzer"
32
+ Issues = "https://github.com/Neguiolidas/videolyzer/issues"
33
+
34
+ [project.scripts]
35
+ videolyzer = "videolyzer:main"
36
+
37
+ [tool.setuptools]
38
+ py-modules = ["videolyzer"]
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+