Transformers.js documentation
utils/video
Get started
Tutorials
Building a Vanilla JS ApplicationBuilding a React ApplicationBuilding a Next.js ApplicationBuilding a Browser ExtensionBuilding an Electron ApplicationServer-side Inference in Node.jsBuilding a Next.js AI Chatbot with Vercel AI SDK
Developer Guides
Running models on WebGPUUsing quantized models (dtypes)Accessing Private/Gated ModelsServer-side Audio Processing
Integrations
API Reference
You are viewing main version, which requires installation from source. If you'd like
regular npm install, checkout the latest stable version (v3.8.1).
utils/video
Browser video loading helpers.
load_video() samples frames from a video source into RawImage frames so
vision-language models can consume short clips. Video decoding currently
relies on browser media APIs.
Classes
RawVideoFrame
A decoded video frame and its timestamp, in seconds.
RawVideoFrame.constructor(image, timestamp)
Create a video frame.
Parameters
image(RawImage) — The decoded image for this frame.timestamp(number) — The frame timestamp, in seconds.
RawVideo
A sampled video represented as decoded frames plus total duration.
RawVideo.constructor(frames, duration)
Create a video from decoded frames.
Parameters
frames(RawVideoFrame[] |RawImage[]) — Frames with timestamps, or images to space uniformly acrossduration.duration(number) — Duration in seconds.
RawVideo.width : number
Width of the video frames, in pixels.
RawVideo.height : number
Height of the video frames, in pixels.
RawVideo.fps : number
Effective sampled frame rate.
Functions
load_video(src, [options])
Load and sample frames from a video.
Parameters
src(string|Blob|HTMLVideoElement) — The video to process.options(Object) optional — Optional parameters.num_frames(number) optional — defaults tonull— The number of frames to sample uniformly.fps(number) optional — defaults tonull— The number of frames to sample per second.
Returns: Promise<RawVideo> — The loaded video.