From 04de21e5940e5913be19fabdcb7da2bfd997f292 Mon Sep 17 00:00:00 2001 From: nilaoda Date: Mon, 12 Dec 2022 00:18:54 +0800 Subject: [PATCH] Fix #82 --- src/N_m3u8DL-RE.Common/Entity/WebVttSub.cs | 13 +++++++++---- src/N_m3u8DL-RE/CommandLine/CommandInvoker.cs | 2 +- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/src/N_m3u8DL-RE.Common/Entity/WebVttSub.cs b/src/N_m3u8DL-RE.Common/Entity/WebVttSub.cs index b33c329..05edda9 100644 --- a/src/N_m3u8DL-RE.Common/Entity/WebVttSub.cs +++ b/src/N_m3u8DL-RE.Common/Entity/WebVttSub.cs @@ -152,14 +152,19 @@ namespace N_m3u8DL_RE.Common.Entity } //确实存在时间轴错误的情况,才修复 - if ((this.Cues.Count > 0 && sub.Cues.Count > 0 && sub.Cues.First().StartTime < this.Cues.Last().EndTime) || this.Cues.Count == 0) + if ((this.Cues.Count > 0 && sub.Cues.Count > 0 && sub.Cues.First().StartTime < this.Cues.Last().EndTime && sub.Cues.First().EndTime != this.Cues.Last().EndTime) || this.Cues.Count == 0) { //The MPEG2 transport stream clocks (PCR, PTS, DTS) all have units of 1/90000 second var seconds = (sub.MpegtsTimestamp - baseTimestamp) / 90000; - for (int i = 0; i < sub.Cues.Count; i++) + var offset = TimeSpan.FromSeconds(seconds); + //当前预添加的字幕的起始时间小于实际上已经走过的时间(如offset已经是100秒,而字幕起始却是2秒),才修复 + if (sub.Cues.Count > 0 && sub.Cues.First().StartTime < offset) { - sub.Cues[i].StartTime += TimeSpan.FromSeconds(seconds); - sub.Cues[i].EndTime += TimeSpan.FromSeconds(seconds); + for (int i = 0; i < sub.Cues.Count; i++) + { + sub.Cues[i].StartTime += offset; + sub.Cues[i].EndTime += offset; + } } } } diff --git a/src/N_m3u8DL-RE/CommandLine/CommandInvoker.cs b/src/N_m3u8DL-RE/CommandLine/CommandInvoker.cs index 4ab2ddb..ea56b07 100644 --- a/src/N_m3u8DL-RE/CommandLine/CommandInvoker.cs +++ b/src/N_m3u8DL-RE/CommandLine/CommandInvoker.cs @@ -18,7 +18,7 @@ namespace N_m3u8DL_RE.CommandLine { internal partial class CommandInvoker { - public const string VERSION_INFO = "N_m3u8DL-RE (Beta version) 20221210"; + public const string VERSION_INFO = "N_m3u8DL-RE (Beta version) 20221211"; [GeneratedRegex("((best|worst)\\d*|all)")] private static partial Regex ForStrRegex();