subgo

package module
v1.2.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 17, 2026 License: MIT Imports: 11 Imported by: 0

README

subgo

A Go library and CLI for processing subtitle files.

Installation

go install github.com/kianelbo/subgo/cmd/subgo@latest

CLI Usage

subgo <input-file> [flags]
Flags
Flag Description
-o, --output Output file (default: output.srt)
-s, --shift Shift timing (e.g., 300ms, -1s)
-t, --stretch Stretch factor (e.g., 1.05 for 5% longer)
-c, --clamp Clamp negative times to zero (default: true)
--trim-first Remove first n events
--trim-last Remove last n events
--trim-before Remove events before timestamp
--trim-after Remove events after timestamp
--remove-hi Remove hearing impaired annotations
--remove-ids Remove events by comma-separated indices
Example
subgo eraserhead.srt --trim-before 1m --shift 300ms --remove-hi -o eraserhead.srt

Library Usage

import "github.com/kianelbo/subgo"

sub, _ := subgo.Load("input.ass")
sub = sub.Shift(300*time.Millisecond, true)
sub = sub.Stretch(1.05, 0)
sub.Save("output.srt")

Supported Formats

  • SRT
  • ASS/SSA
  • WebVTT
  • SBV

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Event

type Event struct {
	Start time.Duration
	End   time.Duration
	Text  string
}

Event represents a single subtitle cue.

type Format

type Format interface {
	Name() string
	Extensions() []string
	Decode(r io.Reader) (Subtitle, error)
	Encode(w io.Writer, s Subtitle) error
}

Format represents a subtitle file format (SRT, ASS, etc.).

func DetectFormat

func DetectFormat(filename string) (Format, error)

DetectFormat returns a Format based on the filename's extension.

type Subtitle

type Subtitle struct {
	Events []Event
}

Subtitle is a collection of events.

func Load

func Load(filename string) (Subtitle, error)

Load reads a subtitle file, detecting format from the filename extension.

func (Subtitle) RemoveHI

func (s Subtitle) RemoveHI() Subtitle

RemoveHI removes hearing impaired annotations like (sobbing) or [loud noise] from event text. Events that become empty after removal are excluded.

func (Subtitle) RemoveIds added in v1.1.1

func (s Subtitle) RemoveIds(ids []uint) Subtitle

RemoveIds remove events by indices.

func (Subtitle) Save

func (s Subtitle) Save(filename string) error

Save writes the subtitle to a file, detecting format from the filename extension.

func (Subtitle) Shift

func (s Subtitle) Shift(delta time.Duration, clamp bool) Subtitle

Shift returns a new Subtitle with all events shifted by delta. If clamp is true, negative times are clamped to zero.

func (Subtitle) Stretch

func (s Subtitle) Stretch(factor float64, anchor time.Duration) Subtitle

Stretch returns a new Subtitle with all times scaled around an anchor. newT = (t - anchor) * factor + anchor.

func (Subtitle) TrimAfter

func (s Subtitle) TrimAfter(t time.Duration) Subtitle

TrimAfter removes all events that start after the given timestamp.

func (Subtitle) TrimBefore

func (s Subtitle) TrimBefore(t time.Duration) Subtitle

TrimBefore removes all events that start before the given timestamp.

func (Subtitle) TrimFirst

func (s Subtitle) TrimFirst(n int) Subtitle

TrimFirst removes the first n events.

func (Subtitle) TrimLast

func (s Subtitle) TrimLast(n int) Subtitle

TrimLast removes the last n events.

Directories

Path Synopsis
cmd
subgo command

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL