# `examples.test_video`

Test script for VLM video support in vllm-mlx.

[View the complete module source at #L1-L349](https://github.com/waybarrios/vllm-mlx/blob/a69d47912bcb21d8fe04d48f75fa896b620ffcfa/examples/test_video.py#L1-L349).

## 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.test_video
    options:
      members:
        - logger
        - download_sample_video
        - create_test_video
        - get_video_info
        - test_frame_extraction
        - test_video_generation
        - test_video_url
        - main
      filters: []
      show_if_no_docstring: true

## 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.

<details class="api-contract" id="contract-examples.test_video.download_sample_video" markdown="1">
<summary><code>examples.test_video.download_sample_video</code> · function</summary>

```python
examples.test_video.download_sample_video() -> str
```

Download a sample video for testing.

**Parameters**

This callable has no explicit inputs.

**Returns**

- Type: `str`
- Direct return expressions: `temp_file.name`

**Exceptions and behavior**

Function `download_sample_video` calls `logger.info`, `requests.get`, `response.raise_for_status`, `tempfile.NamedTemporaryFile`; returns `temp_file.name`.
No direct `raise` statement appears in this definition.

[View source #L27-L56](https://github.com/waybarrios/vllm-mlx/blob/a69d47912bcb21d8fe04d48f75fa896b620ffcfa/examples/test_video.py#L27-L56).

</details>

<details class="api-contract" id="contract-examples.test_video.create_test_video" markdown="1">
<summary><code>examples.test_video.create_test_video</code> · function</summary>

```python
examples.test_video.create_test_video() -> str
```

Create a simple test video using OpenCV if download fails.

**Parameters**

This callable has no explicit inputs.

**Returns**

- Type: `str`
- Direct return expressions: `temp_file.name`

**Exceptions and behavior**

Function `create_test_video` calls `logger.error`, `sys.exit`, `logger.info`, `tempfile.NamedTemporaryFile`; returns `temp_file.name`.
No direct `raise` statement appears in this definition.

[View source #L59-L105](https://github.com/waybarrios/vllm-mlx/blob/a69d47912bcb21d8fe04d48f75fa896b620ffcfa/examples/test_video.py#L59-L105).

</details>

<details class="api-contract" id="contract-examples.test_video.get_video_info" markdown="1">
<summary><code>examples.test_video.get_video_info</code> · function</summary>

```python
examples.test_video.get_video_info(video_path: str) -> dict
```

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.

[View source #L108-L126](https://github.com/waybarrios/vllm-mlx/blob/a69d47912bcb21d8fe04d48f75fa896b620ffcfa/examples/test_video.py#L108-L126).

</details>

<details class="api-contract" id="contract-examples.test_video.test_frame_extraction" markdown="1">
<summary><code>examples.test_video.test_frame_extraction</code> · function</summary>

```python
examples.test_video.test_frame_extraction(video_path: str) -> not annotated
```

Test video frame extraction.

**Parameters**

| Name | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `video_path` | `str` | `yes` | `none` | Required positional or keyword input. |

**Returns**

- Type: `not annotated`

**Exceptions and behavior**

Function `test_frame_extraction` calls `logger.info`, `get_video_info`, `time.time`, `extract_video_frames_smart`.
No direct `raise` statement appears in this definition.

[View source #L129-L145](https://github.com/waybarrios/vllm-mlx/blob/a69d47912bcb21d8fe04d48f75fa896b620ffcfa/examples/test_video.py#L129-L145).

</details>

<details class="api-contract" id="contract-examples.test_video.test_video_generation" markdown="1">
<summary><code>examples.test_video.test_video_generation</code> · function</summary>

```python
examples.test_video.test_video_generation(video_path: str, model_name: str) -> not annotated
```

Test video understanding with VLM.

**Parameters**

| Name | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `video_path` | `str` | `yes` | `none` | Required positional or keyword input. |
| `model_name` | `str` | `yes` | `none` | Required positional or keyword input. |

**Returns**

- Type: `not annotated`
- Direct return expressions: `model`

**Exceptions and behavior**

Function `test_video_generation` calls `logger.info`, `time.time`, `MLXVisionLanguageModel`, `model.load`; returns `model`.
No direct `raise` statement appears in this definition.

[View source #L148-L219](https://github.com/waybarrios/vllm-mlx/blob/a69d47912bcb21d8fe04d48f75fa896b620ffcfa/examples/test_video.py#L148-L219).

</details>

<details class="api-contract" id="contract-examples.test_video.test_video_url" markdown="1">
<summary><code>examples.test_video.test_video_url</code> · function</summary>

```python
examples.test_video.test_video_url(model, video_url: str) -> not annotated
```

Test video from URL.

**Parameters**

| Name | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `model` | `not annotated` | `yes` | `none` | Required positional or keyword input. |
| `video_url` | `str` | `yes` | `none` | Required positional or keyword input. |

**Returns**

- Type: `not annotated`
- Direct return expressions: `True`

**Exceptions and behavior**

Function `test_video_url` calls `logger.info`, `time.time`, `model.chat`, `model.generate`; returns `True`.
No direct `raise` statement appears in this definition.

[View source #L222-L266](https://github.com/waybarrios/vllm-mlx/blob/a69d47912bcb21d8fe04d48f75fa896b620ffcfa/examples/test_video.py#L222-L266).

</details>

<details class="api-contract" id="contract-examples.test_video.main" markdown="1">
<summary><code>examples.test_video.main</code> · function</summary>

```python
examples.test_video.main() -> not annotated
```

Function `main` calls `argparse.ArgumentParser`, `parser.add_argument`, `parser.parse_args`, `Path(video_path).exists`.

**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`, `Path(video_path).exists`.
No direct `raise` statement appears in this definition.

[View source #L269-L345](https://github.com/waybarrios/vllm-mlx/blob/a69d47912bcb21d8fe04d48f75fa896b620ffcfa/examples/test_video.py#L269-L345).

</details>

## 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 |
| --- | --- | --- | --- | --- |
| [`download_sample_video`](#contract-examples.test_video.download_sample_video) | function | `download_sample_video() -> str` | Download a sample video for testing. | [#L27-L56](https://github.com/waybarrios/vllm-mlx/blob/a69d47912bcb21d8fe04d48f75fa896b620ffcfa/examples/test_video.py#L27-L56) |
| [`create_test_video`](#contract-examples.test_video.create_test_video) | function | `create_test_video() -> str` | Create a simple test video using OpenCV if download fails. | [#L59-L105](https://github.com/waybarrios/vllm-mlx/blob/a69d47912bcb21d8fe04d48f75fa896b620ffcfa/examples/test_video.py#L59-L105) |
| [`get_video_info`](#contract-examples.test_video.get_video_info) | function | `get_video_info(video_path: str) -> dict` | Get information about a video file. | [#L108-L126](https://github.com/waybarrios/vllm-mlx/blob/a69d47912bcb21d8fe04d48f75fa896b620ffcfa/examples/test_video.py#L108-L126) |
| [`test_frame_extraction`](#contract-examples.test_video.test_frame_extraction) | function | `test_frame_extraction(video_path: str) -> not annotated` | Test video frame extraction. | [#L129-L145](https://github.com/waybarrios/vllm-mlx/blob/a69d47912bcb21d8fe04d48f75fa896b620ffcfa/examples/test_video.py#L129-L145) |
| [`test_video_generation`](#contract-examples.test_video.test_video_generation) | function | `test_video_generation(video_path: str, model_name: str) -> not annotated` | Test video understanding with VLM. | [#L148-L219](https://github.com/waybarrios/vllm-mlx/blob/a69d47912bcb21d8fe04d48f75fa896b620ffcfa/examples/test_video.py#L148-L219) |
| [`test_video_url`](#contract-examples.test_video.test_video_url) | function | `test_video_url(model, video_url: str) -> not annotated` | Test video from URL. | [#L222-L266](https://github.com/waybarrios/vllm-mlx/blob/a69d47912bcb21d8fe04d48f75fa896b620ffcfa/examples/test_video.py#L222-L266) |
| [`main`](#contract-examples.test_video.main) | function | `main() -> not annotated` | Function `main` calls `argparse.ArgumentParser`, `parser.add_argument`, `parser.parse_args`, `Path(video_path).exists`. | [#L269-L345](https://github.com/waybarrios/vllm-mlx/blob/a69d47912bcb21d8fe04d48f75fa896b620ffcfa/examples/test_video.py#L269-L345) |
