Skip to main content
Subtitle sources are used to add subtitle data to output subtitle tracks. All subtitle sources extend the base SubtitleSource class.

TextSubtitleSource

Parses subtitle text from a subtitle file format and adds the cues to the output subtitle track.

Constructor

SubtitleCodec
required
The subtitle format/codec used in the text being added. Supported values:
  • 'srt' - SubRip subtitle format
  • 'webvtt' - WebVTT subtitle format
  • 'ass' - Advanced SubStation Alpha format

Methods

add

Parses subtitle text according to the specified codec and adds it to the output track. You don’t have to add the entire subtitle file at once - you can provide it in chunks.
string
required
The subtitle text to parse and add. Can be the entire subtitle file content or a chunk of it.
Promise<void>
Resolves when the output is ready to receive more samples. Await this to respect backpressure.
Example:

close

Closes the source, preventing future subtitle cues from being added and signaling that no more data will be added to this track.
Calling close() is optional but recommended after adding the last subtitle chunk for improved performance and reduced memory usage.

Subtitle formats

SubRip (.srt)

The SubRip format is a simple, widely-supported subtitle format. Each subtitle consists of:
  1. A sequential number
  2. Timing information (start —> end)
  3. The subtitle text
  4. A blank line

WebVTT (.vtt)

WebVTT (Web Video Text Tracks) is the native subtitle format for HTML5 video. It supports styling and positioning.

Advanced SubStation Alpha (.ass)

ASS is an advanced subtitle format that supports complex styling, positioning, and animations. It’s commonly used for anime and fan subtitles.