# README
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
# Functions
NewSubtitles creates new subtitles.
Open opens a subtitle reader based on options.
OpenFile opens a file regardless of other options.
ReadFromSRT parses an .srt content.
ReadFromSSA parses an .ssa content.
ReadFromSSAWithOptions parses an .ssa content.
ReadFromSTL parses an .stl content.
ReadFromTeletext parses a teletext content http://www.etsi.org/deliver/etsi_en/300400_300499/300472/01.03.01_60/en_300472v010301p.pdf http://www.etsi.org/deliver/etsi_i_ets/300700_300799/300706/01_60/ets_300706e01p.pdf TODO Update README TODO Add tests.
ReadFromTTML parses a .ttml content.
ReadFromWebVTT parses a .vtt content TODO Tags (u, i, b) TODO Class.
WriteToTTMLWithIndentOption sets the indent option.
# Constants
Languages.
Languages.
Languages.
Languages.
Languages.
# Variables
Bytes.
Colors.
Colors.
Colors.
Colors.
Colors.
Colors.
Colors.
Colors.
Colors.
Colors.
Colors.
Colors.
Colors.
Colors.
Colors.
Colors.
Errors.
Errors.
Errors.
Now allows testing functions using it.
# Structs
Color represents a color.
Item represents a text to show between 2 time boundaries with formatting.
Line represents a set of formatted line items.
LineItem represents a formatted line item.
Metadata represents metadata TODO Merge attributes.
Options represents open or write options.
Region represents a subtitle's region.
SSAOptions.
STLOptions represents STL parsing options.
Style represents a subtitle's style.
StyleAttributes represents style attributes.
Subtitles represents an ordered list of items with formatting.
TeletextOptions represents teletext options.
TTMLIn represents an input TTML that must be unmarshaled We split it from the output TTML as we can't add strict namespace without breaking retrocompatibility.
TTMLInDuration represents an input TTML duration.
TTMLInHeader represents an input TTML header.
TTMLInItem represents an input TTML item.
TTMLInMetadata represents an input TTML Metadata.
TTMLInRegion represents an input TTML region.
TTMLInStyle represents an input TTML style.
TTMLInStyleAttributes represents input TTML style attributes.
TTMLInSubtitle represents an input TTML subtitle.
TTMLOut represents an output TTML that must be marshaled We split it from the input TTML as this time we'll add strict namespaces.
TTMLOutHeader represents an output TTML header.
TTMLOutItem represents an output TTML Item.
TTMLOutMetadata represents an output TTML Metadata.
TTMLOutRegion represents an output TTML region.
TTMLOutStyle represents an output TTML style.
TTMLOutStyleAttributes represents output TTML style attributes.
TTMLOutSubtitle represents an output TTML subtitle.
WebVTTTimestampMap is a structure for storing timestamps for WEBVTT's X-TIMESTAMP-MAP feature commonly used for syncing cue times with MPEG-TS streams.
WriteToTTMLOptions represents TTML write options.
# Type aliases
TTMLInItems represents input TTML items.
TTMLOutDuration represents an output TTML duration.
WriteToTTMLOption represents a WriteToTTML option.