examples.video_benchmark¶
Video Benchmark Script for vllm-mlx Tests Vision-Language Models with video at different configurations (FPS, frame count, resolution) and measures performance metrics.
View the complete module source at #L1-L563.
API details¶
Each callable below includes its exact signature, type annotations, inputs, defaults, return contract, documented exceptions, implementation source, and parsed docstring sections when the source provides them.
examples.video_benchmark
¶
Video Benchmark Script for vllm-mlx
Tests Vision-Language Models with video at different configurations (FPS, frame count, resolution) and measures performance metrics.
Usage
Direct API benchmark (no server needed):¶
python examples/video_benchmark.py --model mlx-community/Qwen3-VL-4B-Instruct-3bit
With video URL:¶
python examples/video_benchmark.py --video-url https://example.com/video.mp4
Quick test:¶
python examples/video_benchmark.py --quick
examples.video_benchmark.SAMPLE_VIDEOS
module-attribute
¶
SAMPLE_VIDEOS = {'480x270_30s': {'url': 'https://file-examples.com/storage/feb05093c66764aa00cbc58/2017/04/file_example_MP4_480_1_5MG.mp4', 'description': 'Sample video 480x270 (30s)', 'resolution': '480x270', 'duration': 30}, '640x360_30s': {'url': 'https://file-examples.com/storage/feb05093c66764aa00cbc58/2017/04/file_example_MP4_640_3MG.mp4', 'description': 'Sample video 640x360 (30s)', 'resolution': '640x360', 'duration': 30}, '1280x720_30s': {'url': 'https://file-examples.com/storage/feb05093c66764aa00cbc58/2017/04/file_example_MP4_1280_10MG.mp4', 'description': 'Sample video 1280x720 HD (30s)', 'resolution': '1280x720', 'duration': 30}, 'bunny_240p': {'url': 'https://docs.evostream.com/sample_content/assets/bunny.mp4', 'description': 'Big Buck Bunny 240p', 'resolution': '424x240', 'duration': 60}, 'sintel_720p': {'url': 'https://docs.evostream.com/sample_content/assets/sintel1m720p.mp4', 'description': 'Sintel Trailer 720p', 'resolution': '1280x720', 'duration': 60}, 'big_buck_bunny_10s': {'url': 'https://test-videos.co.uk/vids/bigbuckbunny/mp4/h264/360/Big_Buck_Bunny_360_10s_1MB.mp4', 'description': 'Big Buck Bunny (10s, 360p)', 'resolution': '640x360', 'duration': 10}}
examples.video_benchmark.VideoBenchmarkResult
dataclass
¶
VideoBenchmarkResult(config_name: str, fps: float, max_frames: int, frames_extracted: int, video_duration: float, time_seconds: float, prompt_tokens: int, completion_tokens: int, tokens_per_second: float, response_preview: str)
Result from a single video benchmark run.
examples.video_benchmark.VideoBenchmarkResult.frames_extracted
instance-attribute
¶
examples.video_benchmark.VideoBenchmarkResult.video_duration
instance-attribute
¶
examples.video_benchmark.VideoBenchmarkResult.completion_tokens
instance-attribute
¶
examples.video_benchmark.VideoBenchmarkResult.tokens_per_second
instance-attribute
¶
examples.video_benchmark.VideoBenchmarkResult.response_preview
instance-attribute
¶
examples.video_benchmark.create_test_video
¶
create_test_video(duration: float = 5.0, fps: float = 30.0, width: int = 640, height: int = 480) -> str
Create a synthetic test video with colored frames and text.
Parameters:
-
duration(float, default:5.0) –Video duration in seconds
-
fps(float, default:30.0) –Frames per second
-
width(int, default:640) –Video width
-
height(int, default:480) –Video height
Returns:
-
str–Path to created video file
Source code in examples/video_benchmark.py
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 | |
examples.video_benchmark.download_video
¶
Download video from URL.
Source code in examples/video_benchmark.py
examples.video_benchmark.get_video_info
¶
Get information about a video file.
Source code in examples/video_benchmark.py
examples.video_benchmark.run_video_benchmark
¶
run_video_benchmark(model, video_path: str, fps: float, max_frames: int, config_name: str, warmup: bool = False) -> VideoBenchmarkResult
Run a single video benchmark configuration.
Source code in examples/video_benchmark.py
examples.video_benchmark.run_benchmark
¶
run_benchmark(model_name: str, video_path: str = None, video_url: str = None, video_duration: float = 10.0, warmup_runs: int = 1, quick: bool = False) -> list[VideoBenchmarkResult]
Run full video benchmark across multiple configurations.
Parameters:
-
model_name(str) –VLM model to use
-
video_path(str, default:None) –Local video file path
-
video_url(str, default:None) –URL to download video from
-
video_duration(float, default:10.0) –Duration for synthetic video
-
warmup_runs(int, default:1) –Number of warmup runs
-
quick(bool, default:False) –Run quick benchmark with fewer configs
Returns:
-
list[VideoBenchmarkResult]–List of VideoBenchmarkResult objects
Source code in examples/video_benchmark.py
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 | |
examples.video_benchmark.print_results
¶
print_results(results: list[VideoBenchmarkResult])
Print benchmark results in a nice table.
Source code in examples/video_benchmark.py
examples.video_benchmark.save_results
¶
save_results(results: list[VideoBenchmarkResult], output_path: str, model_name: str)
Save benchmark results to JSON file.
Source code in examples/video_benchmark.py
examples.video_benchmark.main
¶
Source code in examples/video_benchmark.py
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 | |
Complete contract reference¶
Expand any definition for its exact inputs, annotations, defaults, return contract, directly raised exceptions, source-grounded behavior, and immutable line link. This section includes private and nested definitions that ordinary API generators omit.
examples.video_benchmark.VideoBenchmarkResult · class
examples.video_benchmark.VideoBenchmarkResult(config_name: str, fps: float, max_frames: int, frames_extracted: int, video_duration: float, time_seconds: float, prompt_tokens: int, completion_tokens: int, tokens_per_second: float, response_preview: str)
Result from a single video benchmark run.
Parameters
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
config_name |
str |
yes |
none |
Required constructor field. |
fps |
float |
yes |
none |
Required constructor field. |
max_frames |
int |
yes |
none |
Required constructor field. |
frames_extracted |
int |
yes |
none |
Required constructor field. |
video_duration |
float |
yes |
none |
Required constructor field. |
time_seconds |
float |
yes |
none |
Required constructor field. |
prompt_tokens |
int |
yes |
none |
Required constructor field. |
completion_tokens |
int |
yes |
none |
Required constructor field. |
tokens_per_second |
float |
yes |
none |
Required constructor field. |
response_preview |
str |
yes |
none |
Required constructor field. |
Returns
- Constructs:
examples.video_benchmark.VideoBenchmarkResult
Exceptions and behavior
Class VideoBenchmarkResult declares 0 direct member(s).
No direct raise statement appears in this definition.
examples.video_benchmark.create_test_video · function
examples.video_benchmark.create_test_video(duration: float = 5.0, fps: float = 30.0, width: int = 640, height: int = 480) -> str
Create a synthetic test video with colored frames and text.
Parameters
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
duration |
float |
no |
5.0 |
Video duration in seconds |
fps |
float |
no |
30.0 |
Frames per second |
width |
int |
no |
640 |
Video width |
height |
int |
no |
480 |
Video height |
Returns
- Type:
str - Direct return expressions:
temp_file.name
Exceptions and behavior
Function create_test_video calls tempfile.NamedTemporaryFile, temp_file.close, cv2.VideoWriter_fourcc, cv2.VideoWriter; returns temp_file.name.
No direct raise statement appears in this definition.
examples.video_benchmark.download_video · function
Download video from URL.
Parameters
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
url |
str |
yes |
none |
Required positional or keyword input. |
timeout |
int |
no |
120 |
Optional positional or keyword input; defaults to 120. |
Returns
- Type:
str - Direct return expressions:
temp_file.name
Exceptions and behavior
Function download_video calls logger.info, requests.get, response.raise_for_status, tempfile.NamedTemporaryFile; returns temp_file.name.
No direct raise statement appears in this definition.
examples.video_benchmark.get_video_info · function
Get information about a video file.
Parameters
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
video_path |
str |
yes |
none |
Required positional or keyword input. |
Returns
- Type:
dict - Direct return expressions:
{'error': 'Cannot open video'};info
Exceptions and behavior
Function get_video_info calls cv2.VideoCapture, cap.isOpened, int, cap.get; has 2 explicit return paths.
No direct raise statement appears in this definition.
examples.video_benchmark.run_video_benchmark · function
examples.video_benchmark.run_video_benchmark(model, video_path: str, fps: float, max_frames: int, config_name: str, warmup: bool = False) -> VideoBenchmarkResult
Run a single video benchmark configuration.
Parameters
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
model |
not annotated |
yes |
none |
Required positional or keyword input. |
video_path |
str |
yes |
none |
Required positional or keyword input. |
fps |
float |
yes |
none |
Required positional or keyword input. |
max_frames |
int |
yes |
none |
Required positional or keyword input. |
config_name |
str |
yes |
none |
Required positional or keyword input. |
warmup |
bool |
no |
False |
Optional positional or keyword input; defaults to False. |
Returns
- Type:
VideoBenchmarkResult - Direct return expressions:
VideoBenchmarkResult(config_name=config_name, fps=fps, max_frames=max_frames, frames_extracted=frames_extracted, video_…
Exceptions and behavior
Function run_video_benchmark calls get_video_info, print, time.perf_counter, model.generate; returns VideoBenchmarkResult(config_name=config_name, fps=fps, max_frames=max_frames, frames_extracted=frames_extracted, video_….
No direct raise statement appears in this definition.
examples.video_benchmark.run_benchmark · function
examples.video_benchmark.run_benchmark(model_name: str, video_path: str = None, video_url: str = None, video_duration: float = 10.0, warmup_runs: int = 1, quick: bool = False) -> list[VideoBenchmarkResult]
Run full video benchmark across multiple configurations.
Parameters
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
model_name |
str |
yes |
none |
VLM model to use |
video_path |
str |
no |
None |
Local video file path |
video_url |
str |
no |
None |
URL to download video from |
video_duration |
float |
no |
10.0 |
Duration for synthetic video |
warmup_runs |
int |
no |
1 |
Number of warmup runs |
quick |
bool |
no |
False |
Run quick benchmark with fewer configs |
Returns
- Type:
list[VideoBenchmarkResult] - Direct return expressions:
results
Exceptions and behavior
Function run_benchmark calls print, time.time, MLXVisionLanguageModel, model.load; returns results.
No direct raise statement appears in this definition.
examples.video_benchmark.print_results · function
Print benchmark results in a nice table.
Parameters
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
results |
list[VideoBenchmarkResult] |
yes |
none |
Required positional or keyword input. |
Returns
- Type:
not annotated - Direct return expressions:
None
Exceptions and behavior
Function print_results calls print, sorted, table_data.append, tabulate; returns None.
No direct raise statement appears in this definition.
examples.video_benchmark.save_results · function
examples.video_benchmark.save_results(results: list[VideoBenchmarkResult], output_path: str, model_name: str) -> not annotated
Save benchmark results to JSON file.
Parameters
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
results |
list[VideoBenchmarkResult] |
yes |
none |
Required positional or keyword input. |
output_path |
str |
yes |
none |
Required positional or keyword input. |
model_name |
str |
yes |
none |
Required positional or keyword input. |
Returns
- Type:
not annotated
Exceptions and behavior
Function save_results calls time.strftime, open, json.dump, print.
No direct raise statement appears in this definition.
examples.video_benchmark.main · function
Function main calls argparse.ArgumentParser, parser.add_argument, parser.parse_args, run_benchmark.
Parameters
This callable has no explicit inputs.
Returns
- Type:
not annotated
Exceptions and behavior
Function main calls argparse.ArgumentParser, parser.add_argument, parser.parse_args, run_benchmark.
No direct raise statement appears in this definition.
Complete symbol map¶
This map also includes private definitions and nested helpers. The signature column exposes every explicit input even when an internal helper has no dedicated parameter prose.
| Symbol | Kind | Signature and inputs | What it does | Source |
|---|---|---|---|---|
VideoBenchmarkResult |
class | VideoBenchmarkResult(config_name: str, fps: float, max_frames: int, frames_extracted: int, video_duration: float, time_seconds: float, prompt_tokens: int, completion_tokens: int, tokens_per_second: float, response_preview: str) |
Result from a single video benchmark run. | #L80-L91 |
create_test_video |
function | create_test_video(duration: float = 5.0, fps: float = 30.0, width: int = 640, height: int = 480) -> str |
Create a synthetic test video with colored frames and text. | #L94-L175 |
download_video |
function | download_video(url: str, timeout: int = 120) -> str |
Download video from URL. | #L178-L198 |
get_video_info |
function | get_video_info(video_path: str) -> dict |
Get information about a video file. | #L201-L217 |
run_video_benchmark |
function | run_video_benchmark(model, video_path: str, fps: float, max_frames: int, config_name: str, warmup: bool = False) -> VideoBenchmarkResult |
Run a single video benchmark configuration. | #L220-L271 |
run_benchmark |
function | run_benchmark(model_name: str, video_path: str = None, video_url: str = None, video_duration: float = 10.0, warmup_runs: int = 1, quick: bool = False) -> list[VideoBenchmarkResult] |
Run full video benchmark across multiple configurations. | #L274-L374 |
print_results |
function | print_results(results: list[VideoBenchmarkResult]) -> not annotated |
Print benchmark results in a nice table. | #L377-L445 |
save_results |
function | save_results(results: list[VideoBenchmarkResult], output_path: str, model_name: str) -> not annotated |
Save benchmark results to JSON file. | #L448-L474 |
main |
function | main() -> not annotated |
Function main calls argparse.ArgumentParser, parser.add_argument, parser.parse_args, run_benchmark. |
#L477-L559 |