feat(flv): split data group on timestamp jump

This commit is contained in:
genteure 2022-08-29 12:15:43 +08:00
parent 4472ad5d53
commit ca17ee15f3

View File

@ -1,4 +1,5 @@
using System.Collections.Generic;
using System.Linq;
using BililiveRecorder.Flv.Pipeline.Actions;
namespace BililiveRecorder.Flv.Grouping.Rules
@ -8,8 +9,8 @@ namespace BililiveRecorder.Flv.Grouping.Rules
public bool CanStartWith(Tag tag) => tag.IsData();
public bool CanAppendWith(Tag tag, List<Tag> tags) =>
// Tag 是非关键帧数据
tag.IsNonKeyframeData()
// Tag 是非关键帧数据,并且与前一个 Tag 的时间戳差距不超过 25 秒
(tag.IsNonKeyframeData() && (tags.LastOrDefault() is not Tag lastTag || (tag.Timestamp - lastTag.Timestamp < 24999)))
// 或:是关键帧,并且之前只有音频数据
|| (tag.Type == TagType.Video && tag.IsKeyframeData() && tags.TrueForAll(x => x.Type == TagType.Audio))
// 或:是音频头,并且之前未出现过音频数据