The subtitles toolkit for converting between SRT, WebVTT, and FCPXML
npm i subkit
For CLI usages, see subkit-cli.
import fs from "node:fs/promises";
import { dataToVtt, dataToFcpxml, srtToData, srtToFcpxml } from "subkit";
const srt = await fs.readFile("path/to/file.srt", "utf8");
// Convert SRT to data object
const data = srtToData(srt);
// Convert SRT data oject to any format
const vtt = dataToVtt(data);
const fcpxml = dataToFcpxml(data);
// Convert SRT to FCPXML with convertion aliases
const fcpxml_ = srtToFcpxml(srt);
console.log(fcpxml === fcpxml_);
// Output => true
This converts SRT text content to a SubSrt
data object.
This accepts a SubLike
data as input. The separator
is used for timestamp strings and it defaults to ,
.
This converts WebVTT text content to a SubVtt
data object.
This accepts a SubLike
data as input. The separator
is used for timestamp strings and it defaults to .
.
This converts FCPXML text context to a SubFcpxml
data object.
This accepts a SubLike
and fps
as input. And some fields can be configured by using DataToFcpxmlOptions
.
We've defined some convertion aliases for converting between two subs. Available convertion aliases are:
srtToVtt(text: string, separator?: Separator)
vttToSrt(text: string, separator?: Separator)
fcpxmlToSrt(text: string, separator?: Separator)
fcpxmlToVtt(text: string, separator?: Separator)
srtToFcpxml(text: string, fps: number, options?: DataToFcpxmlOptions)
vttToFcpxml(text: string, fps: number, optiosn?: DataToFcpxmlOptions)
This can be used to make a quick detection of your subtitles file.
This converts the milliseconds to time string for SRT or VTT.
This converts the SRT or VTT time string to milliseconds.
- subkit-cli - CLI for this module
MIT