subsync

package
v0.10.0-dev.74 Latest Latest
Warning

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

Go to latest
Published: Nov 11, 2026 License: AGPL-3.0 Imports: 12 Imported by: 0

Documentation

Overview

Package subsync aligns a subtitle to its video: the reference pipeline, the audio path, the dialogue filter and the verdict. It does no I/O and never logs.

Index

Constants

View Source
const (

	// MaxAudioFrames bounds the audio path's frames, 10 ms each: about 83
	// minutes, the FFT's memory at 500,000 frames.
	MaxAudioFrames = 500_000
)

The reference pipeline's constants: one owner per number.

View Source
const MaxModel = ModelLinear

MaxModel is the corpus gate's verdict: Linear, with the end-fit ground, refused fewer same-cut subtitles than piecewise and its drop state at zero delivered-and-wrong, so Align and the jobs never ask AlignReference past ModelLinear and only this package's tests reach the piecewise path.

Variables

View Source
var ErrDifferentCut = errors.New("subsync: the subtitle is for a different cut")

ErrDifferentCut reports a mapping showing the candidate is for another cut of the video: reference dialogue it leaves uncovered past either end, time it inserts, or an end of the subtitle that fits the reference worse than edgeGate.

Functions

func Settle

func Settle(r *Result, forced bool, below Fallback) (timing.Timing, timing.Verdict, error)

Settle returns r's timing and Verified when its gate passes (referenceGate, or audioGate for audio), else, Unverified, the mapping below names. It refuses with ErrDifferentCut instead when the coverage guard finds a cut in the mapping it returns or, for a reference fit, in the fit's own Shape at any confidence. An unmeasured result has no reference to judge against. forced skips the EdgeSpeechMs ground.

Types

type Fallback

type Fallback uint8

Fallback is what a caller delivers for a fit below its gate.

const (
	// AtIdentity delivers the candidate where it lies, Unverified: search's
	// delivery.
	AtIdentity Fallback = iota
	// AtFit offers the fit's own timing, Unverified: a proposal a person
	// reviews before applying it, or a batch, which applies nothing below
	// the gate.
	AtFit
)

type Model

type Model uint8

Model is the hypothesis the pipeline selected, and AlignReference's ceiling.

const (
	ModelNone Model = iota // the guard refused an input
	ModelShift
	ModelLinear
	ModelPiecewise
)

The models, in the order the pipeline tries them.

type Result

type Result struct {
	Timing        timing.Timing // canonical form
	Shape         Shape
	IdentityShape Shape
	Confidence    float64 // e2, held out for piecewise; peak × 0.9 for audio
	Method        timing.Method
	Measured      bool
}

Result is one fit. Shape (Timing's mapping) and IdentityShape (the candidate as it is, which Settle delivers below the gate) are measured against the reference for any fit made beside one that passed the guard, an audio fit too; Measured is false otherwise, and always for the MethodNone result.

func AlignAudio

func AlignAudio(ctx context.Context, speech Speech, ref, inc []Span, durationMs int64) (Result, error)

AlignAudio returns a Shift with Confidence peak × 0.9 from correlating the safe and precise speech decisions with inc's dialogue, the precise one when the two offsets agree within audioAgreementMs. Fewer than minSpans spans, no frames, or an offset past the duration's limit places nothing: the MethodNone result AlignReference's guard returns. With a non-empty ref (one that passed AlignReference's guard) it measures the shift's Shape and IdentityShape against it, so Settle guards the audio fit as it guards a reference one. durationMs is the video's duration.

func AlignReference

func AlignReference(ctx context.Context, ref, inc []Span, upTo Model) (Result, error)

AlignReference is shift, then linear, then (upTo ModelPiecewise only) piecewise with a drop state on the selected global model's scale; every non-Drop segment it emits holds a kept cue's start. More than maxSpans spans on either side, fewer than minSpans, or a reference speech coverage outside (0.05, 0.95) is ModelNone. A context ended before or during a stage returns its error and no result.

type Shape

type Shape struct {
	// EdgeSpeechMs is the reference dialogue lying more than maxRiseMs before
	// the first kept cue's start or after the last kept cue's end.
	EdgeSpeechMs int64
	// InsertedMs is the most the mapping lengthens a kept-to-kept gap beyond
	// Scale times its candidate gap; 0 for Shift and Linear.
	InsertedMs int64
	// EdgeFit is the lowest e2 of any run of at least edgeCues consecutive
	// kept cues that starts at the first kept cue or ends at the last; the
	// whole mapping's e2 when fewer than 2 × edgeCues cues are kept.
	EdgeFit float64
}

Shape is what Settle reads of one mapping, in video time after its scale.

type Span

type Span struct{ StartMs, EndMs int64 }

Span is one dialogue cue on the baseline timeline.

func DialogueSpans

func DialogueSpans(c timing.Cues) []Span

DialogueSpans keeps ASS and SSA Dialogue events whose style the classifier calls dialogue, then every event surviving the SDH, music, karaoke-pair, typesetting-font and credit filters.

type Speech

type Speech struct{ LLR []float64 }

Speech is the audio path's input: one vad.Detector LLR per 10 ms frame of the video's first audio stream, at most MaxAudioFrames.

Directories

Path Synopsis
Package ffmpeg is subflux's one ffmpeg and ffprobe runner.
Package ffmpeg is subflux's one ffmpeg and ffprobe runner.
ffmpegtest
Package ffmpegtest lets a test binary stand in for ffmpeg and ffprobe.
Package ffmpegtest lets a test binary stand in for ffmpeg and ffprobe.
Package fft provides a radix-2 Cooley-Tukey FFT implementation for cross-correlation in the subsync package.
Package fft provides a radix-2 Cooley-Tukey FFT implementation for cross-correlation in the subsync package.
Package vad is a line-by-line Go port of WebRTC's voice activity detector (chromium/webrtc common_audio/vad/, BSD-3-Clause, Copyright (c) 2012 The WebRTC project authors): the allpass filter bank, log energy features, GMM classifier and adaptive model update.
Package vad is a line-by-line Go port of WebRTC's voice activity detector (chromium/webrtc common_audio/vad/, BSD-3-Clause, Copyright (c) 2012 The WebRTC project authors): the allpass filter bank, log energy features, GMM classifier and adaptive model update.

Jump to

Keyboard shortcuts

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