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, and this page is available as Markdown at https://anyformat.swc.rs/api/video.md.

Video

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

LanguagePackageModule
Node.js@swc/anyformat-video@swc/anyformat-video
Pythonanyformat-videoanyformat_video

Supported formats

IdentifierMIME typeFormat
mp4video/mp4MPEG-4 Part 14
movvideo/quicktimeQuickTime File Format
3gpvideo/3gpp3GPP and 3GPP2 multimedia files
webmvideo/webmWebM
mkvvideo/x-matroskaMatroska
avivideo/x-msvideoAudio Video Interleave
flvvideo/x-flvFlash Video
tsvideo/mp2tMPEG transport stream
mpgvideo/mpegMPEG 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

function detect(data: Uint8Array): DetectedFormat | null
import { readFile } from 'node:fs/promises'
import { detect } from '@swc/anyformat-video'

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

Python

def detect(data: bytes) -> DetectedFormat | None
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.jsPythonTypeDescription
formatformatstringThe stable lowercase identifier of the format, for example "mp4".
mimeTypemime_typestringThe 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

function supportedFormats(): string[]
import { supportedFormats } from '@swc/anyformat-video'

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

Python

def supported_formats() -> list[str]
import anyformat_video

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