|
|
@@ -26,13 +26,13 @@ import (
|
|
|
)
|
|
|
|
|
|
type SubTimelineFixer struct {
|
|
|
- fixerConfig sub_timeline_fiexer.SubTimelineFixerConfig
|
|
|
+ FixerConfig sub_timeline_fiexer.SubTimelineFixerConfig
|
|
|
ffmpegHelper *ffmpeg_helper.FFMPEGHelper
|
|
|
}
|
|
|
|
|
|
func NewSubTimelineFixer(fixerConfig sub_timeline_fiexer.SubTimelineFixerConfig) *SubTimelineFixer {
|
|
|
return &SubTimelineFixer{
|
|
|
- fixerConfig: fixerConfig,
|
|
|
+ FixerConfig: fixerConfig,
|
|
|
ffmpegHelper: ffmpeg_helper.NewFFMPEGHelper(),
|
|
|
}
|
|
|
}
|
|
|
@@ -143,7 +143,7 @@ func (s *SubTimelineFixer) GetOffsetTimeV1(infoBase, infoSrc *subparser.FileInfo
|
|
|
/*
|
|
|
确认两个字幕间的偏移,暂定的方案是两边都连续匹配上 5 个索引,再抽取一个对话的时间进行修正计算
|
|
|
*/
|
|
|
- maxCompareDialogue := s.fixerConfig.MaxCompareDialogue
|
|
|
+ maxCompareDialogue := s.FixerConfig.MaxCompareDialogue
|
|
|
// 基线的长度
|
|
|
_, docsLength := tfidf.Dims()
|
|
|
var matchIndexList = make([]MatchIndex, 0)
|
|
|
@@ -337,14 +337,14 @@ func (s *SubTimelineFixer) GetOffsetTimeV1(infoBase, infoSrc *subparser.FileInfo
|
|
|
matchIndexLineCount := len(matchIndexList) * maxCompareDialogue
|
|
|
//perMatch := float64(matchIndexLineCount) / float64(len(infoSrc.DialoguesEx))
|
|
|
perMatch := float64(matchIndexLineCount) / float64(len(baseCorpus))
|
|
|
- if perMatch < s.fixerConfig.MinMatchedPercent {
|
|
|
- tmpContent := infoSrc.Name + fmt.Sprintf(" Sequence match %d dialogues (< %f%%), Skip,", s.fixerConfig.MaxCompareDialogue, s.fixerConfig.MinMatchedPercent*100) + fmt.Sprintf(" %f%% ", perMatch*100)
|
|
|
+ if perMatch < s.FixerConfig.MinMatchedPercent {
|
|
|
+ tmpContent := infoSrc.Name + fmt.Sprintf(" Sequence match %d dialogues (< %f%%), Skip,", s.FixerConfig.MaxCompareDialogue, s.FixerConfig.MinMatchedPercent*100) + fmt.Sprintf(" %f%% ", perMatch*100)
|
|
|
|
|
|
debugInfos = append(debugInfos, tmpContent)
|
|
|
|
|
|
log_helper.GetLogger().Infoln(tmpContent)
|
|
|
} else {
|
|
|
- tmpContent := infoSrc.Name + fmt.Sprintf(" Sequence match %d dialogues,", s.fixerConfig.MaxCompareDialogue) + fmt.Sprintf(" %f%% ", perMatch*100)
|
|
|
+ tmpContent := infoSrc.Name + fmt.Sprintf(" Sequence match %d dialogues,", s.FixerConfig.MaxCompareDialogue) + fmt.Sprintf(" %f%% ", perMatch*100)
|
|
|
|
|
|
debugInfos = append(debugInfos, tmpContent)
|
|
|
|
|
|
@@ -359,7 +359,7 @@ func (s *SubTimelineFixer) GetOffsetTimeV1(infoBase, infoSrc *subparser.FileInfo
|
|
|
}
|
|
|
}
|
|
|
// 虽然有条件判断是认为有问题的,但是返回值还是要填写除去的
|
|
|
- if perMatch < s.fixerConfig.MinMatchedPercent {
|
|
|
+ if perMatch < s.FixerConfig.MinMatchedPercent {
|
|
|
return false, newMean, newSd, nil
|
|
|
}
|
|
|
|
|
|
@@ -396,12 +396,12 @@ func (s *SubTimelineFixer) GetOffsetTimeV2(baseUnit, srcUnit *sub_helper.SubUnit
|
|
|
|
|
|
srcVADLen := len(srcUnit.VADList)
|
|
|
// 滑动窗口的长度
|
|
|
- srcWindowLen := int(float64(srcVADLen) * MatchPer)
|
|
|
+ srcWindowLen := int(float64(srcVADLen) * s.FixerConfig.MatchPer)
|
|
|
srcSlideLen := srcVADLen - srcWindowLen
|
|
|
// 窗口可以滑动的长度
|
|
|
srcSlideLenHalf := srcSlideLen / 2
|
|
|
//
|
|
|
- oneStep := srcSlideLenHalf / CompareParts
|
|
|
+ oneStep := srcSlideLenHalf / s.FixerConfig.CompareParts
|
|
|
if srcSlideLen <= 0 {
|
|
|
srcSlideLen = 1
|
|
|
}
|
|
|
@@ -425,7 +425,7 @@ func (s *SubTimelineFixer) GetOffsetTimeV2(baseUnit, srcUnit *sub_helper.SubUnit
|
|
|
if bUseSubOrAudioAsBase == false {
|
|
|
// 使用 音频 来进行匹配
|
|
|
// 去掉头和尾,具体百分之多少,见 FrontAndEndPerBase
|
|
|
- audioCutLen := int(float64(len(inData.AudioVADList)) * FrontAndEndPerBase)
|
|
|
+ audioCutLen := int(float64(len(inData.AudioVADList)) * s.FixerConfig.FrontAndEndPerBase)
|
|
|
|
|
|
offsetIndex, score = fffAligner.Fit(inData.AudioVADList[audioCutLen:len(inData.AudioVADList)-audioCutLen], inData.SrcUnit.GetVADFloatSlice()[inData.OffsetIndex:srcWindowLen+inData.OffsetIndex])
|
|
|
realOffsetIndex := offsetIndex + audioCutLen
|
|
|
@@ -466,10 +466,10 @@ func (s *SubTimelineFixer) GetOffsetTimeV2(baseUnit, srcUnit *sub_helper.SubUnit
|
|
|
return nil
|
|
|
}
|
|
|
// -------------------------------------------------
|
|
|
- antPool, err := ants.NewPoolWithFunc(FixThreads, func(inData interface{}) {
|
|
|
+ antPool, err := ants.NewPoolWithFunc(s.FixerConfig.FixThreads, func(inData interface{}) {
|
|
|
data := inData.(InputData)
|
|
|
defer data.Wg.Done()
|
|
|
- ctx, cancel := context.WithTimeout(context.Background(), SubOneUnitProcessTimeOut)
|
|
|
+ ctx, cancel := context.WithTimeout(context.Background(), time.Duration(s.FixerConfig.SubOneUnitProcessTimeOut)*time.Second)
|
|
|
defer cancel()
|
|
|
|
|
|
done := make(chan error, 1)
|
|
|
@@ -523,7 +523,7 @@ func (s *SubTimelineFixer) GetOffsetTimeV2(baseUnit, srcUnit *sub_helper.SubUnit
|
|
|
}
|
|
|
wg.Wait()
|
|
|
// 这里可能遇到匹配的时候没有能够执行够 CompareParts 次,有可能是负数跳过或者时间转换失败导致,前者为主(可能是这两个就是一个东西的时候,或者说没有时间轴偏移的时候)
|
|
|
- if insertIndex < CompareParts/2 {
|
|
|
+ if insertIndex < s.FixerConfig.CompareParts/2 {
|
|
|
return false, 0, 0, nil
|
|
|
}
|
|
|
outCorrelationFixResult := s.calcMeanAndSD(tmpStartDiffTimeListEx, tmpStartDiffTimeList)
|
|
|
@@ -601,14 +601,6 @@ func (s *SubTimelineFixer) calcMeanAndSD(startDiffTimeList stat.Float64Slice, tm
|
|
|
}
|
|
|
|
|
|
const FixMask = "-fix"
|
|
|
-const SubOneUnitProcessTimeOut = 60 * 5 * time.Second // 字幕时间轴校正一个单元的超时时间
|
|
|
-
|
|
|
-// 字幕匹配字幕 GetVADInfoFeatureFromSubNew
|
|
|
-const FrontAndEndPerBase = 0.15 // 前百分之 15 和后百分之 15 都不进行识别
|
|
|
-const FrontAndEndPerSrc = 0.0 // 前百分之 20 和后百分之 20 都不进行识别
|
|
|
-const MatchPer = 0.7
|
|
|
-const CompareParts = 5
|
|
|
-const FixThreads = 3 // 字幕校正的并发线程
|
|
|
|
|
|
var mutexFixV2 sync.Mutex
|
|
|
|