优化VTT时间轴偏移的自动处理逻辑
This commit is contained in:
parent
ddd3931f57
commit
e6371f2b56
|
@ -111,18 +111,33 @@ namespace N_m3u8DL_RE.Common.Entity
|
||||||
FixTimestamp(webSub, this.MpegtsTimestamp);
|
FixTimestamp(webSub, this.MpegtsTimestamp);
|
||||||
foreach (var item in webSub.Cues)
|
foreach (var item in webSub.Cues)
|
||||||
{
|
{
|
||||||
if (!this.Cues.Contains(item)) this.Cues.Add(item);
|
if (!this.Cues.Contains(item))
|
||||||
|
{
|
||||||
|
//如果相差只有1ms,且payload相同,则拼接
|
||||||
|
var last = this.Cues.LastOrDefault();
|
||||||
|
if (last != null && this.Cues.Count > 0 && (item.StartTime - last.EndTime).TotalMilliseconds <= 1 && item.Payload == last.Payload)
|
||||||
|
{
|
||||||
|
last.EndTime = item.EndTime;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
this.Cues.Add(item);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void FixTimestamp(WebVttSub sub, long baseTimestamp)
|
private void FixTimestamp(WebVttSub sub, long baseTimestamp)
|
||||||
{
|
{
|
||||||
if (baseTimestamp == 0 || sub.MpegtsTimestamp == 0)
|
if (sub.MpegtsTimestamp == 0)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//确实存在时间轴错误的情况,才修复
|
||||||
|
if ((this.Cues.Count > 0 && sub.Cues.Count > 0 && sub.Cues.First().StartTime < this.Cues.Last().EndTime) || this.Cues.Count == 0)
|
||||||
|
{
|
||||||
//The MPEG2 transport stream clocks (PCR, PTS, DTS) all have units of 1/90000 second
|
//The MPEG2 transport stream clocks (PCR, PTS, DTS) all have units of 1/90000 second
|
||||||
var seconds = (sub.MpegtsTimestamp - baseTimestamp) / 90000;
|
var seconds = (sub.MpegtsTimestamp - baseTimestamp) / 90000;
|
||||||
for (int i = 0; i < sub.Cues.Count; i++)
|
for (int i = 0; i < sub.Cues.Count; i++)
|
||||||
|
@ -131,6 +146,7 @@ namespace N_m3u8DL_RE.Common.Entity
|
||||||
sub.Cues[i].EndTime += TimeSpan.FromSeconds(seconds);
|
sub.Cues[i].EndTime += TimeSpan.FromSeconds(seconds);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private static TimeSpan ConvertToTS(string str)
|
private static TimeSpan ConvertToTS(string str)
|
||||||
{
|
{
|
||||||
|
|
|
@ -132,6 +132,11 @@ namespace N_m3u8DL_RE.DownloadManager
|
||||||
{
|
{
|
||||||
var vttContent = File.ReadAllText(FileDic[seg]!.ActualFilePath);
|
var vttContent = File.ReadAllText(FileDic[seg]!.ActualFilePath);
|
||||||
var vtt = WebVttSub.Parse(vttContent);
|
var vtt = WebVttSub.Parse(vttContent);
|
||||||
|
//手动计算MPEGTS
|
||||||
|
if (finalVtt.MpegtsTimestamp == 0 && vtt.MpegtsTimestamp == 0)
|
||||||
|
{
|
||||||
|
vtt.MpegtsTimestamp = 90 * (long)(seg.Duration * 1000) * seg.Index;
|
||||||
|
}
|
||||||
if (first)
|
if (first)
|
||||||
{
|
{
|
||||||
finalVtt = vtt;
|
finalVtt = vtt;
|
||||||
|
|
Loading…
Reference in New Issue