Browse Source

调整,FixConfig 的设置校验

Signed-off-by: allan716 <[email protected]>
allan716 4 years ago
parent
commit
00a893ac08

+ 1 - 1
internal/pkg/sub_timeline_fixer/fixer.go

@@ -396,7 +396,7 @@ func (s *SubTimelineFixer) GetOffsetTimeV2(baseUnit, srcUnit *sub_helper.SubUnit
 
 	srcVADLen := len(srcUnit.VADList)
 	// 滑动窗口的长度
-	srcWindowLen := int(float64(srcVADLen) * s.FixerConfig.MatchPer)
+	srcWindowLen := int(float64(srcVADLen) * s.FixerConfig.WindowMatchPer)
 	srcSlideLen := srcVADLen - srcWindowLen
 	// 窗口可以滑动的长度
 	srcSlideLenHalf := srcSlideLen / 2

+ 1 - 1
internal/pkg/sub_timeline_fixer/fixer_test.go

@@ -798,7 +798,7 @@ var timelineFixer = NewSubTimelineFixer(sub_timeline_fiexer.SubTimelineFixerConf
 	SubOneUnitProcessTimeOut: 5 * 60,
 	FrontAndEndPerBase:       0.15,
 	FrontAndEndPerSrc:        0.0,
-	MatchPer:                 0.7,
+	WindowMatchPer:           0.7,
 	CompareParts:             5,
 	FixThreads:               3,
 })

+ 25 - 5
internal/types/sub_timeline_fiexer/sub_timeline_fixer_config.go

@@ -10,23 +10,43 @@ type SubTimelineFixerConfig struct {
 	SubOneUnitProcessTimeOut int     // 字幕时间轴校正一个单元的超时时间,单位秒
 	FrontAndEndPerBase       float64 // 前百分之 15 和后百分之 15 都不进行识别
 	FrontAndEndPerSrc        float64 // 前百分之 20 和后百分之 20 都不进行识别
-	MatchPer                 float64 // SrcSub 滑动窗体的占比
+	WindowMatchPer           float64 // SrcSub 滑动窗体的占比
 	CompareParts             int     // 滑动窗体分段次数
 	FixThreads               int     // 字幕校正的并发线程
 }
 
 // CheckDefault 检测默认值(比如某些之默认不能为0),不对就重置到默认值上
 func (s *SubTimelineFixerConfig) CheckDefault() {
-	if s.MaxCompareDialogue == 0 {
+	// V1
+	if s.MaxCompareDialogue <= 0 {
 		s.MaxCompareDialogue = 3
 	}
-	if s.MaxStartTimeDiffSD == 0 {
+	if s.MaxStartTimeDiffSD <= 0 {
 		s.MaxStartTimeDiffSD = 0.1
 	}
-	if s.MinMatchedPercent == 0 {
+	if s.MinMatchedPercent <= 0 {
 		s.MinMatchedPercent = 0.1
 	}
-	if s.MinOffset == 0 {
+	if s.MinOffset <= 0 {
 		s.MinOffset = 0.1
 	}
+	// V2
+	if s.SubOneUnitProcessTimeOut <= 0 {
+		s.SubOneUnitProcessTimeOut = 30
+	}
+	if s.FrontAndEndPerBase <= 0 || s.FrontAndEndPerBase >= 1.0 {
+		s.FrontAndEndPerBase = 0.15
+	}
+	if s.FrontAndEndPerSrc <= 0 || s.FrontAndEndPerSrc >= 1.0 {
+		s.FrontAndEndPerSrc = 0.0
+	}
+	if s.WindowMatchPer <= 0 || s.WindowMatchPer >= 1.0 {
+		s.WindowMatchPer = 0.7
+	}
+	if s.CompareParts <= 0 {
+		s.CompareParts = 5
+	}
+	if s.CompareParts <= 0 {
+		s.CompareParts = 3
+	}
 }