subtitle

package
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Oct 29, 2026 License: AGPL-3.0 Imports: 16 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package subtitle finds a video's subtitle tracks, embedded or in files next to it, and serves the text ones as WebVTT for the web player.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Converter

type Converter struct {
	FFmpeg string
	Dir    string
	// contains filtered or unexported fields
}

Converter turns subtitle tracks into WebVTT and caches the results, so each track is converted once per version of its file.

func NewConverter

func NewConverter(ffmpeg, dir string) *Converter

func (*Converter) Serve

func (c *Converter) Serve(w http.ResponseWriter, r *http.Request, videoPath string, t Track, all []Track)

Serve writes track t of the video at videoPath as WebVTT. all lists the video's tracks: the first request for an embedded track extracts every embedded text track in one pass, since that costs one read of the file.

type Track

type Track struct {
	ID    string `json:"id"`    // "e<N>" for embedded stream N, "x<hash>" for a sidecar file
	Label string `json:"label"` // in English, such as "English (SDH)"
	// Note is the track's own title, where it says more than its language
	// and flags, such as "Commentary", so apps can build a label in their
	// own language.
	Note     string `json:"note,omitempty"`
	Language string `json:"language,omitempty"` // ISO 639-1 where known, e.g. "en"
	Codec    string `json:"codec"`
	Forced   bool   `json:"forced,omitempty"`
	Default  bool   `json:"default,omitempty"`
	SDH      bool   `json:"sdh,omitempty"`
	External bool   `json:"external,omitempty"`
	// BurnIn marks picture-based subtitles (PGS, VobSub, DVB), which browsers
	// can't render: the server draws them into the video during a transcode.
	BurnIn bool `json:"burnIn,omitempty"`

	Stream int    `json:"-"` // embedded: index among the file's subtitle streams
	Path   string `json:"-"` // external: the sidecar file
}

Track is one subtitle track a player can offer.

func Find

func Find(tracks []Track, id string) (Track, bool)

Find returns the track with the given id.

func List

func List(videoPath string, embedded []probe.Subtitle) []Track

List returns a video's tracks: embedded streams in file order, then sidecar files. Codecs Matinee can't show at all are left out.

func Sidecars

func Sidecars(videoPath string) []Track

Sidecars finds subtitle files named after a video, like "Movie.srt", "Movie.en.srt", "Movie.en.forced.srt" or "Movie.English.SDH.srt".

Jump to

Keyboard shortcuts

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