> For AI agents: the complete documentation index is available at https://anyformat.swc.rs/llms.txt, the full documentation bundle is available at https://anyformat.swc.rs/llms-full.txt.

# Video

The video family identifies video formats from the leading bytes of a file.

| Language | Package                | Module                 |
| -------- | ---------------------- | ---------------------- |
| Node.js  | `@swc/anyformat-video` | `@swc/anyformat-video` |
| Python   | `anyformat-video`      | `anyformat_video`      |

## Supported formats

| Identifier | MIME type          | Format                          |
| ---------- | ------------------ | ------------------------------- |
| `mp4`      | `video/mp4`        | MPEG-4 Part 14                  |
| `mov`      | `video/quicktime`  | QuickTime File Format           |
| `3gp`      | `video/3gpp`       | 3GPP and 3GPP2 multimedia files |
| `webm`     | `video/webm`       | WebM                            |
| `mkv`      | `video/x-matroska` | Matroska                        |
| `avi`      | `video/x-msvideo`  | Audio Video Interleave          |
| `flv`      | `video/x-flv`      | Flash Video                     |
| `ts`       | `video/mp2t`       | MPEG transport stream           |
| `mpg`      | `video/mpeg`       | MPEG program stream             |

## `detect`

Identifies the video format of `data` from its leading bytes. Returns `null` in
Node.js and `None` in Python when the format is not recognized.

The first 512 bytes of a file are enough for every video format. An MPEG
transport stream needs at least two packets (377 bytes).

### Node.js

```ts
function detect(data: Uint8Array): DetectedFormat | null
```

```js
import { readFile } from 'node:fs/promises'
import { detect } from '@swc/anyformat-video'

detect(await readFile('clip.webm'))
// => { format: 'webm', mimeType: 'video/webm' }
```

### Python

```python
def detect(data: bytes) -> DetectedFormat | None
```

```python
from pathlib import Path

import anyformat_video

anyformat_video.detect(Path("clip.webm").read_bytes())
# => DetectedFormat(format='webm', mime_type='video/webm')
```

## `DetectedFormat`

A format identified by `detect`.

| Node.js    | Python      | Type     | Description                                                         |
| ---------- | ----------- | -------- | ------------------------------------------------------------------- |
| `format`   | `format`    | `string` | The stable lowercase identifier of the format, for example `"mp4"`. |
| `mimeType` | `mime_type` | `string` | The most common MIME type of the format.                            |

In Python, `DetectedFormat` is a final class with read-only properties, and the
type of each property is `str`.

## `supportedFormats`

Returns the identifier of each format that `detect` can return.

### Node.js

```ts
function supportedFormats(): string[]
```

```js
import { supportedFormats } from '@swc/anyformat-video'

supportedFormats()
// => ['mp4', 'mov', '3gp', 'webm', 'mkv', 'avi', 'flv', 'ts', 'mpg']
```

### Python

```python
def supported_formats() -> list[str]
```

```python
import anyformat_video

anyformat_video.supported_formats()
# => ['mp4', 'mov', '3gp', 'webm', 'mkv', 'avi', 'flv', 'ts', 'mpg']
```
