smacke / ffsubsync

Automagically synchronize subtitles with video.
MIT License
6.74k stars 278 forks source link

allow one split to handle cases where intro sequence appears in middle of video #115

Open smacke opened 3 years ago

smacke commented 3 years ago

In most cases, a TV episode's intro sequence will occur at the start of the video, and ffs will handle these properly. However, if the intro sequence occurs in the middle, at least part of the sync will always be incorrect. If we are allowed to split the subtitles a single time, we should be able to handle the case where the intro sequence occurs in the middle, which should cover the majority of cases where splits are necessary.

The key is to figure out how to pick the split point. I think golden section search for the split point could be a good strategy. The other approach that could work well based on early tests is to try and search for "maximally self-concordant blocks", i.e., maximum-sized blocks for which the best sync on any sub-block agrees with the sync on the overall block. The latter approach has the advantage that it could generalize nicely to any number of splits, but the golden section search approach is probably easier to implement.