How to fix out-of-sync subtitles
This is for anyone who has found a subtitle file for a film or episode and watched the lines arrive a beat too late, or start fine and end up minutes adrift: people building a home media library, language learners pairing a film with a second-language track, and video editors and course producers handed a caption file cut for a different export.
Shift, or stretch? Check two lines
Out-of-sync subtitles fail in one of two ways, and two minutes with the video tells you which. Play a line in the first few minutes and note how far off it is. Then jump near the end and do the same.
- Same error at both ends: an offset. The release you have has a longer or shorter intro, a different studio logo, or a recap trimmed. Shift every line by that amount.
- Small error at the start, large at the end: a frame-rate drift. The file was timed against a copy running at a different speed, and the error grows with every minute. A shift cannot fix it; the timing has to be stretched.
Why the drift is nearly always 25 to 23.976
Film runs at 24 frames per second, and streaming and NTSC copies run it at 23.976 (exactly 24000/1001). European PAL television and DVDs run at 25 frames per second and simply play every frame once, so a PAL copy runs about 4.3% fast and a 100-minute film finishes roughly four minutes early. A subtitle ripped from a PAL disc and played on a 23.976 copy drifts behind steadily.
The fix is one multiplication. Frame n appears at n/25 seconds on the PAL copy
and at n/23.976 on yours, so every time in the file becomes
t × 25 / 23.976 = t × 1.0427083. The reverse case (film-rate subtitles on a PAL copy)
divides by the same number.
A worked example
A subtitle file's line 12 sits at 00:02:00,000 but is spoken at
00:02:07,125. Its last line sits at 01:30:00,000 but is spoken at
01:33:52,625. The error grows from 7.1 seconds to 3 minutes 52.6 seconds, so this is
a drift plus a shift.
| Step | Arithmetic | Result |
|---|---|---|
| Stretch | (5,632.625 − 127.125) / (5,400 − 120) | 1.0427083, the 25 → 23.976 ratio |
| Shift | 127.125 − 120 × 1.0427083 | +2.000 s (a longer logo on this copy) |
| A line at 00:45:00,000 | 2,700 × 1.0427083 + 2 | 2,817.313 s = 00:46:57,313 |
In the tool, pick Two sync points, enter line 12 and the last line with the times you heard, and it computes both numbers. Or pick Frame-rate fix, 25 → 23.976, with an extra shift of 2. The command line gives the same file either way:
node resync.mjs film.srt --sync 00:02:00,000=00:02:07,125 --sync 01:30:00,000=01:33:52,625 node resync.mjs film.srt --fps 25:23.976 --offset 2
No time to read times off the video? Use a second subtitle
If you have a correctly timed subtitle for the same copy, in any language, the tool can do the whole thing from timing alone. Dialogue has a rhythm that survives translation: lines begin and end at the same moments. Every pair of lines votes for the shift that would put one on the other, at each common frame-rate ratio; the true answer collects a pile of votes while unrelated pairs scatter. A line fitted through the lines that then land close together gives the final stretch and shift, and a confidence rating says how many lines agreed.
On 200 synthetic tracks of 600 to 1,800 lines (a random frame-rate ratio, a shift of up to five minutes either way, a quarter of lines missing from one file, a fifth extra, each line jittered by up to 0.3 s), every one came back within half a second of the true timing at the start and end of the film, rated high confidence; 50 pairs of unrelated tracks were never rated high. Those are generated tracks, not real films: the test file and the sweep are in the source.
When to use something else
- No reference subtitle, and you won't scrub the video: a tool that listens to the audio, such as ffsubsync, finds the shift from speech itself.
- The versions differ by cut scenes, not speed (an extended edition, a TV edit): one straight line cannot fit both halves. alass splits the file into pieces and aligns each.
- Fixing wording or individual lines against a waveform: a desktop editor such as Subtitle Edit or Aegisub.
Common questions
How do I tell an offset from a frame-rate drift?
Check two lines, one in the first few minutes and one near the end. If both are off by the same amount, it is an offset: shift by that amount. If the error at the end is much bigger than at the start, the file was timed for a release at another frame rate, and it needs a stretch as well.
Why is 25 to 23.976 fps the usual fix?
Film is shot at 24 frames per second and released for streaming and NTSC regions at 23.976. European PAL television and DVDs run at 25 frames per second and play every frame of the film once, so the whole film runs about 4.3% fast and finishes roughly four minutes early. Subtitles timed against a PAL copy drift steadily behind on a 23.976 copy. Every time in the file has to be multiplied by 25 / 23.976 = 1.0427083.
When should I use a different tool?
When there is no correctly timed subtitle to align to and you do not want to read times off the video, a tool that listens to the audio, such as ffsubsync, can find the shift itself. When the two versions differ by cut scenes rather than speed, you need an aligner that splits the file into pieces, such as alass. For editing wording and timing line by line against a waveform, a desktop editor such as Subtitle Edit or Aegisub fits better.
Subtitle Resync is not affiliated with ffsubsync, alass, Subtitle Edit or Aegisub; they are named so you can pick the right tool. Use subtitles you have the right to use.