subsync

package
v0.10.0-dev.44 Latest Latest
Warning

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

Go to latest
Published: Nov 9, 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 on the piecewise stage and its drop state: they ship off, so Align and the jobs never ask AlignReference past ModelLinear. Only this package's tests reach the piecewise path, until a corpus-gate run records zero delivered-and-wrong with it on.

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, lines over no reference dialogue, 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) (timing.Timing, timing.Verdict, error)

Settle refuses a measured result with ErrDifferentCut when its InsertedMs passes maxRiseMs, its GapSpeechMs passes maxGapSpeechMs, its EdgeSpeechMs passes maxEdgeSpeechMs or its ExtraLinesMs passes maxExtraLinesMs, at any confidence for a reference fit and once audioGate passes for an audio one; and, once its gate passes, when its EdgeFit is below edgeGate. forced skips the GapSpeechMs, EdgeSpeechMs and ExtraLinesMs grounds. Otherwise it returns r's timing and Verified when its gate passes (referenceGate, or audioGate for audio), else Identity and Unverified.

Types

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
	Confidence float64 // e2, held out for piecewise; peak × 0.9 for audio
	Method     timing.Method
	Measured   bool
}

Result is one fit. Shape is measured against the reference whenever one passed the guard, for an audio fit too; Measured is false when none did.

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 is ModelNone. With a non-empty ref (one that passed AlignReference's guard) it measures the shift's Shape 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 {
	// GapSpeechMs is the most reference dialogue inside one interior stretch
	// the kept cues leave uncovered.
	GapSpeechMs int64
	// 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
	// ExtraLinesMs is the longest span, from first start to last end, of
	// consecutive kept cues none of which lies within maxRiseMs of reference
	// dialogue, head, tail and interior: material the video lacks.
	ExtraLinesMs 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 fit's e2 when fewer than 2 × edgeCues cues are kept.
	EdgeFit float64
}

Shape is what Settle reads of one fit's 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