Skip to content

Class: Video

@providerprotocol/ai


@providerprotocol/ai / @providerprotocol/ai / Video

Defined in: src/core/media/Video.ts:79

Represents a video file that can be used in UPP messages.

Video can be created from various sources (files, bytes, base64) and converted to different formats as needed by providers. The class provides a unified interface regardless of the underlying source type.

Note: Providers have size limits for inline video data. Google Gemini limits inline data to 20MB per request. For larger files, consider using provider-specific file upload APIs.

// Load from file
const fileVideo = await Video.fromPath('./clip.mp4');
// From raw bytes
const bytesVideo = Video.fromBytes(uint8Array, 'video/webm');
// Use in a message
const message = new UserMessage([video.toBlock()]);

readonly data: Uint8Array

Defined in: src/core/media/Video.ts:81

The video data as raw bytes


readonly optional duration: number

Defined in: src/core/media/Video.ts:85

Duration in seconds, if known


readonly optional height: number

Defined in: src/core/media/Video.ts:89

Video height in pixels, if known


readonly mimeType: string

Defined in: src/core/media/Video.ts:83

MIME type of the video (e.g., ‘video/mp4’, ‘video/webm’)


readonly optional width: number

Defined in: src/core/media/Video.ts:87

Video width in pixels, if known

get size(): number

Defined in: src/core/media/Video.ts:106

Gets the size of the video data in bytes.

number

toBase64(): string

Defined in: src/core/media/Video.ts:115

Converts the video to a base64-encoded string.

string

The video data as a base64 string


toBlock(): VideoBlock

Defined in: src/core/media/Video.ts:147

Converts this Video to a VideoBlock for use in UPP messages.

VideoBlock

A VideoBlock that can be included in message content arrays


toBytes(): Uint8Array

Defined in: src/core/media/Video.ts:138

Gets the video data as raw bytes.

Uint8Array

The video data as a Uint8Array


toDataUrl(): string

Defined in: src/core/media/Video.ts:128

Converts the video to a data URL suitable for embedding.

string

A data URL in the format data:{mimeType};base64,{data}


static fromBase64(base64, mimeType, options?): Video

Defined in: src/core/media/Video.ts:240

Creates a Video from a base64-encoded string.

string

The base64-encoded video data (without data URL prefix)

string

The MIME type of the video

Optional metadata (duration, width, height)

number

number

number

Video

A Video containing the decoded data

const video = Video.fromBase64(base64String, 'video/mp4');

static fromBlock(block): Video

Defined in: src/core/media/Video.ts:262

Creates a Video from an existing VideoBlock.

Useful for converting content blocks received from providers back into Video instances for further processing.

VideoBlock

A VideoBlock from message content

Video

A Video with the block’s data and metadata


static fromBytes(data, mimeType, options?): Video

Defined in: src/core/media/Video.ts:219

Creates a Video from raw byte data.

Uint8Array

The video data as a Uint8Array

string

The MIME type of the video

Optional metadata (duration, width, height)

number

number

number

Video

A Video containing the byte data

const video = Video.fromBytes(mp4Data, 'video/mp4');
const videoWithMeta = Video.fromBytes(data, 'video/mp4', { duration: 60 });

static fromPath(path, options?): Promise<Video>

Defined in: src/core/media/Video.ts:174

Creates a Video by reading a file from disk.

The file is read into memory as bytes. MIME type is automatically detected from the file extension.

string

Path to the video file

Optional metadata (duration, width, height)

number

number

number

Promise<Video>

Promise resolving to a Video with the file contents

const video = await Video.fromPath('./clips/demo.mp4');
const videoWithMeta = await Video.fromPath('./clip.mp4', { duration: 30, width: 1920, height: 1080 });