subtitles-converter
v0.2.0
Published
Subtitle converter and toolkit for JavaScript, TypeScript and the command line. Convert SRT to VTT, VTT to SRT, ASS to SRT, SBV, SUB, TTML/DFXP, SAMI, LRC, CSV, SCC and EBU-STL; sync and shift timing, fix frame rate, remove SDH/hearing-impaired text, stri
Maintainers
Readme
Subtitle Converter: SRT, VTT, ASS and more (JavaScript, TypeScript and CLI)
A free, open-source subtitle converter and subtitle toolkit. Use it from the command line or as a library.
- Convert SRT to VTT, VTT to SRT, ASS/SSA to SRT, SBV to SRT, SUB to SRT, TTML/DFXP to SRT, SAMI to SRT, SCC to SRT and EBU-STL to SRT. It also writes SRT to TXT, SRT to CSV, SRT to LRC and SRT to JSON.
- Sync subtitles that are out of sync. Shift the timing, convert the frame rate (23.976 to 25 fps), or fix drift with two-point sync.
- Clean subtitles. Remove SDH and hearing-impaired text such as
[door slams],(laughs),JOHN:and♪, and strip<i>and{\an8}tags. - Fix broken SRT files. It sorts cues, removes duplicate and empty cues, fixes overlaps and renumbers the file.
- Check subtitle quality: line length, characters per second (CPS), duration and overlaps. It also gives word count and WPM.
- Merge two SRT files, split an SRT file into parts, and make dual subtitles: two languages in one file, for language learning.
- Text to SRT: turn a script or transcript into a timed subtitle file.
It has zero runtime dependencies. It runs in Node, the browser, Deno, Bun and edge runtimes, and it never uploads your files.
Don't want to install anything? Every tool also runs free in your browser at aivently.com/tools.
Contents
- Supported subtitle formats
- Command line (CLI)
- JavaScript / TypeScript API
- Recipes
- FAQ
- Free online subtitle tools
Supported subtitle formats
| Format | Extension | Read | Write |
| --- | --- | :---: | :---: |
| SubRip | .srt | yes | yes |
| WebVTT | .vtt | yes | yes |
| Advanced SubStation Alpha / SSA | .ass, .ssa | yes | yes |
| YouTube SBV | .sbv | yes | as original |
| MicroDVD | .sub | yes | as original |
| TTML / DFXP (Netflix, Amazon) | .ttml, .dfxp | yes | as original |
| SAMI | .smi, .sami | yes | as original |
| LRC lyrics | .lrc | yes | yes |
| MPL2 | .txt | yes | as original |
| TMPlayer | .txt | yes | as original |
| CSV (Start,End,Text) | .csv | yes | yes |
| Scenarist SCC (broadcast captions) | .scc | convertScc | — |
| EBU-STL | .stl | convertEbuStl | — |
| Plain text | .txt | from text | yes |
| JSON | .json | — | yes |
The format is detected from the content, so a file with the wrong extension still works.
Command line (CLI)
npx subtitles-converter convert movie.srt --to vtt -o movie.vttOr install it globally:
npm install -g subtitles-converter| Task | Command |
| --- | --- |
| SRT to VTT | subtitles-converter convert movie.srt --to vtt -o movie.vtt |
| VTT to SRT | subtitles-converter convert movie.vtt --to srt -o movie.srt |
| ASS to SRT | subtitles-converter convert movie.ass --to srt -o movie.srt |
| Batch convert a folder | subtitles-converter convert *.vtt --to srt |
| SRT to TXT (dialogue only) | subtitles-converter text movie.srt -o movie.txt |
| SRT to CSV / Excel | subtitles-converter convert movie.srt --to csv -o movie.csv |
| SRT to LRC | subtitles-converter convert song.srt --to lrc -o song.lrc |
| Subtitles 2.5 s too late | subtitles-converter shift movie.srt --by -2.5s -o synced.srt |
| 23.976 fps to 25 fps | subtitles-converter shift movie.srt --fps 23.976:25 -o 25fps.srt |
| Fix drifting subtitles | subtitles-converter sync movie.srt --point 00:01:00=00:01:02 --point 01:30:00=01:30:05 |
| Remove SDH / hearing impaired | subtitles-converter clean movie.srt --sdh -o clean.srt |
| Remove <i> and {\an8} tags | subtitles-converter clean movie.srt --tags -o clean.srt |
| Fix a broken SRT file | subtitles-converter fix broken.srt -o fixed.srt |
| Check subtitle quality (CI) | subtitles-converter check movie.srt (exit code 1 on problems) |
| Word count, WPM, CPS | subtitles-converter stats movie.srt |
| Merge two SRT files | subtitles-converter merge part1.srt part2.srt -o full.srt |
| Split an SRT file | subtitles-converter split movie.srt --at 00:45:00 |
| Dual (bilingual) subtitles | subtitles-converter dual english.srt spanish.srt -o dual.srt |
| Text / script to SRT | subtitles-converter from-text script.txt -o script.srt |
Times can be written as 90, 1.5s, -250ms, 01:02:03,500 or 1:02:03.5.
Run subtitles-converter --help to see every option.
JavaScript / TypeScript API
npm install subtitles-converterimport {
loadSubtitleText,
convertSubtitle,
shiftSubtitle,
syncSubtitle,
removeHearingImpaired,
stripFormatting,
fixSubtitle,
checkSubtitle,
subtitleStats,
mergeSubtitles,
splitSubtitle,
dualSubtitles,
textToSubtitle,
subtitleToText,
subtitleToCsv,
subtitleToLrc,
} from "subtitles-converter";
const { document } = loadSubtitleText(srtText, "episode.srt"); // detects the format
convertSubtitle(document, "vtt"); // SRT → WebVTT
convertSubtitle(document, "ass"); // SRT → ASS
subtitleToText(document, { timestamps: false, joinLines: true }); // SRT → plain text
subtitleToCsv(document); // SRT → CSV
subtitleToLrc(document); // SRT → LRC
// Out-of-sync subtitles: 2.5 s late, and 23.976 fps timing played at 25 fps
shiftSubtitle(document, { offsetMs: -2500, fromFps: 23.976, toFps: 25 });
// Subtitles that drift: give the right time for two lines
syncSubtitle(document, { fromMs: 60_000, toMs: 62_000 }, { fromMs: 5_400_000, toMs: 5_405_000 });
// Remove [sound effects], (laughs), SPEAKER: labels and ♪ music lines
removeHearingImpaired(stripFormatting(document));
// Sort, dedupe, fix overlaps, extend cues that flash by
const { document: fixed, changes } = fixSubtitle(document, { minGapMs: 80 });
checkSubtitle(document); // { cueCount, durationMs, findings: [{ code: "reading_speed", ordinals: [12] }] }
subtitleStats(document); // { words, wordsPerMinute, averageCharactersPerSecond, longestLine, ... }
mergeSubtitles(part1, part2, { mode: "append", gapMs: 0 });
splitSubtitle(document, { atMs: [45 * 60_000] }); // or { parts: 2 }
dualSubtitles(englishDocument, spanishDocument); // two-line bilingual SRT
textToSubtitle("Hello there. This line comes next.", { charactersPerSecond: 15 });Lower-level API
import { detectSubtitleFormat, parseSubtitle, renderSubtitleExport } from "subtitles-converter";
const detection = detectSubtitleFormat({ filename: "movie.ass", content });
// → { format: "ass", status: "supported" | "mismatch" | "gated" | "unsupported", declaredFormat }
const document = parseSubtitle(content, { id: "movie", format: "ass" });
const result = renderSubtitleExport(document, {
format: "original", // or "srt" | "vtt" | "ass" | "txt" | "json"
constraints: { maxCharsPerLine: 42, maxLinesPerCue: 2, maxReadingSpeed: 17 },
});
// → { content, format, warnings, fallbackFormats? }Format details are kept where the target format can carry them:
- ASS styles, event fields and override tags;
- WebVTT headers,
NOTE/STYLE/REGIONblocks, cue identifiers and settings; - the original SRT cue numbers.
When a round trip would lose information, renderSubtitleExport returns
content: null together with a warning, so nothing is dropped silently.
Edit helpers (applyEditOperation, and createEditingSession with undo and
redo) support cue updates, splits, merges, timing nudges, and find and
replace. You can use them to build a subtitle editor.
Safety limits
The parsers enforce these limits:
- 50,000 source lines;
- 64 KiB per line;
- 10,000 cues;
- bounded tag and override counts.
They reject DOCTYPE and ENTITY in XML formats. Malformed input throws an
Error with a stable snake_case code, such as subtitle_timing_invalid.
Recipes
Convert SRT to VTT for HTML5 video
The <track> element needs WebVTT, not SRT.
npx subtitles-converter convert captions.srt --to vtt -o captions.vtt<video controls src="movie.mp4">
<track kind="subtitles" src="captions.vtt" srclang="en" label="English" default />
</video>Fix subtitles that are out of sync
- If every line is late or early by the same amount, use
shift --by <time>. - If the subtitles start in sync and then drift, the frame rate is wrong.
Try
shift --fps 23.976:25, or--fps 25:23.976. - If the drift is uneven, use
syncwith two lines you know the correct time for, one near the start and one near the end.
Remove hearing-impaired (SDH) subtitles
npx subtitles-converter clean movie.en.sdh.srt --sdh -o movie.en.srtThis removes [sound descriptions], (actions), upper-case speaker labels
and ♪ music lines. Cues that become empty are dropped.
Lint subtitles in CI
- run: npx subtitles-converter check subtitles/en.srtThe command exits with code 1 when lines are too long (more than 42 characters), a cue has more than 2 lines, the reading speed is more than 17 CPS, or cues overlap.
FAQ
How do I convert SRT to VTT?
Run npx subtitles-converter convert file.srt --to vtt -o file.vtt. Or use
convertSubtitle(document, "vtt") in code. WebVTT adds a WEBVTT header and
uses . instead of , before the milliseconds.
How do I convert VTT to SRT?
Run npx subtitles-converter convert file.vtt --to srt -o file.srt. Cue
settings such as align:start are not part of SRT, so they are dropped.
Can I convert ASS or SSA to SRT?
Yes. The dialogue and timing are kept. Styling such as fonts and positions
cannot be written to SRT. Run clean --tags to remove leftover {\...}
overrides.
How do I remove timestamps from an SRT file?
Run subtitles-converter text file.srt to get only the dialogue. Add
--join to get one paragraph.
How do I make bilingual (dual-language) subtitles?
Run subtitles-converter dual english.srt other.srt. Each cue shows the
primary line with the translation below it.
Does it upload my subtitles anywhere? No. Everything runs locally and there are no network calls.
Can it translate subtitles? This library does not translate. For AI subtitle translation that keeps the timing, see Aivently.
Free online subtitle tools
These are built on this library. They run in your browser, and your file is never uploaded.
- Subtitle converter: SRT, VTT, ASS, SUB, SBV, TTML…
- SRT to text
- Subtitle sync / time shifter
- SRT checker
- SRT merger
- Dual subtitles maker
- Sample SRT, VTT and ASS files
Development
npm install
npm test
npm run buildAll test fixtures are synthetic. Contributions are welcome: open an issue or a pull request.
License
MIT © Aivently
