David Le CorfecandGitHub 7acfe23468 Improve STL GSIBlock write (#75)
* add missing STL GSIBlock fields to Subtitles.Metadata

* write the same GSIBlock as read

* fix stl tests
2023-01-20 11:48:38 +01:00
2022-04-14 10:15:24 +02:00
2023-01-20 11:48:38 +01:00
2017-12-24 03:41:14 +01:00
2022-03-17 11:22:56 +01:00
2021-04-14 09:52:13 +02:00
2021-04-14 09:52:13 +02:00
2021-08-10 16:58:26 +02:00
2017-07-02 15:45:41 +02:00
2022-04-14 10:15:24 +02:00
2017-07-15 11:52:08 +02:00
2021-08-13 18:09:14 +02:00
2023-01-20 11:48:38 +01:00
2023-01-20 11:48:38 +01:00
2022-04-14 10:15:24 +02:00
2023-01-20 11:48:38 +01:00
2021-04-14 09:52:13 +02:00
2021-08-10 16:58:26 +02:00

GoReportCard GoDoc Travis 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("00: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
S
Description
Manipulate subtitles in GO (.srt, .ssa/.ass, .stl, .ttml, .vtt (webvtt), teletext, etc.)
Readme MIT
363 KiB
Languages
Go 99.9%
Dockerfile 0.1%