Giter VIP home page Giter VIP logo

vtt-to-srt's Introduction

vtt-to-srt

Convert WebVTT (The Web Video Text Tracks Format, aka html5 video subtitles) into SubRip SRT.

Check it out srt-to-vtt for reverse convertion.

Setting up

npm install vtt-to-srt
# or set it up globally
npm install vtt-to-srt --global

Command line

You may use it from the terminal if vtt-to-str was installed globally

vtt-to-srt example.vtt example.srt
cat example.vtt | vtt-to-srt > example.str
vtt-to-srt example.str < example.vtt

Usage

If converting from a text file:

import fs from 'fs';
import vtt2srt from 'vtt-to-srt';

fs.createReadStream(__dirname + '/subtitles.vtt')
  .pipe(vtt())
  .pipe(fs.createWriteStream(__dirname + '/subtitles.srt'));

If converting from an string:

import fs from 'fs';
import vtt2srt from 'vtt-to-srt';

const vttString = 'WEBVTT FILE\r\n1\r\n00:00:01.000 --> 00:00:02.000\r\nthis is WebVTT';

const srtStream = vtt2srt();

srtStream.write(vttString);
srtStream.end();
srtStream.pipe(fs.createWriteStream(__dirname + '/subtitles.srt'));

If converting to an string:

import fs from 'fs';
import vtt2srt from 'vtt-to-srt';

const vttString = 'WEBVTT FILE\r\n1\r\n00:00:01.000 --> 00:00:02.000\r\nthis is WebVTT';

const srtStream = vtt2srt();

srtStream.write(vttString);
srtStream.end(() => console.log(srtStream.read().toString('utf-8'));

Note: these examples are available in the examples folder. Run them with babel-node

Test

npm run test

vtt-to-srt's People

Contributors

tsur avatar jiyee avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.