npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

subtitle-converter

v3.0.12

Published

Convert subtitles from one format to another

Readme

subtitle-converter

Convert and modify subtitle files with NodeJS.

There are many subtitle tools written in node, but there are none that support all popular subtitle and caption formats. subtitle-converter builds off of the work of others (most notably node-captions, node-webvtt, and subtitles-parser) in order to ultimately become the only subtitle module necessary to include in your node project.

Currently supported input file types: dfxp, scc, srt, ttml, vtt, ssa, ass

Currently supported output file types: srt, vtt

All output files are encoded with UTF-8. In the future we may support more encoding types.

Install

npm install subtitle-converter

Convert

NodeJS:

const fs = require('fs')
const { convert } = require('subtitle-converter');

const filepath = '/Users/test/Downloads/english_subtitle.srt';
const subtitleText = fs.readFileSync(filepath, 'utf-8');
const outputExtension = '.vtt'; // conversion is based on output file extension
const options = {
  removeTextFormatting: true,
};

const { subtitle, status } = convert(subtitleText, outputExtension, options)

if (status.success) console.log(subtitle);
else console.log(status);

Browser:

const { convert } = require('subtitle-converter');

function convertFile(fileObject) {
  const reader = new FileReader();
  let converted = '';
  reader.readAsText(fileObject);
  reader.onload = () => {
    const text = reader.result;
    const { subtitle, status } = convert(text, '.vtt');
    if(status.success) converted = subtitle;
    else console.log(status);
  };
  return converted;
}

Options

startAtZeroHour (boolean) - Pass in true to make sure the timecodes start within

shiftTimecode (number) - Pass in the amount of seconds to shift the timecode. If undefined the output timecode will match the input.

  • For example: 5, -5, 5.2

sourceFps (number) - Pass in the FPS of the video file used to create the input subtitle file. If outputFps is also included, subtitle-converter will shift the timecode accordingly to fit the output FPS.

  • For example: 25, 23.976, 29.97

outputFps (number) - Pass in the FPS desired for the output subtitle file. sourceFps is a required field in order to do FPS conversion.

  • For example: 25, 23.976, 29.97

removeTextFormatting (boolean) - Default is false. If set to true, tags such as <b> and {bold} will be stripped from the text. This may be useful when converting to formats that do not support styling in this manner.

timecodeOverlapLimiter (number, boolean) - Default is false, allowing overlapping timecode. If a number (in seconds) is included subtitle-converter will automatically fix overlapping timecode if the amount of seconds the text overlaps is less than the timecodeOverlapLimiter.

  • If this value is set to 1 and your SRT looks like:
1
00:00:15,448 --> 00:00:18,000
Hello

2
00:00:17,417 --> 00:00:19,252
World
  • Then the output would become:
1
00:00:15,448 --> 00:00:18,000
Hello

2
00:00:18,000 --> 00:00:19,252
World

combineOverlapping (boolean) - Default is false. If set to true, timecodes that are overlapping will be combined into one entry with a newline separating the text.

Validate

Returns a status object with the following format.

status = {
  success: true/false,
  startsAtZeroHour: true/false,
  reversedTimecodes: [{id, timecode}],
  overlappingTimecodes: [{id, timecode}],
  formattedText: [{id, text}],
  invalidEntries: [{id, timecode, text}],
  invalidTimecodes: [{id, timecode}],
  invalidIndices: [{id}],
}

Example:

// Validate with defaults
const { validate } = require('subtitle-converter');
const status = validate(text, '.srt');

console.log(status);

// Validate with options
const { validate } = require('subtitle-converter');
const status = validate(text, '.srt', {
    startsAtZeroHour: true,
    overlappingTimecodes: true
  });

console.log(status.succes);

Options

Please Note: If no options are passed, all checks will take place. If options are specified, only those checks that are set to true will take place.


startsAtZeroHour (boolean) - checking if the first timecode starts at hour zero.

reversedTimecodes (boolean) - checking if there are any timecodes where the start time is after the end time.

overlappingTimecodes (boolean) - checking if there are any timecodes where a start time occurs before the previous end time.

formattedText (boolean) - checking if there is any formatted text. ({an 1},<i>This text is italicized</i>).


invalidEntries (Always detected) - checking if there are any odd entries or errors.

invalidTimecodes (Always detected) [.srt] - checking if there are any timecodes that are not in a valid format.

invalidIndices (Always detected) [.srt] - checking if there are any non-digit indices before timecodes.