parseVtt()v4.0.537
Parses the contents of a WebVTT file (.vtt) and returns an array of Caption items.
Example usageimport {parseVtt } from '@remotion/captions'; constinput = `WEBVTT 00:00:00.000 --> 00:00:02.500 Welcome to the Example WebVTT File! 00:00:03.000 --> 00:00:06.000 This is a demonstration of WebVTT subtitles. `.trim (); const {captions } =parseVtt ({input }); /* captions = [ { confidence: 1, endMs: 2500, startMs: 0, text: 'Welcome to the Example WebVTT File!', timestampMs: 1250, }, { confidence: 1, endMs: 6000, startMs: 3000, text: 'This is a demonstration of WebVTT subtitles.', timestampMs: 4500, }, ] */
API
input
The contents of a .vtt file as a string.
Return value
An object with the following properties:
captions
An array of Caption items.
Behavior
- The
WEBVTTheader is optional and ignored, including any trailing text on the header line. - A cue may be preceded by an optional identifier on its own line.
- Timestamps accept both
HH:MM:SS.mmmand the shorterMM:SS.mmmform, and a comma may be used as the millisecond separator. - Cue settings after the timestamps (such as
align:start position:10%) are ignored. NOTE,STYLEandREGIONblocks are skipped.- Multi-line cue text is joined with
\n.
Compatibility
| Browsers | Servers | Environments | |||||||
|---|---|---|---|---|---|---|---|---|---|
Chrome | Firefox | Safari | Node.js | Bun | Serverless Functions | ||||