Sfoglia il codice sorgente

新增一个配置字段,设置最大的时间轴校正的偏移支持,默认 120s,最小也是这个值

Signed-off-by: allan716 <[email protected]>
allan716 3 anni fa
parent
commit
3144b6ea4c

+ 1 - 1
internal/logic/sub_timeline_fixer/SubTimelineFixerHelperEx.go

@@ -29,7 +29,7 @@ func NewSubTimelineFixerHelperEx(fixerConfig sub_timeline_fiexer.SubTimelineFixe
 	return &SubTimelineFixerHelperEx{
 	return &SubTimelineFixerHelperEx{
 		ffmpegHelper:        ffmpeg_helper.NewFFMPEGHelper(),
 		ffmpegHelper:        ffmpeg_helper.NewFFMPEGHelper(),
 		subParserHub:        sub_parser_hub.NewSubParserHub(ass.NewParser(), srt.NewParser()),
 		subParserHub:        sub_parser_hub.NewSubParserHub(ass.NewParser(), srt.NewParser()),
-		timelineFixPipeLine: sub_timeline_fixer.NewPipeline(sub_timeline_fixer.DefaultMaxOffsetSeconds),
+		timelineFixPipeLine: sub_timeline_fixer.NewPipeline(fixerConfig.V2_MaxOffsetTime),
 		fixerConfig:         fixerConfig,
 		fixerConfig:         fixerConfig,
 		needDownloadFFMPeg:  false,
 		needDownloadFFMPeg:  false,
 	}
 	}

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

@@ -240,7 +240,7 @@ var FramerateRatios = []float64{24. / 23.976, 25. / 23.976, 25. / 24.}
 
 
 const MinFramerateRatio = 0.9
 const MinFramerateRatio = 0.9
 const MaxFramerateRatio = 1.1
 const MaxFramerateRatio = 1.1
-const DefaultMaxOffsetSeconds = 60
+const DefaultMaxOffsetSeconds = 120
 const SampleRate = 100
 const SampleRate = 100
 
 
 type PipeResult struct {
 type PipeResult struct {

+ 28 - 27
internal/pkg/sub_timeline_fixer/pipeline_test.go

@@ -33,35 +33,36 @@ func TestPipeline_FitGSS(t *testing.T) {
 		wantErr bool
 		wantErr bool
 	}{
 	}{
 		{name: "BL S01E03", args: args{
 		{name: "BL S01E03", args: args{
-			baseSubFile:      "C:\\Tmp\\BL - S01E03\\英_2.ass",
-			ffsubSyncSubFile: "C:\\Tmp\\BL - S01E03\\ffsubsync.ass",
-			srcSubFile:       "C:\\Tmp\\BL - S01E03\\org.ass",
-			srcFixedSubFile:  "C:\\Tmp\\BL - S01E03\\org-fix.ass",
+			baseSubFile:      "C:\\Tmp\\fixsubtimeline\\BL - S01E03\\英_2.ass",
+			ffsubSyncSubFile: "C:\\Tmp\\fixsubtimeline\\BL - S01E03\\ffsubsync.ass",
+			srcSubFile:       "C:\\Tmp\\fixsubtimeline\\BL - S01E03\\org.ass",
+			srcFixedSubFile:  "C:\\Tmp\\fixsubtimeline\\BL - S01E03\\org-fix.ass",
 		}, want: -4.290000, wantErr: false},
 		}, want: -4.290000, wantErr: false},
 		{name: "Rick and Morty - S05E01", args: args{
 		{name: "Rick and Morty - S05E01", args: args{
-			baseSubFile:      "C:\\Tmp\\Rick and Morty - S05E01\\英_2.ass",
-			ffsubSyncSubFile: "C:\\Tmp\\Rick and Morty - S05E01\\ffsubsync.ass",
-			srcSubFile:       "C:\\Tmp\\Rick and Morty - S05E01\\org.ass",
-			srcFixedSubFile:  "C:\\Tmp\\Rick and Morty - S05E01\\org-fix.ass",
+			baseSubFile:      "C:\\Tmp\\fixsubtimeline\\Rick and Morty - S05E01\\英_2.ass",
+			ffsubSyncSubFile: "C:\\Tmp\\fixsubtimeline\\Rick and Morty - S05E01\\ffsubsync.ass",
+			srcSubFile:       "C:\\Tmp\\fixsubtimeline\\Rick and Morty - S05E01\\org.ass",
+			srcFixedSubFile:  "C:\\Tmp\\fixsubtimeline\\Rick and Morty - S05E01\\org-fix.ass",
 		}, want: -6.170000, wantErr: false},
 		}, want: -6.170000, wantErr: false},
 		{name: "Rick and Morty - S05E10", args: args{
 		{name: "Rick and Morty - S05E10", args: args{
-			baseSubFile:      "C:\\Tmp\\Rick and Morty - S05E10\\英_2.ass",
-			ffsubSyncSubFile: "C:\\Tmp\\Rick and Morty - S05E10\\ffsubsync.ass",
-			srcSubFile:       "C:\\Tmp\\Rick and Morty - S05E10\\org.ass",
-			srcFixedSubFile:  "C:\\Tmp\\Rick and Morty - S05E10\\org-fix.ass",
+			baseSubFile:      "C:\\Tmp\\fixsubtimeline\\Rick and Morty - S05E10\\英_2.ass",
+			ffsubSyncSubFile: "C:\\Tmp\\fixsubtimeline\\Rick and Morty - S05E10\\ffsubsync.ass",
+			srcSubFile:       "C:\\Tmp\\fixsubtimeline\\Rick and Morty - S05E10\\org.ass",
+			srcFixedSubFile:  "C:\\Tmp\\fixsubtimeline\\Rick and Morty - S05E10\\org-fix.ass",
 		}, want: -6.020000, wantErr: false},
 		}, want: -6.020000, wantErr: false},
 		{name: "Foundation - S01E09", args: args{
 		{name: "Foundation - S01E09", args: args{
-			baseSubFile:      "C:\\Tmp\\Foundation - S01E09\\英_2.ass",
-			ffsubSyncSubFile: "C:\\Tmp\\Foundation - S01E09\\ffsubsync.ass",
-			srcSubFile:       "C:\\Tmp\\Foundation - S01E09\\org.ass",
-			srcFixedSubFile:  "C:\\Tmp\\Foundation - S01E09\\org-fix.ass",
+			baseSubFile:      "C:\\Tmp\\fixsubtimeline\\Foundation - S01E09\\英_2.ass",
+			ffsubSyncSubFile: "C:\\Tmp\\fixsubtimeline\\Foundation - S01E09\\ffsubsync.ass",
+			srcSubFile:       "C:\\Tmp\\fixsubtimeline\\Foundation - S01E09\\org.ass",
+			srcFixedSubFile:  "C:\\Tmp\\fixsubtimeline\\Foundation - S01E09\\org-fix.ass",
 		}, want: -29.890000, wantErr: false},
 		}, want: -29.890000, wantErr: false},
-		//{name: "mix", args: args{
-		//	baseSubFile: "C:\\Tmp\\Rick and Morty - S05E10\\英_2.ass",
-		//	srcSubFile:  "C:\\Tmp\\BL - S01E03\\org.ass",
-		//}, want: -4.1, wantErr: false},
+		{name: "Foundation - S01E09", args: args{
+			baseSubFile:      "C:\\Tmp\\fixsubtimeline\\Yellowstone S04E05\\英_2.ass",
+			ffsubSyncSubFile: "C:\\Tmp\\fixsubtimeline\\Yellowstone S04E05\\ffsubsync.ass",
+			srcSubFile:       "C:\\Tmp\\fixsubtimeline\\Yellowstone S04E05\\org.ass",
+			srcFixedSubFile:  "C:\\Tmp\\fixsubtimeline\\Yellowstone S04E05\\org-fix.ass",
+		}, want: -62.84, wantErr: false},
 	}
 	}
-
 	for _, tt := range tests {
 	for _, tt := range tests {
 		t.Run(tt.name, func(t *testing.T) {
 		t.Run(tt.name, func(t *testing.T) {
 
 
@@ -124,20 +125,20 @@ func TestPipeline_FitGSSByAudio(t *testing.T) {
 		{name: "Rick and Morty - S05E01 -- 0",
 		{name: "Rick and Morty - S05E01 -- 0",
 			args: args{
 			args: args{
 				audioInfo: vad.AudioInfo{
 				audioInfo: vad.AudioInfo{
-					FileFullPath: "C:\\Tmp\\Rick and Morty - S05E01\\未知语言_1.pcm",
+					FileFullPath: "C:\\Tmp\\fixsubtimeline\\Rick and Morty - S05E01\\未知语言_1.pcm",
 				},
 				},
-				subFilePath:     "C:\\Tmp\\Rick and Morty - S05E01\\英_2.ass",
-				srcFixedSubFile: "C:\\Tmp\\Rick and Morty - S05E01\\org-fix.ass"},
+				subFilePath:     "C:\\Tmp\\fixsubtimeline\\Rick and Morty - S05E01\\英_2.ass",
+				srcFixedSubFile: "C:\\Tmp\\fixsubtimeline\\Rick and Morty - S05E01\\org-fix.ass"},
 			want: true, want1: 0.33,
 			want: true, want1: 0.33,
 		},
 		},
 		// Rick and Morty - S05E01
 		// Rick and Morty - S05E01
 		{name: "Rick and Morty - S05E01 -- 1",
 		{name: "Rick and Morty - S05E01 -- 1",
 			args: args{
 			args: args{
 				audioInfo: vad.AudioInfo{
 				audioInfo: vad.AudioInfo{
-					FileFullPath: "C:\\Tmp\\Rick and Morty - S05E01\\未知语言_1.pcm",
+					FileFullPath: "C:\\Tmp\\fixsubtimeline\\Rick and Morty - S05E01\\未知语言_1.pcm",
 				},
 				},
-				subFilePath:     "C:\\Tmp\\Rick and Morty - S05E01\\org.ass",
-				srcFixedSubFile: "C:\\Tmp\\Rick and Morty - S05E01\\org-fix.ass"},
+				subFilePath:     "C:\\Tmp\\fixsubtimeline\\Rick and Morty - S05E01\\org.ass",
+				srcFixedSubFile: "C:\\Tmp\\fixsubtimeline\\Rick and Morty - S05E01\\org-fix.ass"},
 			want: true, want1: -6.1,
 			want: true, want1: -6.1,
 		},
 		},
 	}
 	}

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

@@ -15,6 +15,7 @@ type SubTimelineFixerConfig struct {
 	V2_FixThreads               int     // 字幕校正的并发线程
 	V2_FixThreads               int     // 字幕校正的并发线程
 	V2_MaxStartTimeDiffSD       float64 // 对白开始时间的统计 SD 最大误差,超过则不进行修正
 	V2_MaxStartTimeDiffSD       float64 // 对白开始时间的统计 SD 最大误差,超过则不进行修正
 	V2_MinOffset                float64 // 超过这个(+-)偏移的时间轴才校正,否则跳过,单位秒
 	V2_MinOffset                float64 // 超过这个(+-)偏移的时间轴才校正,否则跳过,单位秒
+	V2_MaxOffsetTime            int     // 最大可以校正的时间偏移,时间是秒
 }
 }
 
 
 // CheckDefault 检测默认值(比如某些之默认不能为0),不对就重置到默认值上
 // CheckDefault 检测默认值(比如某些之默认不能为0),不对就重置到默认值上
@@ -57,4 +58,8 @@ func (s *SubTimelineFixerConfig) CheckDefault() {
 	if s.V2_MinOffset <= 0 {
 	if s.V2_MinOffset <= 0 {
 		s.V2_MinOffset = 0.3
 		s.V2_MinOffset = 0.3
 	}
 	}
+
+	if s.V2_MaxOffsetTime <= 0 {
+		s.V2_MaxOffsetTime = 120
+	}
 }
 }