video-to-context 0.5.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,37 @@
1
+ # Copy this file to .env and choose ONE option. The tool still runs with none,
2
+ # using local OCR for on-screen text but without visual analysis.
3
+
4
+ # Option 1: Claude (default model: claude-haiku-5-5)
5
+ # ANTHROPIC_API_KEY=
6
+
7
+ # Option 2: Gemini
8
+ # VISION_BASE_URL=https://generativelanguage.googleapis.com/v1beta/openai/
9
+ # VISION_API_KEY=
10
+ # VISION_MODEL=gemini-3.8-flash
11
+
12
+ # Option 3: OpenAI
13
+ # VISION_BASE_URL=https://api.openai.com/v1
14
+ # VISION_API_KEY=
15
+ # VISION_MODEL=gpt-5.4-mini
16
+
17
+ # Option 4: OpenRouter (use a vision model from openrouter.ai/models)
18
+ # VISION_BASE_URL=https://openrouter.ai/api/v1
19
+ # VISION_API_KEY=
20
+ # VISION_MODEL=
21
+
22
+ # Option 5: Ollama, free and on your own machine (no API key)
23
+ # VISION_BASE_URL=http://localhost:11434/v1
24
+ # VISION_MODEL=gemma4:12b
25
+ # VISION_MAX_FRAMES=12
26
+ # VISION_REASONING_EFFORT=none
27
+ # VISION_TIMEOUT_S=600
28
+
29
+ # Optional: limit how many frames are sent to the model (default 90).
30
+ # VISION_MAX_FRAMES=30
31
+
32
+ # MCP server: folders AI tools may read videos from. Local files are off until this is set.
33
+ # Separate folders with ":" on macOS and Linux, or ";" on Windows.
34
+ # VIDEO_TEXT_ALLOWED_DIRS=/Users/you/Videos
35
+
36
+ # MCP server: where results are stored (default: store/ in this project).
37
+ # VIDEO_TEXT_STORE=/Users/you/video-text-store
@@ -0,0 +1,55 @@
1
+ # Python environments
2
+ .venv/
3
+ venv/
4
+ env/
5
+ .conda/
6
+
7
+ # Python build and cache files
8
+ __pycache__/
9
+ *.py[cod]
10
+ *.egg-info/
11
+ build/
12
+ dist/
13
+ .pytest_cache/
14
+ .mypy_cache/
15
+ .ruff_cache/
16
+ .coverage
17
+ htmlcov/
18
+ .ipynb_checkpoints/
19
+
20
+ # Secrets and local settings
21
+ .env
22
+ .env.*
23
+ !.env.example
24
+ .claude/settings.local.json
25
+
26
+ # Pipeline output and input media
27
+ store/
28
+ data/
29
+ tests/samples/*
30
+ !tests/samples/.gitkeep
31
+ *.mp4
32
+ *.mov
33
+ *.mkv
34
+ *.webm
35
+ *.m4a
36
+ *.wav
37
+ *.mp3
38
+
39
+ # Downloaded model weights
40
+ *.pt
41
+ *.pth
42
+ *.onnx
43
+ *.safetensors
44
+ *.gguf
45
+
46
+ # Logs and temporary files
47
+ *.log
48
+ *.tmp
49
+
50
+ # Editors and operating systems
51
+ .vscode/
52
+ .idea/
53
+ *.swp
54
+ .DS_Store
55
+ Thumbs.db
@@ -0,0 +1,202 @@
1
+
2
+ Apache License
3
+ Version 2.0, January 2004
4
+ http://www.apache.org/licenses/
5
+
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
+
8
+ 1. Definitions.
9
+
10
+ "License" shall mean the terms and conditions for use, reproduction,
11
+ and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by
14
+ the copyright owner that is granting the License.
15
+
16
+ "Legal Entity" shall mean the union of the acting entity and all
17
+ other entities that control, are controlled by, or are under common
18
+ control with that entity. For the purposes of this definition,
19
+ "control" means (i) the power, direct or indirect, to cause the
20
+ direction or management of such entity, whether by contract or
21
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
+ outstanding shares, or (iii) beneficial ownership of such entity.
23
+
24
+ "You" (or "Your") shall mean an individual or Legal Entity
25
+ exercising permissions granted by this License.
26
+
27
+ "Source" form shall mean the preferred form for making modifications,
28
+ including but not limited to software source code, documentation
29
+ source, and configuration files.
30
+
31
+ "Object" form shall mean any form resulting from mechanical
32
+ transformation or translation of a Source form, including but
33
+ not limited to compiled object code, generated documentation,
34
+ and conversions to other media types.
35
+
36
+ "Work" shall mean the work of authorship, whether in Source or
37
+ Object form, made available under the License, as indicated by a
38
+ copyright notice that is included in or attached to the work
39
+ (an example is provided in the Appendix below).
40
+
41
+ "Derivative Works" shall mean any work, whether in Source or Object
42
+ form, that is based on (or derived from) the Work and for which the
43
+ editorial revisions, annotations, elaborations, or other modifications
44
+ represent, as a whole, an original work of authorship. For the purposes
45
+ of this License, Derivative Works shall not include works that remain
46
+ separable from, or merely link (or bind by name) to the interfaces of,
47
+ the Work and Derivative Works thereof.
48
+
49
+ "Contribution" shall mean any work of authorship, including
50
+ the original version of the Work and any modifications or additions
51
+ to that Work or Derivative Works thereof, that is intentionally
52
+ submitted to Licensor for inclusion in the Work by the copyright owner
53
+ or by an individual or Legal Entity authorized to submit on behalf of
54
+ the copyright owner. For the purposes of this definition, "submitted"
55
+ means any form of electronic, verbal, or written communication sent
56
+ to the Licensor or its representatives, including but not limited to
57
+ communication on electronic mailing lists, source code control systems,
58
+ and issue tracking systems that are managed by, or on behalf of, the
59
+ Licensor for the purpose of discussing and improving the Work, but
60
+ excluding communication that is conspicuously marked or otherwise
61
+ designated in writing by the copyright owner as "Not a Contribution."
62
+
63
+ "Contributor" shall mean Licensor and any individual or Legal Entity
64
+ on behalf of whom a Contribution has been received by Licensor and
65
+ subsequently incorporated within the Work.
66
+
67
+ 2. Grant of Copyright License. Subject to the terms and conditions of
68
+ this License, each Contributor hereby grants to You a perpetual,
69
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
+ copyright license to reproduce, prepare Derivative Works of,
71
+ publicly display, publicly perform, sublicense, and distribute the
72
+ Work and such Derivative Works in Source or Object form.
73
+
74
+ 3. Grant of Patent License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable
80
+ by such Contributor that are necessarily infringed by their
81
+ Contribution(s) alone or by combination of their Contribution(s)
82
+ with the Work to which such Contribution(s) was submitted. If You
83
+ institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+ or a Contribution incorporated within the Work constitutes direct
86
+ or contributory patent infringement, then any patent licenses
87
+ granted to You under this License for that Work shall terminate
88
+ as of the date such litigation is filed.
89
+
90
+ 4. Redistribution. You may reproduce and distribute copies of the
91
+ Work or Derivative Works thereof in any medium, with or without
92
+ modifications, and in Source or Object form, provided that You
93
+ meet the following conditions:
94
+
95
+ (a) You must give any other recipients of the Work or
96
+ Derivative Works a copy of this License; and
97
+
98
+ (b) You must cause any modified files to carry prominent notices
99
+ stating that You changed the files; and
100
+
101
+ (c) You must retain, in the Source form of any Derivative Works
102
+ that You distribute, all copyright, patent, trademark, and
103
+ attribution notices from the Source form of the Work,
104
+ excluding those notices that do not pertain to any part of
105
+ the Derivative Works; and
106
+
107
+ (d) If the Work includes a "NOTICE" text file as part of its
108
+ distribution, then any Derivative Works that You distribute must
109
+ include a readable copy of the attribution notices contained
110
+ within such NOTICE file, excluding those notices that do not
111
+ pertain to any part of the Derivative Works, in at least one
112
+ of the following places: within a NOTICE text file distributed
113
+ as part of the Derivative Works; within the Source form or
114
+ documentation, if provided along with the Derivative Works; or,
115
+ within a display generated by the Derivative Works, if and
116
+ wherever such third-party notices normally appear. The contents
117
+ of the NOTICE file are for informational purposes only and
118
+ do not modify the License. You may add Your own attribution
119
+ notices within Derivative Works that You distribute, alongside
120
+ or as an addendum to the NOTICE text from the Work, provided
121
+ that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and
125
+ may provide additional or different license terms and conditions
126
+ for use, reproduction, or distribution of Your modifications, or
127
+ for any such Derivative Works as a whole, provided Your use,
128
+ reproduction, and distribution of the Work otherwise complies with
129
+ the conditions stated in this License.
130
+
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
132
+ any Contribution intentionally submitted for inclusion in the Work
133
+ by You to the Licensor shall be under the terms and conditions of
134
+ this License, without any additional terms or conditions.
135
+ Notwithstanding the above, nothing herein shall supersede or modify
136
+ the terms of any separate license agreement you may have executed
137
+ with Licensor regarding such Contributions.
138
+
139
+ 6. Trademarks. This License does not grant permission to use the trade
140
+ names, trademarks, service marks, or product names of the Licensor,
141
+ except as required for reasonable and customary use in describing the
142
+ origin of the Work and reproducing the content of the NOTICE file.
143
+
144
+ 7. Disclaimer of Warranty. Unless required by applicable law or
145
+ agreed to in writing, Licensor provides the Work (and each
146
+ Contributor provides its Contributions) on an "AS IS" BASIS,
147
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+ implied, including, without limitation, any warranties or conditions
149
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+ PARTICULAR PURPOSE. You are solely responsible for determining the
151
+ appropriateness of using or redistributing the Work and assume any
152
+ risks associated with Your exercise of permissions under this License.
153
+
154
+ 8. Limitation of Liability. In no event and under no legal theory,
155
+ whether in tort (including negligence), contract, or otherwise,
156
+ unless required by applicable law (such as deliberate and grossly
157
+ negligent acts) or agreed to in writing, shall any Contributor be
158
+ liable to You for damages, including any direct, indirect, special,
159
+ incidental, or consequential damages of any character arising as a
160
+ result of this License or out of the use or inability to use the
161
+ Work (including but not limited to damages for loss of goodwill,
162
+ work stoppage, computer failure or malfunction, or any and all
163
+ other commercial damages or losses), even if such Contributor
164
+ has been advised of the possibility of such damages.
165
+
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on behalf
172
+ of any other Contributor, and only if You agree to indemnify,
173
+ defend, and hold each Contributor harmless for any liability
174
+ incurred by, or claims asserted against, such Contributor by reason
175
+ of your accepting any such warranty or additional liability.
176
+
177
+ END OF TERMS AND CONDITIONS
178
+
179
+ APPENDIX: How to apply the Apache License to your work.
180
+
181
+ To apply the Apache License to your work, attach the following
182
+ boilerplate notice, with the fields enclosed by brackets "[]"
183
+ replaced with your own identifying information. (Don't include
184
+ the brackets!) The text should be enclosed in the appropriate
185
+ comment syntax for the file format. We also recommend that a
186
+ file or class name and description of purpose be included on the
187
+ same "printed page" as the copyright notice for easier
188
+ identification within third-party archives.
189
+
190
+ Copyright [yyyy] [name of copyright owner]
191
+
192
+ Licensed under the Apache License, Version 2.0 (the "License");
193
+ you may not use this file except in compliance with the License.
194
+ You may obtain a copy of the License at
195
+
196
+ http://www.apache.org/licenses/LICENSE-2.0
197
+
198
+ Unless required by applicable law or agreed to in writing, software
199
+ distributed under the License is distributed on an "AS IS" BASIS,
200
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201
+ See the License for the specific language governing permissions and
202
+ limitations under the License.
@@ -0,0 +1,2 @@
1
+ youtube-shorts-to-text-context
2
+ Copyright 2026 Taewan Ham
@@ -0,0 +1,362 @@
1
+ Metadata-Version: 2.5
2
+ Name: video-to-context
3
+ Version: 0.5.0
4
+ Summary: Turn short videos into structured, timestamped text for LLMs: speech, on-screen text, and visual context.
5
+ Project-URL: Homepage, https://github.com/wani-ham/youtube-shorts-to-text-context
6
+ Project-URL: Repository, https://github.com/wani-ham/youtube-shorts-to-text-context
7
+ Project-URL: Issues, https://github.com/wani-ham/youtube-shorts-to-text-context/issues
8
+ Author: Taewan Ham
9
+ License-Expression: Apache-2.0
10
+ License-File: LICENSE
11
+ License-File: NOTICE
12
+ Keywords: llm,mcp,multimodal,ocr,rag,speech-to-text,video-to-text,whisper,youtube-shorts
13
+ Classifier: Development Status :: 4 - Beta
14
+ Classifier: Environment :: Console
15
+ Classifier: Intended Audience :: Developers
16
+ Classifier: Operating System :: MacOS
17
+ Classifier: Operating System :: POSIX :: Linux
18
+ Classifier: Programming Language :: Python :: 3
19
+ Classifier: Programming Language :: Python :: 3.12
20
+ Classifier: Topic :: Multimedia :: Video
21
+ Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
22
+ Requires-Python: >=3.12
23
+ Requires-Dist: anthropic<3,>=2.12
24
+ Requires-Dist: easyocr<2,>=1.7.2
25
+ Requires-Dist: faster-whisper<2,>=1.2.1
26
+ Requires-Dist: imagehash<5,>=4.3.2
27
+ Requires-Dist: mcp<3,>=2.3
28
+ Requires-Dist: numpy<3,>=2.5
29
+ Requires-Dist: openai<4,>=3.57
30
+ Requires-Dist: pillow<14,>=13
31
+ Requires-Dist: pydantic<3,>=2.14
32
+ Requires-Dist: python-dotenv<2,>=1.2
33
+ Requires-Dist: rapidfuzz<4,>=3.14
34
+ Requires-Dist: scenedetect<0.8,>=0.7.3
35
+ Requires-Dist: torch<3,>=2.15
36
+ Requires-Dist: yt-dlp>=2026.10.26
37
+ Provides-Extra: dev
38
+ Requires-Dist: jiwer<5,>=4; extra == 'dev'
39
+ Requires-Dist: pytest<10,>=9; extra == 'dev'
40
+ Description-Content-Type: text/markdown
41
+
42
+ # Generate Text Contexts from Youtube Shorts
43
+
44
+ Turn a short-form Youtube video into structured, timestamped context in a text format. It includes both audio and visual context.
45
+
46
+ Most language models can't watch a video. This tool gives them a faithful text version of one: what was **said**, what was **written on screen**, and what was **shown**, with every item labelled by source and time.
47
+
48
+ ```text
49
+ [ON-SCREEN:LOGO 00:00–00:16] EXAMPLE CHANNEL
50
+ [AUDIO 00:07–00:11] Today we're testing three ways to brew coffee at home.
51
+ [ON-SCREEN 00:08–00:10] 3 WAYS TO BREW COFFEE
52
+ [VISUAL 00:07–00:16] A person in an apron pours hot water into a glass coffee maker in a bright kitchen.
53
+ ```
54
+
55
+ Use the output as the input to summarisation, search, fact-checking, content moderation, RAG, or your own agents.
56
+
57
+ ## Contents
58
+
59
+ - [How it works](#how-it-works)
60
+ - [Quick start](#quick-start)
61
+ - [Choosing a vision model](#choosing-a-vision-model)
62
+ - [Usage](#usage)
63
+ - [Use it from AI tools (MCP)](#use-it-from-ai-tools-mcp)
64
+ - [Output](#output)
65
+ - [Troubleshooting](#troubleshooting)
66
+ - [Privacy and responsible use](#privacy-and-responsible-use)
67
+ - [Development](#development)
68
+ - [License](#license)
69
+
70
+ ## How it works
71
+
72
+ ```text
73
+ YouTube link or video file
74
+ │
75
+ download and check
76
+ │
77
+ ├── audio ──► speech-to-text (Whisper, runs locally)
78
+ │
79
+ └── frames ─► vision model: on-screen text, scenes, settings, editing
80
+ │
81
+ record.json + record.md
82
+ ```
83
+
84
+ ## Quick start
85
+
86
+ ### 1. Install the requirements
87
+
88
+ You need [uv](https://docs.astral.sh/uv/), **ffmpeg**, and about 5 GB of free disk space. uv installs the right Python version for you.
89
+
90
+ | System | Install command |
91
+ | --- | --- |
92
+ | macOS | `brew install uv ffmpeg` |
93
+ | Ubuntu or Debian | `sudo apt install ffmpeg && curl -LsSf https://astral.sh/uv/install.sh \| sh` |
94
+
95
+ ### 2. Install video-to-context
96
+
97
+ ```bash
98
+ uv tool install --python 3.12 video-to-context
99
+ ```
100
+
101
+ If the command isn't found afterwards, run `uv tool update-shell` and open a new terminal. You can also use `pip install video-to-context` inside a Python 3.12 environment.
102
+
103
+ ### 3. Choose a vision model (optional)
104
+
105
+ Download the settings template:
106
+
107
+ ```bash
108
+ mkdir -p ~/.video-to-context
109
+ curl -o ~/.video-to-context/.env https://raw.githubusercontent.com/wani-ham/youtube-shorts-to-text-context/main/.env.example
110
+ ```
111
+
112
+ Open `~/.video-to-context/.env` and uncomment one option from the next section. Without one, the tool still produces the transcript and reads on-screen text locally, but it won't include visual analysis.
113
+
114
+ ### 4. Run it
115
+
116
+ ```bash
117
+ video-to-context "https://www.youtube.com/shorts/VIDEO_ID"
118
+ ```
119
+
120
+ The first run is slower because it downloads the speech and OCR models. When it finishes, it prints the path to your result in a `store/` folder inside your current directory.
121
+
122
+ ## Choosing a vision model
123
+
124
+ You don't need Claude. Any service with an OpenAI-compatible API and image support will work.
125
+
126
+ | Option | Cost | Your frames go to | Best for |
127
+ | --- | --- | --- | --- |
128
+ | **Claude Haiku 5.5** | About 1 cent per video (estimate) | Anthropic | Tested default |
129
+ | **Gemini** | Free tier available | Google | Trying it at no cost |
130
+ | **OpenAI** | Paid | OpenAI | Existing OpenAI users |
131
+ | **OpenRouter** | Free and paid models | The selected provider | Comparing models |
132
+ | **Ollama** | Free | **Nowhere, runs locally** | Private text extraction, no account |
133
+ | **None** | Free | Nowhere | Transcript and text only |
134
+
135
+ > **Status:** Claude has been tested on real videos. Ollama with Gemma 4 12B has been tested on one real video: it read on-screen text well, but its scene descriptions were unreliable. Gemini, OpenAI, and OpenRouter use the same connection as Ollama but haven't been tested with their real services.
136
+
137
+ ### Claude
138
+
139
+ Create a key in the [Claude Console](https://platform.claude.com/). API usage is billed separately from Claude Pro and Max plans.
140
+
141
+ ```bash
142
+ ANTHROPIC_API_KEY=your-key
143
+ ```
144
+
145
+ ### Gemini
146
+
147
+ Create a key in [Google AI Studio](https://aistudio.google.com/). Free-tier content may be used to improve Google's products, so avoid private videos on that tier.
148
+
149
+ ```bash
150
+ VISION_BASE_URL=https://generativelanguage.googleapis.com/v1beta/openai/
151
+ VISION_API_KEY=your-key
152
+ VISION_MODEL=gemini-3.8-flash
153
+ ```
154
+
155
+ ### OpenAI
156
+
157
+ ```bash
158
+ VISION_BASE_URL=https://api.openai.com/v1
159
+ VISION_API_KEY=your-key
160
+ VISION_MODEL=gpt-5.4-mini
161
+ ```
162
+
163
+ ### OpenRouter
164
+
165
+ Choose a model that accepts images from [openrouter.ai/models](https://openrouter.ai/models).
166
+
167
+ ```bash
168
+ VISION_BASE_URL=https://openrouter.ai/api/v1
169
+ VISION_API_KEY=your-key
170
+ VISION_MODEL=provider/model-name
171
+ ```
172
+
173
+ ### Ollama (free and local)
174
+
175
+ Install [Ollama](https://ollama.com/), then download a vision model. Allow about 8 GB of disk space and at least 16 GB of memory, and close other heavy apps.
176
+
177
+ ```bash
178
+ ollama pull gemma4:12b
179
+ ```
180
+
181
+ Start Ollama with a larger context. Its default is too small for this prompt and the images:
182
+
183
+ ```bash
184
+ OLLAMA_CONTEXT_LENGTH=16384 ollama serve
185
+ ```
186
+
187
+ If Ollama is already running in the background, quit it first. Then add this to `.env`:
188
+
189
+ ```bash
190
+ VISION_BASE_URL=http://localhost:11434/v1
191
+ VISION_MODEL=gemma4:12b
192
+ VISION_MAX_FRAMES=12
193
+ VISION_REASONING_EFFORT=none
194
+ VISION_TIMEOUT_S=600
195
+ ```
196
+
197
+ - `VISION_MAX_FRAMES` limits how many images are sent per video. Fewer frames use less memory but can miss short captions.
198
+ - `VISION_REASONING_EFFORT=none` turns off model thinking. On a 16 GB Apple Silicon Mac, one request took about 78 seconds this way and about 250 seconds with thinking, which gave somewhat better scene descriptions.
199
+ - `VISION_TIMEOUT_S` gives slower local models enough time to answer.
200
+
201
+ Model names change often. If one is rejected, check your provider's current model list.
202
+
203
+ ## Usage
204
+
205
+ ```bash
206
+ # A YouTube video or Short
207
+ video-to-context "https://www.youtube.com/shorts/VIDEO_ID"
208
+
209
+ # A video file on your computer
210
+ video-to-context --file path/to/video.mp4
211
+
212
+ # A file with details about where it came from
213
+ video-to-context --file ad.mp4 --sponsor "Brand" --date 2026-11-02 --caption "Post text"
214
+
215
+ # Process a video again, ignoring the saved result
216
+ video-to-context "https://youtu.be/VIDEO_ID" --force
217
+ ```
218
+
219
+ Videos can be up to 5 minutes and 200 MB. To change these limits, edit [config.py](https://github.com/wani-ham/youtube-shorts-to-text-context/blob/main/video_to_context/config.py) in a source install.
220
+
221
+ The command exits with `0` for a complete record, `1` for a partial record, and `2` for a rejected input.
222
+
223
+ ### Use it from Python
224
+
225
+ ```python
226
+ from dotenv import load_dotenv
227
+ from video_to_context.run import process
228
+
229
+ load_dotenv()
230
+ record = process(url="https://www.youtube.com/shorts/VIDEO_ID", out="store")
231
+
232
+ print(record.llm_document)
233
+ print(record.visual_context.summary if record.visual_context else "No visual analysis")
234
+ ```
235
+
236
+ ## Use it from AI tools (MCP)
237
+
238
+ The included [MCP](https://modelcontextprotocol.io/) server lets AI tools analyse a video when you ask, for example: *"Summarise this Short and tell me what its on-screen text claims."*
239
+
240
+ Finish the [Quick start](#quick-start) first. The server reads your settings from `~/.video-to-context/.env` and stores results in `~/.video-to-context/store`.
241
+
242
+ ### Claude Code
243
+
244
+ ```bash
245
+ claude mcp add --scope user video-to-text -- "$(command -v video-to-context-mcp)"
246
+ ```
247
+
248
+ ### Cursor, Claude Desktop, and other clients
249
+
250
+ Find the full command path with `command -v video-to-context-mcp`, then add it to the client's MCP configuration. For Cursor, that's `~/.cursor/mcp.json`.
251
+
252
+ ```json
253
+ {
254
+ "mcpServers": {
255
+ "video-to-text": {
256
+ "command": "/absolute/path/to/video-to-context-mcp"
257
+ }
258
+ }
259
+ }
260
+ ```
261
+
262
+ ### Tools
263
+
264
+ | Tool | What it does |
265
+ | --- | --- |
266
+ | `start_video_analysis` | Starts a background job for a YouTube link or allowed local file |
267
+ | `get_analysis_status` | Reports whether the job is queued, running, or finished |
268
+ | `get_video_text` | Returns the finished result as Markdown or JSON |
269
+ | `list_analyzed_videos` | Lists videos that already have results |
270
+ | `check_setup` | Checks ffmpeg, the vision model, and file access |
271
+
272
+ Videos run one at a time in the background, because processing takes longer than most tools wait for a single call.
273
+
274
+ ### Security
275
+
276
+ - **Local files are off by default.** To allow them, list specific folders in `VIDEO_TEXT_ALLOWED_DIRS` in `~/.video-to-context/.env`.
277
+ - **URLs are limited to YouTube.**
278
+ - **The server runs locally over stdio** and opens no network port.
279
+ - **Video text is untrusted.** A caption could try to manipulate your AI tool, so be careful when that tool can also run commands or edit files.
280
+
281
+ ## Output
282
+
283
+ Each video gets its own folder, named after a hash of the file, so the same file is never processed twice:
284
+
285
+ ```text
286
+ store/<sha256>/
287
+ ├── record.md Document for LLMs and people
288
+ ├── record.json Full structured data for code
289
+ ├── video.mp4 The video
290
+ ├── frames/ Keyframes referenced by the record
291
+ └── info.json YouTube metadata (for YouTube links)
292
+ ```
293
+
294
+ ### `record.md`
295
+
296
+ Pass this file directly to a language model. It contains:
297
+
298
+ - **YAML metadata:** source, duration, language, footage type, status, and models used.
299
+ - **Quality notes:** anything downstream services should be careful about.
300
+ - **Visual analysis:** a summary, the distinct settings, editing techniques, and shots.
301
+ - **Timeline:** everything in time order, labelled by source.
302
+
303
+ | Label | Meaning | Safe to quote as the video's content? |
304
+ | --- | --- | --- |
305
+ | `AUDIO` | Transcribed speech | Yes, but it may have recognition errors |
306
+ | `ON-SCREEN` | Captions and text in the frame | Yes |
307
+ | `ON-SCREEN:HEADLINE`, `:WATERMARK`, `:LOGO`, `:OTHER` | Text or marks that stay on screen | Yes |
308
+ | `VISUAL` | A model's description of a scene | **No, it is an interpretation** |
309
+
310
+ Video text is untrusted input. It's kept inside code blocks so that your prompt can treat it as data, but a caption could still contain text written to manipulate a model. Tell your downstream model not to follow instructions found in it.
311
+
312
+ ### `record.json`
313
+
314
+ The same information as structured fields, including `transcript`, `on_screen_text`, `visual_context`, `visual_descriptions`, `keyframes`, `flags`, and `errors`. Suspected invented speech is moved to `transcript.removed_segments` so you can review it.
315
+
316
+ If one stage fails, the others still finish and the record is marked `partial`.
317
+
318
+ ## Troubleshooting
319
+
320
+ | What you see | What to do |
321
+ | --- | --- |
322
+ | `fetch_failed` | The video may be private, removed, or age-restricted, or YouTube may be blocking the download. Download limits are stricter on cloud servers. Use `--file` instead. |
323
+ | `vision_not_configured` in `flags` | No vision model is set. Check that `~/.video-to-context/.env` exists and an option is uncommented. |
324
+ | `vision_auth_failed` | The API key is wrong or expired. |
325
+ | `vision_invalid_output` | The model didn't return usable JSON. Try a more capable model. |
326
+ | Out of memory with Ollama | Lower `VISION_MAX_FRAMES` or use a smaller model. |
327
+ | MCP tools don't appear | Use the full path from `command -v video-to-context-mcp`, then restart the client. |
328
+ | `vision_timeout` | Raise `VISION_TIMEOUT_S`, or set `VISION_REASONING_EFFORT=none`. |
329
+ | `objc: Class AVF... is implemented in both` | A harmless macOS warning from two video libraries. |
330
+ | `ffmpeg` not found | Install ffmpeg (step 1), then open a new terminal. |
331
+ | It's slow | Speech-to-text runs on CPU unless you have an NVIDIA GPU. Expect a few minutes for a 2-minute video. |
332
+
333
+ ## Privacy and responsible use
334
+
335
+ - Unless you use Ollama or no vision model, video frames are sent to the provider you choose. Check its data retention and training terms.
336
+ - Videos contain people's faces and voices. The vision prompt tells the model not to identify people, and you shouldn't add face or voice identification without legal review.
337
+ - YouTube's terms restrict downloading. Make sure you have the right to process a video, especially for commercial or public use.
338
+ - `.env`, `store/`, and media files are ignored by git. Never commit API keys.
339
+
340
+ ## Development
341
+
342
+ ```bash
343
+ git clone https://github.com/wani-ham/youtube-shorts-to-text-context.git
344
+ cd youtube-shorts-to-text-context
345
+ python3.12 -m venv .venv
346
+ .venv/bin/pip install -e ".[dev]"
347
+ cp .env.example .env
348
+ .venv/bin/python -m pytest
349
+ .venv/bin/python -m video_to_context.evaluate
350
+ ```
351
+
352
+ In a source checkout, settings come from the project's `.env`, and the MCP server stores results in the project's `store/` folder.
353
+
354
+ To score accuracy on your own test set, put each video in `tests/samples/<name>.mp4` and its hand-written labels in `tests/expected/<name>.json`:
355
+
356
+ ```json
357
+ {"transcript": "…", "on_screen": ["…"], "no_speech": false, "rejected": null}
358
+ ```
359
+
360
+ ## License
361
+
362
+ Licensed under the [Apache License 2.0](https://github.com/wani-ham/youtube-shorts-to-text-context/blob/main/LICENSE). See [NOTICE](https://github.com/wani-ham/youtube-shorts-to-text-context/blob/main/NOTICE) for copyright details.