AlexPoint / SubtitlesParser

Multi formats subtitles parser in C#
MIT License
134 stars 40 forks source link

The decimal numbers of `StartTime` and `EndTime` of `SrtWriter` should be 3 instead of 2. #34

Closed tuanbs closed 2 years ago

tuanbs commented 2 years ago

I found out an issue is that the SrtWriter class returns the StartTime and EndTime with only 2 decimal numbers (fractional part). It leads to the video plays and stops the subtitle earlier a little bit. It should be 3 instead of 2 because I see most subtitles use 3 decimal numbers. For example, the original subtitle is:

00:00:06.704 --> 00:00:10.538
The ravenous swarm stretches
as far as the eye can see.

After using SrtWriter it becomes:

1
00:00:06,70 --> 00:00:10,53
The ravenous swarm stretches
as far as the eye can see.

I found this issue is from the following line: SubtitlesParser/Classes/Writers/SrtWriter.cs

...
string formatTimecodeLine()
{
            TimeSpan start = TimeSpan.FromMilliseconds(subtitleItem.StartTime);
            TimeSpan end = TimeSpan.FromMilliseconds(subtitleItem.EndTime);
            return $"{start:hh\\:mm\\:ss\\,ff} --> {end:hh\\:mm\\:ss\\,ff}";
}
...

I fixed it by replacing return $"{start:hh\\:mm\\:ss\\,ff} --> {end:hh\\:mm\\:ss\\,ff}"; into return $"{start:hh\\:mm\\:ss\\,fff} --> {end:hh\\:mm\\:ss\\,fff}";.

So please update it if you think it's right. Thanks for this awesome plugin and please keep evolving it as you guys are doing amazing job. Cheers.

AlexPoint commented 2 years ago

Thanks for raising this issue. Indeed, the writers were missing a figure in the milliseconds. I committed the changes (link) and pushed a new nuget package (v1.5.1)