AI Understanding
Analyze videos, transcribe audio, and describe visual content.
Backend Support
| Class | local | openai | gemini | elevenlabs |
|---|---|---|---|---|
| ImageToText | BLIP | GPT-4o | Gemini | - |
| AudioToText | Whisper | Whisper API | Gemini | - |
| LLMSummarizer | Ollama | GPT-4o | Gemini | - |
| ObjectDetector | YOLO | GPT-4o | Gemini | - |
| TextDetector | EasyOCR | GPT-4o | Gemini | - |
| FaceDetector | OpenCV | - | - | - |
| ShotTypeClassifier | - | GPT-4o | Gemini | - |
| CameraMotionDetector | OpenCV | - | - | - |
AudioToText
AudioToText
Transcription service for audio and video.
Source code in src/videopython/ai/understanding/audio.py
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 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 | |
__init__
__init__(
backend: AudioToTextBackend | None = None,
model_name: Literal[
"tiny", "base", "small", "medium", "large", "turbo"
] = "small",
enable_diarization: bool = False,
device: str = "cpu",
compute_type: str = "float32",
api_key: str | None = None,
)
Initialize the audio-to-text transcriber.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
backend
|
AudioToTextBackend | None
|
Backend to use. If None, uses config default or 'local'. |
None
|
model_name
|
Literal['tiny', 'base', 'small', 'medium', 'large', 'turbo']
|
Whisper model for local backend. |
'small'
|
enable_diarization
|
bool
|
Enable speaker diarization (local backend only). |
False
|
device
|
str
|
Device for local backend ('cuda' or 'cpu'). |
'cpu'
|
compute_type
|
str
|
Compute type for local backend. |
'float32'
|
api_key
|
str | None
|
API key for cloud backends. If None, reads from environment. |
None
|
Source code in src/videopython/ai/understanding/audio.py
transcribe
async
Transcribe audio or video to text.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
media
|
Audio | Video
|
Audio or Video to transcribe. |
required |
Returns:
| Type | Description |
|---|---|
Transcription
|
Transcription object with segments of text and their timestamps. |
Source code in src/videopython/ai/understanding/audio.py
ImageToText
ImageToText
Generates text descriptions of images.
Source code in src/videopython/ai/understanding/image.py
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 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 | |
__init__
__init__(
backend: ImageToTextBackend | None = None,
device: str | None = None,
num_dominant_colors: int = 5,
api_key: str | None = None,
)
Initialize image-to-text model.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
backend
|
ImageToTextBackend | None
|
Backend to use. If None, uses config default or 'local'. |
None
|
device
|
str | None
|
Device for local backend ('cuda' or 'cpu'). |
None
|
num_dominant_colors
|
int
|
Number of dominant colors for color analysis. |
5
|
api_key
|
str | None
|
API key for cloud backends. If None, reads from environment. |
None
|
Source code in src/videopython/ai/understanding/image.py
describe_image
async
Generate a text description of an image.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
image
|
ndarray | Image
|
Image as numpy array (H, W, 3) in RGB format or PIL Image. |
required |
prompt
|
str | None
|
Optional text prompt to guide the description. |
None
|
Returns:
| Type | Description |
|---|---|
str
|
Text description of the image. |
Source code in src/videopython/ai/understanding/image.py
describe_frame
async
describe_frame(
video: Video,
frame_index: int,
prompt: str | None = None,
extract_colors: bool = False,
include_full_histogram: bool = False,
) -> FrameDescription
Describe a specific frame from a video.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
video
|
Video
|
Video object. |
required |
frame_index
|
int
|
Index of the frame to describe. |
required |
prompt
|
str | None
|
Optional text prompt to guide the description. |
None
|
extract_colors
|
bool
|
Whether to extract color features from the frame. |
False
|
include_full_histogram
|
bool
|
Whether to include full HSV histogram. |
False
|
Returns:
| Type | Description |
|---|---|
FrameDescription
|
FrameDescription object with the frame description. |
Source code in src/videopython/ai/understanding/image.py
describe_frames
async
describe_frames(
video: Video,
frame_indices: list[int],
prompt: str | None = None,
extract_colors: bool = False,
include_full_histogram: bool = False,
) -> list[FrameDescription]
Describe multiple frames from a video.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
video
|
Video
|
Video object. |
required |
frame_indices
|
list[int]
|
List of frame indices to describe. |
required |
prompt
|
str | None
|
Optional text prompt to guide the descriptions. |
None
|
extract_colors
|
bool
|
Whether to extract color features. |
False
|
include_full_histogram
|
bool
|
Whether to include full HSV histogram. |
False
|
Returns:
| Type | Description |
|---|---|
list[FrameDescription]
|
List of FrameDescription objects. |
Source code in src/videopython/ai/understanding/image.py
describe_scene
async
describe_scene(
video: Video,
scene: SceneDescription,
frames_per_second: float = 1.0,
prompt: str | None = None,
extract_colors: bool = False,
include_full_histogram: bool = False,
) -> list[FrameDescription]
Describe frames from a scene, sampling at the specified rate.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
video
|
Video
|
Video object. |
required |
scene
|
SceneDescription
|
SceneDescription to analyze. |
required |
frames_per_second
|
float
|
Frame sampling rate. |
1.0
|
prompt
|
str | None
|
Optional text prompt to guide the descriptions. |
None
|
extract_colors
|
bool
|
Whether to extract color features. |
False
|
include_full_histogram
|
bool
|
Whether to include full HSV histogram. |
False
|
Returns:
| Type | Description |
|---|---|
list[FrameDescription]
|
List of FrameDescription objects for the sampled frames. |
Source code in src/videopython/ai/understanding/image.py
LLMSummarizer
LLMSummarizer
Generates coherent summaries of video content using LLMs.
Source code in src/videopython/ai/understanding/text.py
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 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 | |
__init__
__init__(
backend: LLMBackend | None = None,
model: str | None = None,
api_key: str | None = None,
timeout: float = 30.0,
)
Initialize the LLM summarizer.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
backend
|
LLMBackend | None
|
Backend to use. If None, uses config default or 'local'. |
None
|
model
|
str | None
|
Model name (backend-specific). If None, uses default per backend. |
None
|
api_key
|
str | None
|
API key for cloud backends. If None, reads from environment. |
None
|
timeout
|
float
|
Request timeout in seconds. |
30.0
|
Source code in src/videopython/ai/understanding/text.py
summarize_scene
async
Generate a coherent summary of a scene from frame descriptions.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
frame_descriptions
|
list[tuple[float, str]]
|
List of (timestamp, description) tuples for frames. |
required |
Returns:
| Type | Description |
|---|---|
str
|
2-3 sentence coherent summary of the scene. |
Source code in src/videopython/ai/understanding/text.py
summarize_video
async
Generate a high-level summary of the entire video from scene summaries.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
scene_summaries
|
list[tuple[float, float, str]]
|
List of (start_time, end_time, summary) tuples for each scene. |
required |
Returns:
| Type | Description |
|---|---|
str
|
Paragraph describing the entire video narrative. |
Source code in src/videopython/ai/understanding/text.py
summarize_scene_description
async
Generate summary from a SceneDescription object.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
scene_description
|
SceneDescription
|
SceneDescription object with frame descriptions. |
required |
Returns:
| Type | Description |
|---|---|
str
|
Coherent summary of the scene. |
Source code in src/videopython/ai/understanding/text.py
summarize_video_description
async
Generate summary from a VideoDescription object.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
video_description
|
VideoDescription
|
VideoDescription object with scene descriptions. |
required |
Returns:
| Type | Description |
|---|---|
str
|
High-level summary of the entire video. |
Source code in src/videopython/ai/understanding/text.py
SceneDetector
SceneDetector
Detects scene changes in videos using histogram comparison.
Scene changes are detected by comparing the color histograms of consecutive frames. When the histogram difference exceeds a threshold, a scene boundary is detected.
Source code in src/videopython/ai/understanding/video.py
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 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 | |
__init__
Initialize the scene detector.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
threshold
|
float
|
Sensitivity for scene change detection (0.0 to 1.0). Lower values detect more scene changes. Default: 0.3 |
0.3
|
min_scene_length
|
float
|
Minimum scene duration in seconds. Scenes shorter than this will be merged with adjacent scenes. Default: 0.5 |
0.5
|
Source code in src/videopython/ai/understanding/video.py
detect
Detect scenes in a video.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
video
|
Video
|
Video object to analyze |
required |
Returns:
| Type | Description |
|---|---|
list[SceneDescription]
|
List of SceneDescription objects representing detected scenes, ordered by time. |
list[SceneDescription]
|
Frame descriptions are not populated - use VideoAnalyzer for full analysis. |
Source code in src/videopython/ai/understanding/video.py
VideoAnalyzer
VideoAnalyzer
Comprehensive video analysis combining scene detection, frame understanding, and transcription.
Source code in src/videopython/ai/understanding/video.py
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 | |
__init__
__init__(
scene_threshold: float = 0.3,
min_scene_length: float = 0.5,
device: str | None = None,
detection_backend: ImageToTextBackend | None = None,
api_key: str | None = None,
)
Initialize the video analyzer.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
scene_threshold
|
float
|
Threshold for scene change detection (0.0-1.0) |
0.3
|
min_scene_length
|
float
|
Minimum scene duration in seconds |
0.5
|
device
|
str | None
|
Device for ImageToText model ('cuda', 'cpu', or None for auto) |
None
|
detection_backend
|
ImageToTextBackend | None
|
Backend for object/text detection ('local', 'openai', 'gemini') |
None
|
api_key
|
str | None
|
API key for cloud backends |
None
|
Source code in src/videopython/ai/understanding/video.py
analyze
async
analyze(
video: Video,
frames_per_second: float = 1.0,
transcribe: bool = False,
transcription_model: Literal[
"tiny", "base", "small", "medium", "large", "turbo"
] = "base",
description_prompt: str | None = None,
extract_colors: bool = False,
include_full_histogram: bool = False,
detect_objects: bool = False,
detect_faces: bool = False,
detect_text: bool = False,
detect_shot_type: bool = False,
generate_summaries: bool = False,
) -> VideoDescription
Perform comprehensive video analysis.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
video
|
Video
|
Video object to analyze |
required |
frames_per_second
|
float
|
Frame sampling rate for visual analysis (default: 1.0 fps) |
1.0
|
transcribe
|
bool
|
Whether to generate audio transcription (default: False) |
False
|
transcription_model
|
Literal['tiny', 'base', 'small', 'medium', 'large', 'turbo']
|
Whisper model to use if transcribe=True (default: "base") |
'base'
|
description_prompt
|
str | None
|
Optional prompt to guide frame descriptions |
None
|
extract_colors
|
bool
|
Whether to extract color features from frames (default: False) |
False
|
include_full_histogram
|
bool
|
Whether to include full HSV histogram in color features (default: False) |
False
|
detect_objects
|
bool
|
Whether to detect objects in frames (default: False) |
False
|
detect_faces
|
bool
|
Whether to detect faces in frames (default: False) |
False
|
detect_text
|
bool
|
Whether to detect text (OCR) in frames (default: False) |
False
|
detect_shot_type
|
bool
|
Whether to classify shot type (cloud backends only) (default: False) |
False
|
generate_summaries
|
bool
|
Whether to generate LLM summaries for scenes (default: False) |
False
|
Returns:
| Type | Description |
|---|---|
VideoDescription
|
VideoDescription object with complete analysis |
Source code in src/videopython/ai/understanding/video.py
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 | |
analyze_scenes_only
async
Analyze video scenes without transcription (convenience method).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
video
|
Video
|
Video object to analyze |
required |
Returns:
| Type | Description |
|---|---|
list[SceneDescription]
|
List of SceneDescription objects |
Source code in src/videopython/ai/understanding/video.py
Detection Classes
ObjectDetector
ObjectDetector
Detects objects in images using YOLO (local) or vision LLMs (cloud).
Source code in src/videopython/ai/understanding/detection.py
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 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 | |
__init__
__init__(
backend: ImageToTextBackend | None = None,
model_size: str = "n",
confidence_threshold: float = 0.25,
api_key: str | None = None,
)
Initialize object detector.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
backend
|
ImageToTextBackend | None
|
Backend to use ('local' for YOLO, 'openai'/'gemini' for vision LLMs). |
None
|
model_size
|
str
|
YOLO model size for local backend ('n', 's', 'm', 'l', 'x'). |
'n'
|
confidence_threshold
|
float
|
Minimum confidence for detections (0-1). |
0.25
|
api_key
|
str | None
|
API key for cloud backends. |
None
|
Source code in src/videopython/ai/understanding/detection.py
detect
async
Detect objects in an image.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
image
|
ndarray | Image
|
Image as numpy array (H, W, 3) in RGB format or PIL Image. |
required |
Returns:
| Type | Description |
|---|---|
list[DetectedObject]
|
List of DetectedObject instances. |
Source code in src/videopython/ai/understanding/detection.py
FaceDetector
FaceDetector
Detects faces in images using OpenCV DNN.
Source code in src/videopython/ai/understanding/detection.py
__init__
Initialize face detector.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
confidence_threshold
|
float
|
Minimum confidence for detections (0-1). |
0.5
|
Source code in src/videopython/ai/understanding/detection.py
detect
async
Detect faces in an image.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
image
|
ndarray | Image
|
Image as numpy array (H, W, 3) in RGB format or PIL Image. |
required |
Returns:
| Type | Description |
|---|---|
int
|
Number of faces detected. |
Source code in src/videopython/ai/understanding/detection.py
TextDetector
TextDetector
Detects text in images using EasyOCR (local) or vision LLMs (cloud).
Source code in src/videopython/ai/understanding/detection.py
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 | |
__init__
__init__(
backend: ImageToTextBackend | None = None,
languages: list[str] | None = None,
api_key: str | None = None,
)
Initialize text detector.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
backend
|
ImageToTextBackend | None
|
Backend to use ('local' for EasyOCR, 'openai'/'gemini' for vision LLMs). |
None
|
languages
|
list[str] | None
|
List of language codes for EasyOCR (default: ['en']). |
None
|
api_key
|
str | None
|
API key for cloud backends. |
None
|
Source code in src/videopython/ai/understanding/detection.py
detect
async
Detect text in an image.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
image
|
ndarray | Image
|
Image as numpy array (H, W, 3) in RGB format or PIL Image. |
required |
Returns:
| Type | Description |
|---|---|
list[str]
|
List of detected text strings. |
Source code in src/videopython/ai/understanding/detection.py
ShotTypeClassifier
ShotTypeClassifier
Classifies shot types using vision LLMs.
Source code in src/videopython/ai/understanding/detection.py
460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 | |
__init__
Initialize shot type classifier.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
backend
|
ImageToTextBackend | None
|
Backend to use ('openai' or 'gemini'). |
None
|
api_key
|
str | None
|
API key for cloud backends. |
None
|
Source code in src/videopython/ai/understanding/detection.py
classify
async
Classify the shot type of an image.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
image
|
ndarray | Image
|
Image as numpy array (H, W, 3) in RGB format or PIL Image. |
required |
Returns:
| Type | Description |
|---|---|
str | None
|
Shot type string or None if classification failed. |
Source code in src/videopython/ai/understanding/detection.py
CameraMotionDetector
CameraMotionDetector
Detects camera motion between frames using optical flow.
Source code in src/videopython/ai/understanding/detection.py
819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 | |
__init__
Initialize camera motion detector.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
motion_threshold
|
float
|
Minimum average flow magnitude to consider as motion. |
2.0
|
zoom_threshold
|
float
|
Threshold for detecting zoom (relative change in flow magnitude from center). |
0.1
|
Source code in src/videopython/ai/understanding/detection.py
detect
async
Detect camera motion between two consecutive frames.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
frame1
|
ndarray | Image
|
First frame as numpy array or PIL Image. |
required |
frame2
|
ndarray | Image
|
Second frame as numpy array or PIL Image. |
required |
Returns:
| Type | Description |
|---|---|
str
|
Motion type: 'static', 'pan', 'tilt', 'zoom', or 'complex'. |
Source code in src/videopython/ai/understanding/detection.py
838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 | |
CombinedFrameAnalyzer
CombinedFrameAnalyzer
Analyzes frames using a single vision API call for efficiency.
For cloud backends (OpenAI/Gemini), combines object detection, OCR, face counting, and shot type classification into a single API call instead of multiple calls.
Uses structured outputs (JSON schema) to ensure valid responses.
Source code in src/videopython/ai/understanding/detection.py
594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 | |
__init__
Initialize combined frame analyzer.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
backend
|
ImageToTextBackend | None
|
Backend to use ('openai' or 'gemini'). |
None
|
api_key
|
str | None
|
API key for cloud backends. |
None
|
Source code in src/videopython/ai/understanding/detection.py
analyze
async
Analyze an image with a single API call.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
image
|
ndarray | Image
|
Image as numpy array (H, W, 3) in RGB format or PIL Image. |
required |
Returns:
| Type | Description |
|---|---|
CombinedFrameAnalysis
|
CombinedFrameAnalysis with all detection results. |
Source code in src/videopython/ai/understanding/detection.py
Scene Data Classes
These classes are used by SceneDetector and VideoAnalyzer to represent analysis results:
SceneDescription
SceneDescription
dataclass
A self-contained description of a video scene.
A scene is a continuous segment of video where the visual content remains relatively consistent, bounded by scene changes or transitions. This class combines timing information with visual analysis, transcription, and other metadata.
Attributes:
| Name | Type | Description |
|---|---|---|
start |
float
|
Scene start time in seconds |
end |
float
|
Scene end time in seconds |
start_frame |
int
|
Index of the first frame in this scene |
end_frame |
int
|
Index of the last frame in this scene (exclusive) |
frame_descriptions |
list[FrameDescription]
|
List of descriptions for frames sampled from this scene |
transcription |
Transcription | None
|
Optional transcription of speech within this scene |
summary |
str | None
|
Optional LLM-generated summary of the scene |
scene_type |
str | None
|
Optional classification (e.g., "dialogue", "action", "transition") |
detected_entities |
list[str] | None
|
Optional list of entities/objects detected in the scene |
dominant_colors |
list[tuple[int, int, int]] | None
|
Optional dominant colors aggregated across the scene |
Source code in src/videopython/base/description.py
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 | |
num_frames_described
property
Number of frames that were described in this scene.
get_frame_indices
Get evenly distributed frame indices from this scene.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
num_samples
|
int
|
Number of frames to sample from the scene |
3
|
Returns:
| Type | Description |
|---|---|
list[int]
|
List of frame indices evenly distributed throughout the scene |
Source code in src/videopython/base/description.py
get_description_summary
Get a summary of all frame descriptions concatenated.
Returns:
| Type | Description |
|---|---|
str
|
Single string with all frame descriptions joined |
Source code in src/videopython/base/description.py
get_transcription_text
Get the full transcription text for this scene.
Returns:
| Type | Description |
|---|---|
str
|
Concatenated transcription text, or empty string if no transcription |
Source code in src/videopython/base/description.py
VideoDescription
VideoDescription
dataclass
Complete understanding of a video including visual and audio analysis.
Attributes:
| Name | Type | Description |
|---|---|---|
scene_descriptions |
list[SceneDescription]
|
List of scene descriptions with frame analysis and per-scene transcription |
transcription |
Transcription | None
|
Optional full audio transcription for the entire video |
Source code in src/videopython/base/description.py
total_frames_analyzed
property
Total number of frames analyzed across all scenes.
distribute_transcription
Distribute the video-level transcription to each scene.
Slices the full transcription at word-level granularity and assigns relevant words/segments to each SceneDescription based on time overlap. Modifies scene_descriptions in place.
Source code in src/videopython/base/description.py
get_scene_summary
Get a text summary of a specific scene.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
scene_index
|
int
|
Index of the scene to summarize |
required |
Returns:
| Type | Description |
|---|---|
str
|
Text summary of the scene including timing, descriptions, and transcription |
Source code in src/videopython/base/description.py
get_full_summary
Get a complete text summary of the entire video.
Returns:
| Type | Description |
|---|---|
str
|
Multi-line string with scene summaries and optional transcription |
Source code in src/videopython/base/description.py
FrameDescription
FrameDescription
dataclass
Represents a description of a video frame.
Attributes:
| Name | Type | Description |
|---|---|---|
frame_index |
int
|
Index of the frame in the video |
timestamp |
float
|
Time in seconds when this frame appears |
description |
str
|
Text description of what's in the frame |
color_histogram |
ColorHistogram | None
|
Optional color features extracted from the frame |
detected_objects |
list[DetectedObject] | None
|
Optional list of objects detected in the frame |
detected_text |
list[str] | None
|
Optional list of text strings found via OCR |
detected_faces |
int | None
|
Optional count of faces detected in the frame |
shot_type |
str | None
|
Optional shot classification (e.g., "close-up", "medium", "wide") |
camera_motion |
str | None
|
Optional camera motion type (e.g., "static", "pan", "tilt", "zoom") |
Source code in src/videopython/base/description.py
BoundingBox
BoundingBox
dataclass
A bounding box for detected objects in an image.
Coordinates are normalized to [0, 1] range relative to image dimensions.
Attributes:
| Name | Type | Description |
|---|---|---|
x |
float
|
Left edge of the box (0 = left edge of image) |
y |
float
|
Top edge of the box (0 = top edge of image) |
width |
float
|
Width of the box |
height |
float
|
Height of the box |
Source code in src/videopython/base/description.py
DetectedObject
DetectedObject
dataclass
An object detected in a video frame.
Attributes:
| Name | Type | Description |
|---|---|---|
label |
str
|
Name/class of the detected object (e.g., "person", "car", "dog") |
confidence |
float
|
Detection confidence score between 0 and 1 |
bounding_box |
BoundingBox | None
|
Optional bounding box location of the object |