Understand the ffsubsync synchronization algorithm
masterffsubsync treats subtitle synchronization as a signal-alignment problem using a three-step process:
- Discretize: The reference (audio stream or existing subtitle timings) and the input subtitles are divided into 10 ms windows.
- Label speech: Each 10 ms window is labeled as 'speech' (1) or 'not speech' (0). For subtitles, a window is 'speech' if any subtitle is on screen. For audio, a voice-activity detector (VAD) is used.
- Align: The algorithm compares the two resulting binary strings and searches for the temporal shift that maximizes the alignment score.
If framerate correction is enabled, the algorithm repeats this search across various candidate framerate ratios to find the best overall result.