Subtitles Offset

If you arrived here through Google (or Bing, or whatever) then you are like me: tired of downloading countless subtitle files that although they contain the correct subtitles, they are offset by a couple of seconds.

Sites such as opensubtitles.org and subscene.com, among many others, are great sources for subtitles but, unfortunately, it is quite hard to know which subtitles will work correctly with your video.

For example, yesterday I decided to rip my two versions of The Exorcist so that I could play them through MediaPortal without having to insert the DVDs.

The ripping process was a snap using the wonderful Freemake Video Converter but, unfortunately, if you decide to include the DVD’s own subtitles in the ripped version, Video Converter does not generate separate SRT files, instead, it embeds the original bitmaps from the DVD subtitles resulting in awful and almost impossible to read captions.

Subtitles Offset

Subtitles Offset

So I decided to rip the DVD without any subtitles and then hunt for an appropriate subtitles file…
After much frustration I launched Visual Studio and started coding a small and simple program that would allow me to offset the subtitles by modifying the timing information in the subtitles file.

The results? Perfectly synced subtitles!

At this moment the program is quite simple and probably missing some functionality but it definitely does the job. Who knows? If I get sufficiently bored I may even upgrade it to make it a fully functional and featured subtitling program…

So, if you need to “just” apply an offset to an SRT file, then this little toy will do just that.
Note what when you save the changes, the program will create a new SRT file so the original is never overwritten.
Also note that Subtitle Offset requires the Microsoft .NET Framework 4 Client Profile.

Subtitles Offset (Alpha 1) 0.1 [13.83 kB]

Update: Please always refer to the latest post about Subtitles Offset to make sure you always obtain the latest version.

How does Subtitle Offset work?

It’s quite simple.
First of all, the program parses the SRT file knowing that its format is as follows:

  • Subtitle Index: An integer sequential number representing the index of the subtitle.
  • Time Information: The start and ending time of the subtitle.
  • Text: The actual caption for the current subtitle. Can include one or multiple lines.

Here’s a small section from an SRT file:

899
1:30:53,820 –> 1:30:56,84
What an excellent day for an exorcism.

900
1:30:58,358 –> 1:30:59,655
You’d like that?

901
1:30:59,759 –> 1:31:1,158
Intensely.

The trick here is that when the program reads the subtitles’ timeing information it converts the string-based timing data to a TimeSpan structure. This, of course, is to facilitate the offsetting process.

Each subtitle is then parsed and fed to a class called “Caption” which stores each subtitle with all its information.

Once all the captions are parsed, the program waits for the user to make changes to the offset parameters and then, when a change is detected, a process if called to apply the user’s offset:

Private Sub UpdateOffsetted()
	Dim sec As Integer = nudSeconds.Value
	Dim msec As Integer = nudMilliseconds.Value

	Dim offset As TimeSpan = TimeSpan.FromMilliseconds(sec * 1000 + msec)

	For i As Integer = 0 To originalCaptions.Count - 1
		offsettedCaptions(i).FromTime = originalCaptions(i).FromTime + offset
		offsettedCaptions(i).ToTime = originalCaptions(i).ToTime + offset
		UpdateListViewCaption(lvOffsetted, offsettedCaptions(i))
	Next
End Sub

If you want to play around with the code, here’s a link to download the sources as a Visual Studio 2010 project:

Subtitles Offset (Alpha 1) Source Code 0.1 [44.3 kB]

Update: Please always refer to the latest post about Subtitles Offset to make sure you always obtain the latest version.