Giter Site home page Giter Site logo

go-astisub's Introduction

GoReportCard GoDoc Test Coveralls

This is a Golang library to manipulate subtitles.

It allows you to manipulate srt, stl, ttml, ssa/ass, webvtt and teletext files for now.

Available operations are parsing, writing, applying linear correction, syncing, fragmenting, unfragmenting, merging and optimizing.

Installation

To install the library:

go get github.com/asticode/go-astisub

To install the CLI:

go install github.com/asticode/go-astisub/astisub        

Using the library in your code

WARNING: the code below doesn't handle errors for readibility purposes. However you SHOULD!

// Open subtitles
s1, _ := astisub.OpenFile("/path/to/example.ttml")
s2, _ := astisub.ReadFromSRT(bytes.NewReader([]byte("1\n00:01:00.000 --> 00:02:00.000\nCredits")))

// Add a duration to every subtitles (syncing)
s1.Add(-2*time.Second)

// Fragment the subtitles
s1.Fragment(2*time.Second)

// Merge subtitles
s1.Merge(s2)

// Optimize subtitles
s1.Optimize()

// Unfragment the subtitles
s1.Unfragment()

// Apply linear correction
s1.ApplyLinearCorrection(1*time.Second, 2*time.Second, 5*time.Second, 7*time.Second)

// Write subtitles
s1.Write("/path/to/example.srt")
var buf = &bytes.Buffer{}
s2.WriteToTTML(buf)

Using the CLI

If astisub has been installed properly you can:

  • convert any type of subtitle to any other type of subtitle:

      astisub convert -i example.srt -o example.ttml
    
  • apply linear correction to any type of subtitle:

      astisub apply-linear-correction -i example.srt -a1 1s -d1 2s -a2 5s -d2 7s -o example.out.srt
    
  • fragment any type of subtitle:

      astisub fragment -i example.srt -f 2s -o example.out.srt
    
  • merge any type of subtitle into any other type of subtitle:

      astisub merge -i example.srt -i example.ttml -o example.out.srt
    
  • optimize any type of subtitle:

      astisub optimize -i example.srt -o example.out.srt
    
  • unfragment any type of subtitle:

      astisub unfragment -i example.srt -o example.out.srt
    
  • sync any type of subtitle:

      astisub sync -i example.srt -s "-2s" -o example.out.srt
    

Features and roadmap

  • parsing
  • writing
  • syncing
  • fragmenting/unfragmenting
  • merging
  • ordering
  • optimizing
  • linear correction
  • .srt
  • .ttml
  • .vtt
  • .stl
  • .ssa/.ass
  • .teletext
  • .smi

go-astisub's People

Contributors

asticode avatar dlecorfec avatar nhannguyen700 avatar arnestorksen avatar asnapper avatar tobbee avatar discovery-avishekgulshan avatar anupcshan avatar arun1587 avatar caryyu avatar des-nerger avatar eldersjavas avatar firodj avatar finn0 avatar ruxton avatar j0sh avatar mholt avatar mernat avatar chadnickbok avatar rockjohnson503 avatar samuel avatar nakamume avatar withoutpants avatar iheidashuai avatar ping avatar rrooij 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.