Documentation
¶
Overview ¶
Package syncing provides subtitle timing synchronization for the search engine.
Index ¶
- Constants
- func ExtractEmbeddedReference(ctx context.Context, videoPath, excludeLang string, mapper subsync.LangMapper) []subsync.Cue
- func SyncAgainstReference(ctx context.Context, data []byte, videoPath, lang string, ...) subsync.SyncResult
- func SyncFromAudio(ctx context.Context, data []byte, videoPath, subtitlePath string) subsync.SyncResult
- func SyncFromCues(ctx context.Context, data []byte, refCues []subsync.Cue, videoPath string) subsync.SyncResult
- func WriteSRT(buf *bytes.Buffer, cues []subsync.Cue) error
- type InProcessExec
- type SubtitleProcessor
- func (SubtitleProcessor) NormalizeEncoding(data []byte) []byte
- func (SubtitleProcessor) ParseSRT(data []byte) ([]api.SubtitleCue, error)
- func (SubtitleProcessor) ShiftCues(cues []api.SubtitleCue, offset time.Duration) []api.SubtitleCue
- func (p SubtitleProcessor) SyncFromAudio(ctx context.Context, data []byte, videoPath, subtitlePath string) api.AudioSyncResult
- func (SubtitleProcessor) WriteSRT(cues []api.SubtitleCue) ([]byte, error)
- type SyncExec
- type SyncResult
- type Syncer
Constants ¶
const ( ExtASS = ".ass" ExtSSA = ".ssa" )
Subtitle format extensions used for ASS/SSA detection.
Variables ¶
This section is empty.
Functions ¶
func ExtractEmbeddedReference ¶
func ExtractEmbeddedReference(ctx context.Context, videoPath, excludeLang string, mapper subsync.LangMapper) []subsync.Cue
ExtractEmbeddedReference extracts an embedded subtitle track from the video container to use as a sync reference, excluding the target language.
func SyncAgainstReference ¶
func SyncAgainstReference(ctx context.Context, data []byte, videoPath, lang string, mapper subsync.LangMapper, minConf ...float64) subsync.SyncResult
SyncAgainstReference aligns subtitle timing against an embedded reference subtitle in the video container. This is the only strategy tried here; audio-based sync enters the auto path separately via the engine's audio_sync_fallback (see Engine.syncSubtitle), and external SRT sync is manual-only from the web UI.
func SyncFromAudio ¶
func SyncFromAudio(ctx context.Context, data []byte, videoPath, subtitlePath string) subsync.SyncResult
SyncFromAudio runs audio-based sync on subtitle data using PCM extraction and onset correlation. Detects ASS format for native parsing, falls back to SRT otherwise.
func SyncFromCues ¶
func SyncFromCues(ctx context.Context, data []byte, refCues []subsync.Cue, videoPath string) subsync.SyncResult
SyncFromCues aligns incoming SRT data against pre-parsed reference cues.
Types ¶
type InProcessExec ¶ added in v0.1.148
type InProcessExec struct {
// LangMapper maps ISO 639-2/3 to 639-1 for reference-track selection.
LangMapper subsync.LangMapper
}
InProcessExec runs the strategies directly in the current process: the standalone CLI (already an isolated process), tests, and the sync-worker child itself.
func (InProcessExec) Audio ¶ added in v0.1.148
func (e InProcessExec) Audio(ctx context.Context, data []byte, videoPath, subtitlePath string) subsync.SyncResult
Audio implements SyncExec in-process.
func (InProcessExec) Reference ¶ added in v0.1.148
func (e InProcessExec) Reference(ctx context.Context, data []byte, videoPath, lang string, minConf float64) subsync.SyncResult
Reference implements SyncExec in-process.
type SubtitleProcessor ¶
type SubtitleProcessor struct {
// contains filtered or unexported fields
}
SubtitleProcessor implements api.SubtitleProcessor directly using subsync, without an intermediate backend interface. The lightweight operations (parse/write/shift/normalize) always run in-process; the heavy audio sync routes through the configured SyncExec.
func NewSubtitleProcessor ¶
func NewSubtitleProcessor() SubtitleProcessor
NewSubtitleProcessor creates a SubtitleProcessor that syncs in-process.
func NewSubtitleProcessorWithExec ¶ added in v0.1.148
func NewSubtitleProcessorWithExec(exec SyncExec) SubtitleProcessor
NewSubtitleProcessorWithExec creates a SubtitleProcessor whose audio sync runs through the given executor (server mode: the syncworker client).
func (SubtitleProcessor) NormalizeEncoding ¶
func (SubtitleProcessor) NormalizeEncoding(data []byte) []byte
NormalizeEncoding converts subtitle data to UTF-8.
func (SubtitleProcessor) ParseSRT ¶
func (SubtitleProcessor) ParseSRT(data []byte) ([]api.SubtitleCue, error)
ParseSRT parses SRT subtitle data into cues.
func (SubtitleProcessor) ShiftCues ¶
func (SubtitleProcessor) ShiftCues(cues []api.SubtitleCue, offset time.Duration) []api.SubtitleCue
ShiftCues applies a timing offset to all cues.
func (SubtitleProcessor) SyncFromAudio ¶
func (p SubtitleProcessor) SyncFromAudio(ctx context.Context, data []byte, videoPath, subtitlePath string) api.AudioSyncResult
SyncFromAudio runs audio-based sync on subtitle data.
func (SubtitleProcessor) WriteSRT ¶
func (SubtitleProcessor) WriteSRT(cues []api.SubtitleCue) ([]byte, error)
WriteSRT serializes cues to SRT format.
type SyncExec ¶ added in v0.1.148
type SyncExec interface {
// Reference aligns subtitle data against an embedded reference track
// (SyncAgainstReference semantics; minConf 0 means the default threshold).
Reference(ctx context.Context, data []byte, videoPath, lang string, minConf float64) subsync.SyncResult
// Audio aligns subtitle data against the audio track (SyncFromAudio
// semantics; subtitlePath is the ASS-detection hint, may be empty).
Audio(ctx context.Context, data []byte, videoPath, subtitlePath string) subsync.SyncResult
}
SyncExec executes the two heavy sync strategies. The default implementation (InProcessExec) runs them in this process; server mode installs the syncworker client instead, which runs each job in a supervised one-shot child process so an out-of-memory sync kills the worker, not the server (P13). The seam sits BELOW every public interface: api.SubtitleSyncer, api.SubtitleProcessor, and the package-level strategy functions keep their exact signatures and semantics.
type SyncResult ¶
type SyncResult = subsync.SyncResult
SyncResult is re-exported from subsync for consumer convenience.
type Syncer ¶
type Syncer struct {
// Exec runs the heavy alignment computation. Nil means in-process
// (LangMapper applies); server mode installs the syncworker client for
// process isolation (P13).
Exec SyncExec
// LangMapper maps ISO 639-3 codes to ISO 639-1 for ffprobe track selection.
LangMapper subsync.LangMapper
// MinConfidence is the minimum confidence threshold for auto-sync.
// When zero, defaults to api.DefaultSyncMinConfidence (0.6).
MinConfidence float64
}
Syncer implements SubtitleSyncer using the subsync library.
func (Syncer) PostProcess ¶
func (Syncer) PostProcess(data []byte, pp api.PostProcessConfig) []byte
PostProcess applies encoding normalization, HI removal, tag stripping, etc.