Video analysis¶
VideoAnalyzer runs the global passes (transcription + scene detection), then per
detected scene runs the scene VLM, the audio classifier, and the per-shot face tracker.
The result is one serializable, scene-first VideoAnalysis.
from videopython.ai import VideoAnalysis, VideoAnalyzer
analysis = VideoAnalyzer().analyze_path("video.mp4")
print(analysis.source.title)
for outcome in analysis.run_info.analyzer_outcomes:
print(outcome.analyzer, outcome.status, outcome.reason)
if analysis.scenes:
sample = analysis.scenes.samples[0]
if sample.scene_description:
print(sample.scene_description.caption, sample.scene_description.shot_type)
for track in (sample.faces or []):
print(f"track #{track.track_id}: {track.length} frames")
analysis.save("video_analysis.json")
loaded = VideoAnalysis.load("video_analysis.json")
VideoAnalysis and its nested result types are Pydantic models, so model_dump(),
model_dump_json(), model_validate() and model_validate_json() work throughout the
result tree. save() / load() wrap the JSON pair with UTF-8 and parent-directory
creation. Use loaded.verify_source() to compare the recorded source digest with
the current file; load() alone does not read the media.
Saved identity and migration¶
Every result requires an AnalysisProvenance object at analysis.provenance:
| Field | Contract |
|---|---|
format_version |
Required integer 1; other versions are rejected. |
source_sha256 |
SHA256 of the source file, or null for unbound in-memory input. |
sampling |
The low, medium, or high preset used for the run. |
models |
Analyzer ID to a model-ID/revision map, or null when provenance is unknown. A model revision can also be null. |
Model identities are recorded during analysis. Hugging Face models use repository
revisions (AST records its requested pin, or null for an unpinned model); Ollama uses the server's resolved tag and digest. Bundled Silero and
TransNetV2 weights use a package:<version> revision, which identifies the package
release rather than a weight-file hash. A disabled stage, an early load failure, or
an unavailable identity can leave unknown provenance. Check stage outcomes separately:
known identity is not a successful-analysis flag.
analyze_path() records a resolved absolute source path and hashes the file with
bounded reads. analyze(video, ...) leaves source_sha256=null, even if a source-path
label was supplied, because the in-memory frames are not verified against that file.
Those unbound results can be serialized but cannot be imported into MCP.
verify_source() requires a recorded file identity, compares its digest, and returns
the resolved source path. It starts no models and does not replace saved settings
or unknown provenance with values from the current environment. MCP import/export
performs this check once per call. Source files must remain unchanged while a cached
analysis is in use.
Migration: regenerate older saved analyses with VideoAnalyzer.analyze_path().
Files without provenance are rejected; there is no legacy loader. Do not add the
currently installed models as if they had produced an old result. See
reuse across MCP sessions.
AnalysisProvenance
¶
Bases: BaseModel
Source identity and model revisions recorded during analysis.
Source code in src/videopython/ai/video_analysis/models.py
Configuration¶
from videopython.ai import VideoAnalysisConfig, VideoAnalyzer
config = VideoAnalysisConfig(
enabled_analyzers={"audio_to_text", "semantic_scene_detector", "scene_vlm", "face_tracker"},
analyzer_params={
"scene_vlm": {"model": "qwen3.6:27b"},
"audio_to_text": {"model_name": "large", "vocabulary": ["Klarna", "Allegro"]},
},
)
analysis = VideoAnalyzer(config=config, sampling="medium").analyze_path("video.mp4")
VideoAnalysisConfig.for_profile("full") enables every analyzer (audio_to_text,
audio_classifier, semantic_scene_detector, scene_vlm, face_tracker) and is
equivalent to a bare VideoAnalysisConfig().
Sampling presets¶
sampling sizes the per-scene SceneVLM frame budget: the frame cap, the log-curve
scale/base used for short scenes, and the threshold below which adjacent short scenes
are merged into one VLM call.
sampling |
Per-scene frame cap | Adjacent-merge threshold | Typical use |
|---|---|---|---|
"low" |
8 | 20 s | Quick previews, long videos |
"medium" (default) |
30 | 10 s | Balanced |
"high" |
60 | 4 s | Rich analysis, talking-head depth |
sampling and the VLM model are orthogonal: one sizes the frame budget, the other picks
the captioning model.
Output shape¶
analysis.audio.transcription— the full Whisper transcription.analysis.scenes.samples— oneSceneAnalysisSampleper scene, each carrying:- scene timing (
start_second,end_second,start_frame,end_frame); scene_description: SceneDescription | None— caption, subjects, shot_type.Nonewhen the VLM was disabled or its forward pass failed;audio_classification: AudioClassification | None— events and clip-level predictions for the scene window;faces: list[FaceTrack] | None— per-shot IoU-associated tracks, each with its own frame indices and boxes.
- scene timing (
analysis.run_info.stage_durations_seconds— wall-clock per stage (whisper,scene_detection,scene_vlm,face_tracker,audio_classification, pluswhisper_and_scene_detection_parallelwhen those two run together).analysis.run_info.analyzer_outcomes— one record for every analyzer.statusiscompleted,skipped, orfailed. A skipped analyzer has reasondisabled; a failed analyzer has reasoninitialization_failedorexecution_failed.
Classes¶
VideoAnalysisConfig
¶
Bases: BaseModel
Execution config for scene-first analysis runs.
analyzer_params lets you forward keyword arguments to each predictor
constructor keyed by analyzer id. For example::
VideoAnalysisConfig(
analyzer_params={
"audio_to_text": {"model_name": "large"},
"scene_vlm": {"model": "qwen3.6:27b"},
}
)
Source code in src/videopython/ai/video_analysis/models.py
get_params
¶
Return kwargs dict for the given analyzer, defaulting to empty.
for_profile
classmethod
¶
Config for an analysis profile: 'full' (all analyzers) or 'editing' (catalog-only, no audio classifier).
Source code in src/videopython/ai/video_analysis/models.py
VideoAnalyzer
¶
Orchestrates scene-first analyzers and builds VideoAnalysis output.
sampling controls how aggressively the SceneVLM samples frames per
scene. low is a fast preview pass for long videos, high keeps
talking-head depth, medium is the previous default. The preset
tunes the per-scene frame cap, the log-curve scale/base used to size
short scenes, and the threshold below which adjacent scenes get
merged into one VLM call.
sampling and the SceneVLM tier are orthogonal: small models
can't make use of dense sampling, but the user owns that tradeoff.
Source code in src/videopython/ai/video_analysis/analyzer.py
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 | |
analyze_path
¶
Analyze a video path in scene-first mode.
Source code in src/videopython/ai/video_analysis/analyzer.py
analyze
¶
Analyze an in-memory Video object.
Source code in src/videopython/ai/video_analysis/analyzer.py
VideoAnalysis
¶
Bases: BaseModel
Serializable aggregate scene-first analysis result for one video.
Source code in src/videopython/ai/video_analysis/models.py
verify_source
¶
Check the recorded file digest and return its resolved path without inference.