Technical details


I designed Subtitles Synchronizer in C++. It uses Qt 4.8.0 for the user interface. It only runs on Windows (XP, Vista, 7).

Operating principle


When subtitles are not synchronized with a video, you may have two causes: your video and the subtitles' don't start at the same moment, or your video and the subtitles' don't have the same frame rate, which means that one will be played faster than the other. Of course your issue may be a mix of the two.

In order to correct the first problem, just a translation in time on the subtitles file is enough. So you only theorically need to know when one sentence is actually said in the video. To correct the second issue, it's a little trickier, you must multiply the start time by a ratio of the frame rate of each video. Anyway you must know two sentences to do so.

But the real problem is that you can't know for sure when a sentence is pronounced, since you can only rely on your ears. And the whole new subtitles file will rely on your measure(s). If you are wrong, and you will be, then the whole video won't be synchronized.

Since there will always be an error, we must find a way to minimize it. That's why the user is prompted to set several sentences, even if only one or two are theorically necessary.

Linear regression


We assume that the video won't have any other trouble that a difference of frame rate, or the moment it starts. Thus let t be the time a subtitles is displayed according to the subtitles file, we must find t' = a*t + b, the time the subtitles must be displayed. So we need to find out a and b. (We find again that only one or two measures are theorically needed).

What the user gives us is a series of samples (ti, t'i). Keeping in mind we must find (a, b) (i.e. a straight line if you look at t' = a*t + b), we must find the line which is the closest to each measure. This is done by applying a linear regression algorithm, and that's how Subtitles Synchronizer proceeds to synchronize the subtitles on the video.

This method explains why the more sentences the more accurate: the more samples, the more the error can be lowered by this method. Besides this method is more accurate if the measures, the sentences provided by the user, are far from each other. This can be seen easily: since what we try to find out is a line, try to plot sereral lines manually on a paper which cross two very close points. You will get very different lines. Try again with points which are far from each other, and will surely get/see a unique line.

Read more about linear regression.


Copyright © 2012-2017 Sébastien Bini, all rights reserved. Please report any problem.