videopython 0.61.2__tar.gz → 0.62.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.
- {videopython-0.61.2 → videopython-0.62.0}/PKG-INFO +15 -30
- {videopython-0.61.2 → videopython-0.62.0}/README.md +14 -29
- {videopython-0.61.2 → videopython-0.62.0}/pyproject.toml +1 -1
- {videopython-0.61.2 → videopython-0.62.0}/src/videopython/_ffmpeg.py +24 -1
- {videopython-0.61.2 → videopython-0.62.0}/src/videopython/ai/_ollama.py +13 -0
- {videopython-0.61.2 → videopython-0.62.0}/src/videopython/ai/_predictor.py +4 -0
- {videopython-0.61.2 → videopython-0.62.0}/src/videopython/ai/_revisions.py +10 -0
- {videopython-0.61.2 → videopython-0.62.0}/src/videopython/ai/auto_edit/__init__.py +2 -1
- videopython-0.62.0/src/videopython/ai/auto_edit/_speech.py +54 -0
- videopython-0.62.0/src/videopython/ai/auto_edit/catalog.py +146 -0
- {videopython-0.61.2 → videopython-0.62.0}/src/videopython/ai/auto_edit/models.py +18 -1
- {videopython-0.61.2 → videopython-0.62.0}/src/videopython/ai/dubbing/config.py +1 -1
- {videopython-0.61.2 → videopython-0.62.0}/src/videopython/ai/keyframe.py +0 -9
- {videopython-0.61.2 → videopython-0.62.0}/src/videopython/ai/understanding/audio.py +11 -4
- {videopython-0.61.2 → videopython-0.62.0}/src/videopython/ai/understanding/classification.py +5 -0
- {videopython-0.61.2 → videopython-0.62.0}/src/videopython/ai/understanding/faces.py +8 -0
- {videopython-0.61.2 → videopython-0.62.0}/src/videopython/ai/understanding/image.py +3 -0
- {videopython-0.61.2 → videopython-0.62.0}/src/videopython/ai/understanding/temporal.py +6 -0
- {videopython-0.61.2 → videopython-0.62.0}/src/videopython/ai/video_analysis/__init__.py +2 -0
- videopython-0.62.0/src/videopython/ai/video_analysis/_identity.py +10 -0
- {videopython-0.61.2 → videopython-0.62.0}/src/videopython/ai/video_analysis/analyzer.py +27 -6
- {videopython-0.61.2 → videopython-0.62.0}/src/videopython/ai/video_analysis/detectors.py +16 -3
- {videopython-0.61.2 → videopython-0.62.0}/src/videopython/ai/video_analysis/models.py +24 -0
- {videopython-0.61.2 → videopython-0.62.0}/src/videopython/base/video.py +33 -30
- {videopython-0.61.2 → videopython-0.62.0}/src/videopython/editing/__init__.py +2 -0
- videopython-0.62.0/src/videopython/editing/progress.py +55 -0
- {videopython-0.61.2 → videopython-0.62.0}/src/videopython/editing/streaming.py +14 -4
- {videopython-0.61.2 → videopython-0.62.0}/src/videopython/editing/video_edit.py +55 -11
- {videopython-0.61.2 → videopython-0.62.0}/src/videopython/mcp/_models.py +13 -1
- {videopython-0.61.2 → videopython-0.62.0}/src/videopython/mcp/server.py +99 -17
- videopython-0.61.2/src/videopython/ai/auto_edit/catalog.py +0 -90
- {videopython-0.61.2 → videopython-0.62.0}/.gitignore +0 -0
- {videopython-0.61.2 → videopython-0.62.0}/LICENSE +0 -0
- {videopython-0.61.2 → videopython-0.62.0}/src/videopython/__init__.py +0 -0
- {videopython-0.61.2 → videopython-0.62.0}/src/videopython/_exceptions.py +0 -0
- {videopython-0.61.2 → videopython-0.62.0}/src/videopython/ai/__init__.py +0 -0
- {videopython-0.61.2 → videopython-0.62.0}/src/videopython/ai/_device.py +0 -0
- {videopython-0.61.2 → videopython-0.62.0}/src/videopython/ai/_optional.py +0 -0
- {videopython-0.61.2 → videopython-0.62.0}/src/videopython/ai/_text_chunks.py +0 -0
- {videopython-0.61.2 → videopython-0.62.0}/src/videopython/ai/auto_edit/backend.py +0 -0
- {videopython-0.61.2 → videopython-0.62.0}/src/videopython/ai/auto_edit/editor.py +0 -0
- {videopython-0.61.2 → videopython-0.62.0}/src/videopython/ai/auto_edit/local.py +0 -0
- {videopython-0.61.2 → videopython-0.62.0}/src/videopython/ai/auto_edit/resolve.py +0 -0
- {videopython-0.61.2 → videopython-0.62.0}/src/videopython/ai/dubbing/__init__.py +0 -0
- {videopython-0.61.2 → videopython-0.62.0}/src/videopython/ai/dubbing/_phrases.py +0 -0
- {videopython-0.61.2 → videopython-0.62.0}/src/videopython/ai/dubbing/_synthesis.py +0 -0
- {videopython-0.61.2 → videopython-0.62.0}/src/videopython/ai/dubbing/_tts_backend.py +0 -0
- {videopython-0.61.2 → videopython-0.62.0}/src/videopython/ai/dubbing/audio_ops.py +0 -0
- {videopython-0.61.2 → videopython-0.62.0}/src/videopython/ai/dubbing/dubber.py +0 -0
- {videopython-0.61.2 → videopython-0.62.0}/src/videopython/ai/dubbing/models.py +0 -0
- {videopython-0.61.2 → videopython-0.62.0}/src/videopython/ai/dubbing/pipeline.py +0 -0
- {videopython-0.61.2 → videopython-0.62.0}/src/videopython/ai/dubbing/quality.py +0 -0
- {videopython-0.61.2 → videopython-0.62.0}/src/videopython/ai/dubbing/remux.py +0 -0
- {videopython-0.61.2 → videopython-0.62.0}/src/videopython/ai/dubbing/separation.py +0 -0
- {videopython-0.61.2 → videopython-0.62.0}/src/videopython/ai/dubbing/timing.py +0 -0
- {videopython-0.61.2 → videopython-0.62.0}/src/videopython/ai/dubbing/translation.py +0 -0
- {videopython-0.61.2 → videopython-0.62.0}/src/videopython/ai/dubbing/voice_sample.py +0 -0
- {videopython-0.61.2 → videopython-0.62.0}/src/videopython/ai/effects.py +0 -0
- {videopython-0.61.2 → videopython-0.62.0}/src/videopython/ai/errors.py +0 -0
- {videopython-0.61.2 → videopython-0.62.0}/src/videopython/ai/generation/__init__.py +0 -0
- {videopython-0.61.2 → videopython-0.62.0}/src/videopython/ai/generation/_speech_graphs.py +0 -0
- {videopython-0.61.2 → videopython-0.62.0}/src/videopython/ai/generation/_speech_tokens.py +0 -0
- {videopython-0.61.2 → videopython-0.62.0}/src/videopython/ai/generation/audio.py +0 -0
- {videopython-0.61.2 → videopython-0.62.0}/src/videopython/ai/generation/image.py +0 -0
- {videopython-0.61.2 → videopython-0.62.0}/src/videopython/ai/generation/video.py +0 -0
- {videopython-0.61.2 → videopython-0.62.0}/src/videopython/ai/ops.py +0 -0
- {videopython-0.61.2 → videopython-0.62.0}/src/videopython/ai/transforms.py +0 -0
- {videopython-0.61.2 → videopython-0.62.0}/src/videopython/ai/understanding/__init__.py +0 -0
- {videopython-0.61.2 → videopython-0.62.0}/src/videopython/ai/understanding/_detector.py +0 -0
- {videopython-0.61.2 → videopython-0.62.0}/src/videopython/ai/understanding/_pyannote_patches.py +0 -0
- {videopython-0.61.2 → videopython-0.62.0}/src/videopython/ai/understanding/objects.py +0 -0
- {videopython-0.61.2 → videopython-0.62.0}/src/videopython/ai/video_analysis/sampling.py +0 -0
- {videopython-0.61.2 → videopython-0.62.0}/src/videopython/ai/video_analysis/source_metadata.py +0 -0
- {videopython-0.61.2 → videopython-0.62.0}/src/videopython/audio/__init__.py +0 -0
- {videopython-0.61.2 → videopython-0.62.0}/src/videopython/audio/analysis.py +0 -0
- {videopython-0.61.2 → videopython-0.62.0}/src/videopython/audio/audio.py +0 -0
- {videopython-0.61.2 → videopython-0.62.0}/src/videopython/base/__init__.py +0 -0
- {videopython-0.61.2 → videopython-0.62.0}/src/videopython/base/_dimensions.py +0 -0
- {videopython-0.61.2 → videopython-0.62.0}/src/videopython/base/_video_io.py +0 -0
- {videopython-0.61.2 → videopython-0.62.0}/src/videopython/base/description.py +0 -0
- {videopython-0.61.2 → videopython-0.62.0}/src/videopython/base/draw_detections.py +0 -0
- {videopython-0.61.2 → videopython-0.62.0}/src/videopython/base/fonts/Anton-OFL.txt +0 -0
- {videopython-0.61.2 → videopython-0.62.0}/src/videopython/base/fonts/Anton-Regular.ttf +0 -0
- {videopython-0.61.2 → videopython-0.62.0}/src/videopython/base/fonts/BebasNeue-OFL.txt +0 -0
- {videopython-0.61.2 → videopython-0.62.0}/src/videopython/base/fonts/BebasNeue-Regular.ttf +0 -0
- {videopython-0.61.2 → videopython-0.62.0}/src/videopython/base/fonts/DejaVuSans.ttf +0 -0
- {videopython-0.61.2 → videopython-0.62.0}/src/videopython/base/fonts/LICENSE_DEJAVU +0 -0
- {videopython-0.61.2 → videopython-0.62.0}/src/videopython/base/fonts/Lato-Bold.ttf +0 -0
- {videopython-0.61.2 → videopython-0.62.0}/src/videopython/base/fonts/Lato-OFL.txt +0 -0
- {videopython-0.61.2 → videopython-0.62.0}/src/videopython/base/fonts/Poppins-Bold.ttf +0 -0
- {videopython-0.61.2 → videopython-0.62.0}/src/videopython/base/fonts/Poppins-OFL.txt +0 -0
- {videopython-0.61.2 → videopython-0.62.0}/src/videopython/base/fonts/__init__.py +0 -0
- {videopython-0.61.2 → videopython-0.62.0}/src/videopython/base/transcription.py +0 -0
- {videopython-0.61.2 → videopython-0.62.0}/src/videopython/editing/_ass.py +0 -0
- {videopython-0.61.2 → videopython-0.62.0}/src/videopython/editing/_easing.py +0 -0
- {videopython-0.61.2 → videopython-0.62.0}/src/videopython/editing/_schema.py +0 -0
- {videopython-0.61.2 → videopython-0.62.0}/src/videopython/editing/audio_ops.py +0 -0
- {videopython-0.61.2 → videopython-0.62.0}/src/videopython/editing/effects.py +0 -0
- {videopython-0.61.2 → videopython-0.62.0}/src/videopython/editing/errors.py +0 -0
- {videopython-0.61.2 → videopython-0.62.0}/src/videopython/editing/operation.py +0 -0
- {videopython-0.61.2 → videopython-0.62.0}/src/videopython/editing/transcription_overlay.py +0 -0
- {videopython-0.61.2 → videopython-0.62.0}/src/videopython/editing/transforms.py +0 -0
- {videopython-0.61.2 → videopython-0.62.0}/src/videopython/mcp/__init__.py +0 -0
- {videopython-0.61.2 → videopython-0.62.0}/src/videopython/py.typed +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.5
|
|
2
2
|
Name: videopython
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.62.0
|
|
4
4
|
Summary: LLM-friendly Python video editing with JSON plans, local AI, and MCP tools.
|
|
5
5
|
Project-URL: Homepage, https://videopython.com
|
|
6
6
|
Project-URL: Repository, https://github.com/bartwojtowicz/videopython/
|
|
@@ -65,12 +65,11 @@ Structured, local-first video editing for Python and AI agents.
|
|
|
65
65
|
|
|
66
66
|
Videopython represents an edit as a validated Python model or JSON plan. Whether the
|
|
67
67
|
plan comes from your code, an LLM, or an MCP client, it renders through the same
|
|
68
|
-
bounded
|
|
68
|
+
streaming engine with bounded frame buffers.
|
|
69
69
|
|
|
70
70
|
[Documentation](https://videopython.com) ·
|
|
71
71
|
[First edit](https://videopython.com/tutorials/first-edit/) ·
|
|
72
|
-
[API reference](https://videopython.com/reference/)
|
|
73
|
-
[Roadmap](ROADMAP.md)
|
|
72
|
+
[API reference](https://videopython.com/reference/)
|
|
74
73
|
|
|
75
74
|
## Why videopython?
|
|
76
75
|
|
|
@@ -87,19 +86,10 @@ bounded-memory streaming engine.
|
|
|
87
86
|
|
|
88
87
|
## Installation
|
|
89
88
|
|
|
90
|
-
Install
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
pip install videopython # core video and audio editing
|
|
95
|
-
pip install "videopython[ai]" # all local AI features
|
|
96
|
-
pip install "videopython[mcp]" # MCP and its focused analysis stack
|
|
97
|
-
```
|
|
98
|
-
|
|
99
|
-
Videopython supports Python `>=3.11, <3.15`. The `ai` and `mcp` extras are independent;
|
|
100
|
-
install `videopython[ai,mcp]` if you need both. See the
|
|
101
|
-
[installation guide](https://videopython.com/install/) for FFmpeg features, model
|
|
102
|
-
downloads, Ollama setup, and hardware requirements.
|
|
89
|
+
Install FFmpeg, then run `uv add videopython` (or `pip install videopython`).
|
|
90
|
+
The optional `ai` and `mcp` extras add model runtimes and the MCP server.
|
|
91
|
+
See the [installation guide](https://videopython.com/install/) for supported
|
|
92
|
+
Python versions, extras, FFmpeg features, and model setup.
|
|
103
93
|
|
|
104
94
|
## Quick start
|
|
105
95
|
|
|
@@ -127,8 +117,8 @@ edit.validate()
|
|
|
127
117
|
edit.run_to_file("output.mp4")
|
|
128
118
|
```
|
|
129
119
|
|
|
130
|
-
`run_to_file()` streams the source through FFmpeg and the operation pipeline, so
|
|
131
|
-
|
|
120
|
+
`run_to_file()` streams the source through FFmpeg and the operation pipeline, so frame buffers
|
|
121
|
+
stay bounded for long videos. Continue with
|
|
132
122
|
[Your first edit](https://videopython.com/tutorials/first-edit/).
|
|
133
123
|
|
|
134
124
|
## What you can build
|
|
@@ -143,22 +133,17 @@ use stays bounded for long videos. Continue with
|
|
|
143
133
|
Core editing does not install PyTorch or other model runtimes. AI dependencies load only
|
|
144
134
|
when you use an AI feature.
|
|
145
135
|
|
|
146
|
-
##
|
|
147
|
-
|
|
148
|
-
The documentation follows [Diataxis](https://diataxis.fr/):
|
|
136
|
+
## Scope
|
|
149
137
|
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
- [Reference](https://videopython.com/reference/) documents the API, operations, and
|
|
154
|
-
JSON wire format.
|
|
155
|
-
- [Explanation](https://videopython.com/explanation/) covers the streaming engine,
|
|
156
|
-
plan lifecycle, architecture, and LLM-first design.
|
|
138
|
+
Videopython is a library for programmatic editing. It does not provide a hosted
|
|
139
|
+
inference service, an interactive editing application, universal support for model
|
|
140
|
+
runtimes and FFmpeg builds, or a second in-memory operation engine.
|
|
157
141
|
|
|
158
142
|
## Project status
|
|
159
143
|
|
|
160
144
|
Videopython is pre-1.0, so public interfaces can still change. See the
|
|
161
|
-
[
|
|
145
|
+
[compatibility policy](docs/reference/compatibility.md) for public contracts and
|
|
146
|
+
versioning rules, and [release notes](RELEASE_NOTES.md)
|
|
162
147
|
for changes between versions. Report vulnerabilities through the [security
|
|
163
148
|
policy](SECURITY.md).
|
|
164
149
|
|
|
@@ -9,12 +9,11 @@ Structured, local-first video editing for Python and AI agents.
|
|
|
9
9
|
|
|
10
10
|
Videopython represents an edit as a validated Python model or JSON plan. Whether the
|
|
11
11
|
plan comes from your code, an LLM, or an MCP client, it renders through the same
|
|
12
|
-
bounded
|
|
12
|
+
streaming engine with bounded frame buffers.
|
|
13
13
|
|
|
14
14
|
[Documentation](https://videopython.com) ·
|
|
15
15
|
[First edit](https://videopython.com/tutorials/first-edit/) ·
|
|
16
|
-
[API reference](https://videopython.com/reference/)
|
|
17
|
-
[Roadmap](ROADMAP.md)
|
|
16
|
+
[API reference](https://videopython.com/reference/)
|
|
18
17
|
|
|
19
18
|
## Why videopython?
|
|
20
19
|
|
|
@@ -31,19 +30,10 @@ bounded-memory streaming engine.
|
|
|
31
30
|
|
|
32
31
|
## Installation
|
|
33
32
|
|
|
34
|
-
Install
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
pip install videopython # core video and audio editing
|
|
39
|
-
pip install "videopython[ai]" # all local AI features
|
|
40
|
-
pip install "videopython[mcp]" # MCP and its focused analysis stack
|
|
41
|
-
```
|
|
42
|
-
|
|
43
|
-
Videopython supports Python `>=3.11, <3.15`. The `ai` and `mcp` extras are independent;
|
|
44
|
-
install `videopython[ai,mcp]` if you need both. See the
|
|
45
|
-
[installation guide](https://videopython.com/install/) for FFmpeg features, model
|
|
46
|
-
downloads, Ollama setup, and hardware requirements.
|
|
33
|
+
Install FFmpeg, then run `uv add videopython` (or `pip install videopython`).
|
|
34
|
+
The optional `ai` and `mcp` extras add model runtimes and the MCP server.
|
|
35
|
+
See the [installation guide](https://videopython.com/install/) for supported
|
|
36
|
+
Python versions, extras, FFmpeg features, and model setup.
|
|
47
37
|
|
|
48
38
|
## Quick start
|
|
49
39
|
|
|
@@ -71,8 +61,8 @@ edit.validate()
|
|
|
71
61
|
edit.run_to_file("output.mp4")
|
|
72
62
|
```
|
|
73
63
|
|
|
74
|
-
`run_to_file()` streams the source through FFmpeg and the operation pipeline, so
|
|
75
|
-
|
|
64
|
+
`run_to_file()` streams the source through FFmpeg and the operation pipeline, so frame buffers
|
|
65
|
+
stay bounded for long videos. Continue with
|
|
76
66
|
[Your first edit](https://videopython.com/tutorials/first-edit/).
|
|
77
67
|
|
|
78
68
|
## What you can build
|
|
@@ -87,22 +77,17 @@ use stays bounded for long videos. Continue with
|
|
|
87
77
|
Core editing does not install PyTorch or other model runtimes. AI dependencies load only
|
|
88
78
|
when you use an AI feature.
|
|
89
79
|
|
|
90
|
-
##
|
|
91
|
-
|
|
92
|
-
The documentation follows [Diataxis](https://diataxis.fr/):
|
|
80
|
+
## Scope
|
|
93
81
|
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
- [Reference](https://videopython.com/reference/) documents the API, operations, and
|
|
98
|
-
JSON wire format.
|
|
99
|
-
- [Explanation](https://videopython.com/explanation/) covers the streaming engine,
|
|
100
|
-
plan lifecycle, architecture, and LLM-first design.
|
|
82
|
+
Videopython is a library for programmatic editing. It does not provide a hosted
|
|
83
|
+
inference service, an interactive editing application, universal support for model
|
|
84
|
+
runtimes and FFmpeg builds, or a second in-memory operation engine.
|
|
101
85
|
|
|
102
86
|
## Project status
|
|
103
87
|
|
|
104
88
|
Videopython is pre-1.0, so public interfaces can still change. See the
|
|
105
|
-
[
|
|
89
|
+
[compatibility policy](docs/reference/compatibility.md) for public contracts and
|
|
90
|
+
versioning rules, and [release notes](RELEASE_NOTES.md)
|
|
106
91
|
for changes between versions. Report vulnerabilities through the [security
|
|
107
92
|
policy](SECURITY.md).
|
|
108
93
|
|
|
@@ -14,7 +14,7 @@ import subprocess
|
|
|
14
14
|
import tempfile
|
|
15
15
|
from contextlib import contextmanager
|
|
16
16
|
from pathlib import Path
|
|
17
|
-
from typing import Any, BinaryIO, Iterator, Sequence, cast
|
|
17
|
+
from typing import Any, BinaryIO, Callable, Iterator, Sequence, cast
|
|
18
18
|
|
|
19
19
|
from videopython._exceptions import FFmpegProbeError, FFmpegRunError
|
|
20
20
|
|
|
@@ -50,6 +50,29 @@ def run(cmd: Sequence[str], *, stdin: bytes | None = None) -> bytes:
|
|
|
50
50
|
return result.stdout
|
|
51
51
|
|
|
52
52
|
|
|
53
|
+
def run_with_progress(cmd: Sequence[str], on_frame: Callable[[int], None]) -> None:
|
|
54
|
+
"""Run an FFmpeg file output and drain frame progress until the process exits."""
|
|
55
|
+
argv = [cmd[0], "-progress", "pipe:1", "-stats_period", "0.25", "-nostats", *cmd[1:]]
|
|
56
|
+
with tempfile.TemporaryFile() as errors:
|
|
57
|
+
try:
|
|
58
|
+
proc = subprocess.Popen(argv, stdout=subprocess.PIPE, stderr=errors)
|
|
59
|
+
except FileNotFoundError as e:
|
|
60
|
+
raise FFmpegRunError(f"binary not found on PATH: {cmd[0]}") from e
|
|
61
|
+
try:
|
|
62
|
+
for line in cast(BinaryIO, proc.stdout):
|
|
63
|
+
key, _, value = line.partition(b"=")
|
|
64
|
+
if key == b"frame":
|
|
65
|
+
on_frame(int(value))
|
|
66
|
+
if proc.wait() != 0:
|
|
67
|
+
errors.seek(0)
|
|
68
|
+
raise FFmpegRunError(
|
|
69
|
+
f"ffmpeg failed (exit {proc.returncode}): {errors.read().decode(errors='replace')}"
|
|
70
|
+
)
|
|
71
|
+
finally:
|
|
72
|
+
_terminate(proc)
|
|
73
|
+
cast(BinaryIO, proc.stdout).close()
|
|
74
|
+
|
|
75
|
+
|
|
53
76
|
def probe(path: str | Path, *, extra_args: Sequence[str] | None = None) -> dict[str, Any]:
|
|
54
77
|
"""Run ffprobe and return the parsed JSON payload.
|
|
55
78
|
|
|
@@ -154,6 +154,19 @@ class OllamaStructuredClient:
|
|
|
154
154
|
raise OllamaError(f"Ollama returned a non-object JSON value: {type(data).__name__}")
|
|
155
155
|
return data
|
|
156
156
|
|
|
157
|
+
def model_provenance(self) -> dict[str, str | None] | None:
|
|
158
|
+
"""Resolve the used model tag to a server digest, without inference."""
|
|
159
|
+
if self._client is None:
|
|
160
|
+
return None
|
|
161
|
+
try:
|
|
162
|
+
models = self._client.list().models
|
|
163
|
+
except Exception:
|
|
164
|
+
return None
|
|
165
|
+
for model in models:
|
|
166
|
+
if model.model in (self.model, f"{self.model}:latest"):
|
|
167
|
+
return {model.model: model.digest}
|
|
168
|
+
return None
|
|
169
|
+
|
|
157
170
|
def unload(self) -> None:
|
|
158
171
|
try:
|
|
159
172
|
if self._client is not None and self.keep_alive is not None:
|
|
@@ -51,6 +51,10 @@ class ManagedPredictor:
|
|
|
51
51
|
# Attribute holding the resolved device passed to release_device_memory.
|
|
52
52
|
_device_attr: str = "device"
|
|
53
53
|
|
|
54
|
+
def model_provenance(self) -> dict[str, str | None] | None:
|
|
55
|
+
"""Return recorded model IDs and revisions, or None when unknown."""
|
|
56
|
+
return None
|
|
57
|
+
|
|
54
58
|
def unload(self) -> None:
|
|
55
59
|
"""Drop the model reference(s) and release device memory. Idempotent."""
|
|
56
60
|
for attr in self._model_attrs:
|
|
@@ -43,6 +43,8 @@ Usage:
|
|
|
43
43
|
|
|
44
44
|
from __future__ import annotations
|
|
45
45
|
|
|
46
|
+
from importlib import metadata
|
|
47
|
+
|
|
46
48
|
# Exact model-identifier string -> pinned commit SHA. The key must match the
|
|
47
49
|
# literal value passed to from_pretrained/hf_hub_download at the call site so
|
|
48
50
|
# ``pinned(model_id)`` resolves with a plain dict lookup. SHAs captured from
|
|
@@ -100,3 +102,11 @@ def pinned(model_id: str) -> str | None:
|
|
|
100
102
|
The pinned SHA, or ``None`` when no pin is registered for ``model_id``.
|
|
101
103
|
"""
|
|
102
104
|
return MODEL_REVISIONS.get(model_id)
|
|
105
|
+
|
|
106
|
+
|
|
107
|
+
def package_revision(distribution: str) -> str | None:
|
|
108
|
+
"""Identify bundled weights by their installed package release, when available."""
|
|
109
|
+
try:
|
|
110
|
+
return f"package:{metadata.version(distribution)}"
|
|
111
|
+
except metadata.PackageNotFoundError:
|
|
112
|
+
return None
|
|
@@ -14,7 +14,7 @@ from .backend import PlannerError, StructuredVisionLLM
|
|
|
14
14
|
from .catalog import build_catalog
|
|
15
15
|
from .editor import AutoEditError, AutoEditor
|
|
16
16
|
from .local import OllamaVisionLLM
|
|
17
|
-
from .models import CatalogBundle, CatalogScene, EditCatalog, EditPlan, PlanSegment
|
|
17
|
+
from .models import CatalogBundle, CatalogScene, EditCatalog, EditPlan, PlanSegment, SpeechCandidateConfig
|
|
18
18
|
from .resolve import UnknownSceneIdsError, resolve_plan
|
|
19
19
|
|
|
20
20
|
__all__ = [
|
|
@@ -28,6 +28,7 @@ __all__ = [
|
|
|
28
28
|
"PlanSegment",
|
|
29
29
|
"PlannerError",
|
|
30
30
|
"StructuredVisionLLM",
|
|
31
|
+
"SpeechCandidateConfig",
|
|
31
32
|
"UnknownSceneIdsError",
|
|
32
33
|
"build_catalog",
|
|
33
34
|
"resolve_plan",
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
import math
|
|
4
|
+
|
|
5
|
+
from videopython.base.transcription import Transcription, TranscriptionWord
|
|
6
|
+
|
|
7
|
+
from .models import SpeechCandidateConfig
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
def speech_passages(
|
|
11
|
+
transcription: Transcription | None, config: SpeechCandidateConfig
|
|
12
|
+
) -> list[list[TranscriptionWord]]:
|
|
13
|
+
if transcription is None or any(segment.text.strip() and not segment.words for segment in transcription.segments):
|
|
14
|
+
return []
|
|
15
|
+
words = sorted(transcription.words, key=lambda word: (word.start, word.end))
|
|
16
|
+
if not words:
|
|
17
|
+
return []
|
|
18
|
+
if any(not math.isfinite(w.start) or not math.isfinite(w.end) or w.start < 0 or w.end < w.start for w in words):
|
|
19
|
+
raise ValueError("Speech candidates require finite word times with 0 <= start <= end")
|
|
20
|
+
|
|
21
|
+
spans: list[list[TranscriptionWord]] = []
|
|
22
|
+
first = 0
|
|
23
|
+
end = words[0].end
|
|
24
|
+
for index, word in enumerate(words):
|
|
25
|
+
end = max(end, word.end)
|
|
26
|
+
following = words[index + 1] if index + 1 < len(words) else None
|
|
27
|
+
if following is not None and following.start < end:
|
|
28
|
+
continue
|
|
29
|
+
terminal = word.word.rstrip().rstrip("\"'”’»)]}").endswith((".", "?", "!", "…", "。", "?", "!"))
|
|
30
|
+
pause = following is not None and following.start - end >= config.pause_duration
|
|
31
|
+
if terminal or pause:
|
|
32
|
+
spans.append(words[first : index + 1])
|
|
33
|
+
first = index + 1
|
|
34
|
+
if following is not None:
|
|
35
|
+
end = following.end
|
|
36
|
+
|
|
37
|
+
passages: list[list[TranscriptionWord]] = []
|
|
38
|
+
pending: list[TranscriptionWord] = []
|
|
39
|
+
for span in spans:
|
|
40
|
+
start = span[0].start
|
|
41
|
+
end = max(word.end for word in span)
|
|
42
|
+
if end - start > config.max_duration:
|
|
43
|
+
pending = []
|
|
44
|
+
continue
|
|
45
|
+
if pending and (
|
|
46
|
+
start - max(word.end for word in pending) >= config.pause_duration
|
|
47
|
+
or end - pending[0].start > config.max_duration
|
|
48
|
+
):
|
|
49
|
+
pending = []
|
|
50
|
+
pending.extend(span)
|
|
51
|
+
if end - pending[0].start >= config.min_duration:
|
|
52
|
+
passages.append(pending)
|
|
53
|
+
pending = []
|
|
54
|
+
return passages
|
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
"""Build the LLM-facing edit catalog from VideoAnalysis results."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import hashlib
|
|
6
|
+
import json
|
|
7
|
+
from collections.abc import Sequence
|
|
8
|
+
from pathlib import Path
|
|
9
|
+
from typing import TYPE_CHECKING, Literal
|
|
10
|
+
|
|
11
|
+
import numpy as np
|
|
12
|
+
|
|
13
|
+
from videopython.base.video import extract_frames_at_times
|
|
14
|
+
|
|
15
|
+
from ._speech import speech_passages
|
|
16
|
+
from .models import CatalogBundle, CatalogScene, EditCatalog, SpeechCandidateConfig
|
|
17
|
+
|
|
18
|
+
if TYPE_CHECKING:
|
|
19
|
+
from videopython.ai.video_analysis import SceneAnalysisSample, VideoAnalysis
|
|
20
|
+
from videopython.base.transcription import Transcription
|
|
21
|
+
|
|
22
|
+
DEFAULT_TRANSCRIPT_CHARS = 280
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
def build_catalog(
|
|
26
|
+
analyses: Sequence[VideoAnalysis],
|
|
27
|
+
*,
|
|
28
|
+
keyframes: bool = True,
|
|
29
|
+
max_transcript_chars: int = DEFAULT_TRANSCRIPT_CHARS,
|
|
30
|
+
mode: Literal["visual", "speech"] = "visual",
|
|
31
|
+
speech: SpeechCandidateConfig | None = None,
|
|
32
|
+
) -> CatalogBundle:
|
|
33
|
+
"""Build visual scenes or timed speech passages; speech mode requires speech settings."""
|
|
34
|
+
if mode not in ("visual", "speech") or (mode == "speech") != (speech is not None):
|
|
35
|
+
raise ValueError("Supply speech settings exactly when mode='speech'")
|
|
36
|
+
scenes: list[CatalogScene] = []
|
|
37
|
+
transcripts: dict[str, str] = {}
|
|
38
|
+
used_ids: set[str] = set()
|
|
39
|
+
|
|
40
|
+
for analysis in analyses:
|
|
41
|
+
source_path = analysis.source.path
|
|
42
|
+
samples = analysis.scenes.samples if analysis.scenes else []
|
|
43
|
+
transcription = analysis.audio.transcription if analysis.audio else None
|
|
44
|
+
stem = Path(source_path).stem if source_path else "clip"
|
|
45
|
+
|
|
46
|
+
if speech is not None:
|
|
47
|
+
if analysis.source.duration is None:
|
|
48
|
+
raise ValueError("Speech candidates require the source duration")
|
|
49
|
+
identity = json.dumps(
|
|
50
|
+
[
|
|
51
|
+
str(Path(source_path).resolve()) if source_path else None,
|
|
52
|
+
transcription.model_dump() if transcription else None,
|
|
53
|
+
speech.model_dump(),
|
|
54
|
+
],
|
|
55
|
+
sort_keys=True,
|
|
56
|
+
)
|
|
57
|
+
digest = hashlib.sha256(identity.encode()).hexdigest()[:24]
|
|
58
|
+
for index, passage in enumerate(speech_passages(transcription, speech)):
|
|
59
|
+
start, end = passage[0].start, max(word.end for word in passage)
|
|
60
|
+
if end > analysis.source.duration or start >= analysis.source.duration:
|
|
61
|
+
continue
|
|
62
|
+
scene_id = _unique_id(f"{stem}#speech-{digest}", index, used_ids)
|
|
63
|
+
text = " ".join(" ".join(word.word.split()) for word in passage).strip()
|
|
64
|
+
scenes.append(
|
|
65
|
+
CatalogScene(
|
|
66
|
+
id=scene_id,
|
|
67
|
+
source=Path(source_path) if source_path else Path(stem),
|
|
68
|
+
start=start,
|
|
69
|
+
end=end,
|
|
70
|
+
duration=end - start,
|
|
71
|
+
transcript=_shorten(text, max_transcript_chars),
|
|
72
|
+
has_speech=True,
|
|
73
|
+
)
|
|
74
|
+
)
|
|
75
|
+
transcripts[scene_id] = text
|
|
76
|
+
if keyframes and source_path is None:
|
|
77
|
+
raise ValueError(f"Scene {scene_id!r} has no source path to extract a keyframe from.")
|
|
78
|
+
continue
|
|
79
|
+
|
|
80
|
+
for sample in samples:
|
|
81
|
+
scene_id = _unique_id(stem, sample.scene_index, used_ids)
|
|
82
|
+
caption, shot_type = _description(sample)
|
|
83
|
+
text = _transcript_text(transcription, sample.start_second, sample.end_second)
|
|
84
|
+
transcripts[scene_id] = text
|
|
85
|
+
transcript = _shorten(text, max_transcript_chars)
|
|
86
|
+
scenes.append(
|
|
87
|
+
CatalogScene(
|
|
88
|
+
id=scene_id,
|
|
89
|
+
source=Path(source_path) if source_path else Path(stem),
|
|
90
|
+
start=sample.start_second,
|
|
91
|
+
end=sample.end_second,
|
|
92
|
+
duration=max(0.0, sample.end_second - sample.start_second),
|
|
93
|
+
shot_type=shot_type,
|
|
94
|
+
caption=caption,
|
|
95
|
+
transcript=transcript,
|
|
96
|
+
has_speech=bool(transcript),
|
|
97
|
+
has_faces=bool(sample.faces),
|
|
98
|
+
)
|
|
99
|
+
)
|
|
100
|
+
if keyframes and source_path is None:
|
|
101
|
+
raise ValueError(f"Scene {scene_id!r} has no source path to extract a keyframe from.")
|
|
102
|
+
|
|
103
|
+
frames = extract_catalog_keyframes(scenes) if keyframes else {}
|
|
104
|
+
return CatalogBundle(catalog=EditCatalog(scenes=scenes), keyframes=frames, transcripts=transcripts)
|
|
105
|
+
|
|
106
|
+
|
|
107
|
+
def extract_catalog_keyframes(scenes: Sequence[CatalogScene]) -> dict[str, np.ndarray]:
|
|
108
|
+
"""Extract scene midpoints in one decode per source, preserving scene IDs."""
|
|
109
|
+
by_source: dict[Path, list[CatalogScene]] = {}
|
|
110
|
+
for scene in scenes:
|
|
111
|
+
by_source.setdefault(scene.source, []).append(scene)
|
|
112
|
+
frames: dict[str, np.ndarray] = {}
|
|
113
|
+
for source, source_scenes in by_source.items():
|
|
114
|
+
timestamps = [(scene.start + scene.end) / 2.0 for scene in source_scenes]
|
|
115
|
+
extracted = extract_frames_at_times(source, timestamps)
|
|
116
|
+
for index, scene in enumerate(source_scenes):
|
|
117
|
+
frames[scene.id] = extracted[index]
|
|
118
|
+
return frames
|
|
119
|
+
|
|
120
|
+
|
|
121
|
+
def _unique_id(stem: str, scene_index: int, used: set[str]) -> str:
|
|
122
|
+
base = f"{stem}#{scene_index}"
|
|
123
|
+
candidate, suffix = base, 2
|
|
124
|
+
while candidate in used:
|
|
125
|
+
candidate = f"{base}-{suffix}"
|
|
126
|
+
suffix += 1
|
|
127
|
+
used.add(candidate)
|
|
128
|
+
return candidate
|
|
129
|
+
|
|
130
|
+
|
|
131
|
+
def _description(sample: SceneAnalysisSample) -> tuple[str, str | None]:
|
|
132
|
+
desc = sample.scene_description
|
|
133
|
+
return (desc.caption or "", desc.shot_type) if desc else ("", None)
|
|
134
|
+
|
|
135
|
+
|
|
136
|
+
def _transcript_text(transcription: Transcription | None, start: float, end: float) -> str:
|
|
137
|
+
sliced = transcription.slice(start, end) if transcription else None
|
|
138
|
+
if sliced is None:
|
|
139
|
+
return ""
|
|
140
|
+
return " ".join(" ".join(segment.text.split()) for segment in sliced.segments).strip()
|
|
141
|
+
|
|
142
|
+
|
|
143
|
+
def _shorten(text: str, max_chars: int) -> str:
|
|
144
|
+
if len(text) > max_chars:
|
|
145
|
+
text = text[: max_chars - 3].rstrip() + "..."
|
|
146
|
+
return text
|
|
@@ -7,13 +7,29 @@ from pathlib import Path
|
|
|
7
7
|
from typing import Any
|
|
8
8
|
|
|
9
9
|
import numpy as np
|
|
10
|
-
from pydantic import BaseModel, ConfigDict, Field
|
|
10
|
+
from pydantic import BaseModel, ConfigDict, Field, model_validator
|
|
11
11
|
|
|
12
12
|
from videopython.editing._schema import array_field_schema, field_schema, optional_model_field_schema
|
|
13
13
|
from videopython.editing.operation import Operation, _to_strict_schema
|
|
14
14
|
from videopython.editing.video_edit import OperationInput, TransitionSpec
|
|
15
15
|
|
|
16
16
|
|
|
17
|
+
class SpeechCandidateConfig(BaseModel):
|
|
18
|
+
"""Duration limits and minimum pause for deterministic speech candidates."""
|
|
19
|
+
|
|
20
|
+
model_config = ConfigDict(extra="forbid", frozen=True, allow_inf_nan=False)
|
|
21
|
+
|
|
22
|
+
min_duration: float = Field(gt=0)
|
|
23
|
+
max_duration: float = Field(gt=0)
|
|
24
|
+
pause_duration: float = Field(0.8, gt=0)
|
|
25
|
+
|
|
26
|
+
@model_validator(mode="after")
|
|
27
|
+
def _ordered_limits(self) -> SpeechCandidateConfig:
|
|
28
|
+
if self.max_duration < self.min_duration:
|
|
29
|
+
raise ValueError("max_duration must be at least min_duration")
|
|
30
|
+
return self
|
|
31
|
+
|
|
32
|
+
|
|
17
33
|
class CatalogScene(BaseModel):
|
|
18
34
|
"""A candidate scene the planner picks by id; carries the exact source bounds."""
|
|
19
35
|
|
|
@@ -44,6 +60,7 @@ class CatalogBundle:
|
|
|
44
60
|
|
|
45
61
|
catalog: EditCatalog
|
|
46
62
|
keyframes: dict[str, np.ndarray] = field(default_factory=dict)
|
|
63
|
+
transcripts: dict[str, str] = field(default_factory=dict)
|
|
47
64
|
|
|
48
65
|
|
|
49
66
|
class PlanSegment(BaseModel):
|
|
@@ -31,7 +31,7 @@ class DubbingConfig(BaseModel):
|
|
|
31
31
|
on, a single hallucinated filler phrase cascades through the rest
|
|
32
32
|
of the file. See ``AudioToText`` for the full rationale.
|
|
33
33
|
no_speech_threshold: Forwarded to ``AudioToText``. Whisper's
|
|
34
|
-
no-speech
|
|
34
|
+
no-speech probability cutoff; lower it to make that gate easier to trigger.
|
|
35
35
|
logprob_threshold: Forwarded to ``AudioToText``. Whisper's average
|
|
36
36
|
log-probability gate.
|
|
37
37
|
vocabulary: Forwarded to ``AudioToText``. Optional list of brand
|
|
@@ -32,12 +32,3 @@ def encode_png_b64(frame: np.ndarray) -> str:
|
|
|
32
32
|
buffer = io.BytesIO()
|
|
33
33
|
Image.fromarray(frame).save(buffer, format="PNG")
|
|
34
34
|
return base64.b64encode(buffer.getvalue()).decode("ascii")
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
def keyframe_to_png_b64(frame: np.ndarray, max_dim: int = KEYFRAME_MAX_DIM) -> str:
|
|
38
|
-
"""Downscale a keyframe then PNG-encode it as base64 -- the MCP transport payload.
|
|
39
|
-
|
|
40
|
-
SceneVLM captioning and the local planner deliberately encode full-resolution
|
|
41
|
-
frames via :func:`encode_png_b64` instead.
|
|
42
|
-
"""
|
|
43
|
-
return encode_png_b64(downscale_keyframe(frame, max_dim=max_dim))
|
|
@@ -8,7 +8,7 @@ from typing import Any, Literal
|
|
|
8
8
|
|
|
9
9
|
from videopython.ai._device import log_device_initialization, select_device
|
|
10
10
|
from videopython.ai._predictor import ManagedPredictor
|
|
11
|
-
from videopython.ai._revisions import pinned
|
|
11
|
+
from videopython.ai._revisions import package_revision, pinned
|
|
12
12
|
from videopython.audio import Audio
|
|
13
13
|
from videopython.base.transcription import Transcription, TranscriptionSegment, TranscriptionWord
|
|
14
14
|
from videopython.base.video import Video
|
|
@@ -138,9 +138,9 @@ class AudioToText(ManagedPredictor):
|
|
|
138
138
|
clean audio is small (slightly less context for ambiguous homophones
|
|
139
139
|
across sentence boundaries).
|
|
140
140
|
- ``no_speech_threshold`` and ``logprob_threshold`` are forwarded with
|
|
141
|
-
Whisper's
|
|
142
|
-
``no_speech_threshold``
|
|
143
|
-
|
|
141
|
+
Whisper's defaults (``0.6`` and ``-1.0``). Lowering
|
|
142
|
+
``no_speech_threshold`` makes the no-speech probability gate easier
|
|
143
|
+
to trigger; ``logprob_threshold`` also affects whether a window is skipped.
|
|
144
144
|
|
|
145
145
|
``vocabulary`` biases Whisper's first-window decoder toward a caller-
|
|
146
146
|
supplied list of brand names, product names, or proper nouns via the
|
|
@@ -166,6 +166,7 @@ class AudioToText(ManagedPredictor):
|
|
|
166
166
|
if model_name not in _WHISPER_MODELS:
|
|
167
167
|
choices = ", ".join(_WHISPER_MODELS)
|
|
168
168
|
raise ValueError(f"Unsupported Whisper model {model_name!r}. Choose one of: {choices}.")
|
|
169
|
+
self._loaded_models: dict[str, str | None] = {}
|
|
169
170
|
self.model_name = model_name
|
|
170
171
|
self.enable_diarization = enable_diarization
|
|
171
172
|
self.enable_vad = enable_vad
|
|
@@ -204,6 +205,9 @@ class AudioToText(ManagedPredictor):
|
|
|
204
205
|
kwargs["initial_prompt"] = prompt
|
|
205
206
|
return kwargs
|
|
206
207
|
|
|
208
|
+
def model_provenance(self) -> dict[str, str | None] | None:
|
|
209
|
+
return dict(self._loaded_models) if self._loaded_models else None
|
|
210
|
+
|
|
207
211
|
def _init_local(self) -> None:
|
|
208
212
|
"""Initialize local Whisper model."""
|
|
209
213
|
from videopython.ai._optional import require
|
|
@@ -216,6 +220,7 @@ class AudioToText(ManagedPredictor):
|
|
|
216
220
|
device=self.device,
|
|
217
221
|
compute_type="float32",
|
|
218
222
|
)
|
|
223
|
+
self._loaded_models[model_id] = pinned(model_id)
|
|
219
224
|
|
|
220
225
|
def _run_whisper(self, audio: Any, language: str | None, vocabulary: list[str]) -> dict[str, Any]:
|
|
221
226
|
segments_source, info = self._model.transcribe(
|
|
@@ -248,6 +253,7 @@ class AudioToText(ManagedPredictor):
|
|
|
248
253
|
self._diarization_pipeline = Pipeline.from_pretrained(
|
|
249
254
|
self.PYANNOTE_DIARIZATION_MODEL, revision=pinned(self.PYANNOTE_DIARIZATION_MODEL)
|
|
250
255
|
)
|
|
256
|
+
self._loaded_models[self.PYANNOTE_DIARIZATION_MODEL] = pinned(self.PYANNOTE_DIARIZATION_MODEL)
|
|
251
257
|
_pyannote_patches.install(self._diarization_pipeline)
|
|
252
258
|
self._diarization_pipeline.to(torch.device(self.device))
|
|
253
259
|
|
|
@@ -263,6 +269,7 @@ class AudioToText(ManagedPredictor):
|
|
|
263
269
|
load_silero_vad = require("silero_vad", feature="AudioToText VAD").load_silero_vad
|
|
264
270
|
|
|
265
271
|
self._vad_model = load_silero_vad()
|
|
272
|
+
self._loaded_models["silero-vad/bundled"] = package_revision("silero-vad")
|
|
266
273
|
|
|
267
274
|
def _process_transcription_result(self, transcription_result: dict[str, Any]) -> Transcription:
|
|
268
275
|
"""Process raw transcription result into a Transcription object."""
|
{videopython-0.61.2 → videopython-0.62.0}/src/videopython/ai/understanding/classification.py
RENAMED
|
@@ -34,6 +34,7 @@ class AudioClassifier(ManagedPredictor):
|
|
|
34
34
|
top_k: int = 10,
|
|
35
35
|
device: str | None = None,
|
|
36
36
|
):
|
|
37
|
+
self._loaded_models: dict[str, str | None] | None = None
|
|
37
38
|
self.model_name = model_name
|
|
38
39
|
self.confidence_threshold = confidence_threshold
|
|
39
40
|
self.top_k = top_k
|
|
@@ -48,6 +49,9 @@ class AudioClassifier(ManagedPredictor):
|
|
|
48
49
|
self._processor: Any = None
|
|
49
50
|
self._labels: list[str] = []
|
|
50
51
|
|
|
52
|
+
def model_provenance(self) -> dict[str, str | None] | None:
|
|
53
|
+
return dict(self._loaded_models) if self._loaded_models is not None else None
|
|
54
|
+
|
|
51
55
|
def _init_local(self) -> None:
|
|
52
56
|
"""Initialize local AST model from HuggingFace."""
|
|
53
57
|
from videopython.ai._optional import require
|
|
@@ -60,6 +64,7 @@ class AudioClassifier(ManagedPredictor):
|
|
|
60
64
|
self._model = ASTForAudioClassification.from_pretrained(self.model_name, revision=pinned(self.model_name))
|
|
61
65
|
self._model.to(self.device)
|
|
62
66
|
self._model.eval()
|
|
67
|
+
self._loaded_models = {self.model_name: pinned(self.model_name)}
|
|
63
68
|
|
|
64
69
|
self._labels = [self._model.config.id2label[i] for i in range(len(self._model.config.id2label))]
|
|
65
70
|
|