1
0
Эх сурвалжийг харах

测试修复时间轴

Signed-off-by: allan716 <[email protected]>
allan716 2 жил өмнө
parent
commit
d596c8296f

+ 65 - 51
cmd/subtimelinefixer/main.go

@@ -1,20 +1,12 @@
 package main
 
 import (
-	"log"
-	"os"
-	"strings"
 	"time"
 
 	"github.com/ChineseSubFinder/ChineseSubFinder/pkg"
 
-	"github.com/ChineseSubFinder/ChineseSubFinder/pkg/logic/sub_timeline_fixer"
-
 	"github.com/ChineseSubFinder/ChineseSubFinder/pkg/log_helper"
-	"github.com/ChineseSubFinder/ChineseSubFinder/pkg/settings"
 	"github.com/sirupsen/logrus"
-
-	"github.com/urfave/cli/v2"
 )
 
 /*
@@ -42,51 +34,73 @@ func newLog() *logrus.Logger {
 
 func main() {
 
-	var videoPath string
-	var subtitlesPath string
+	//var videoPath string
+	//var subtitlesPath string
 
 	loggerBase = newLog()
 
-	app := &cli.App{
-		Name:  "Subtitle Timeline Fixer",
-		Usage: "Fix the subtitle timeline according to the video",
-		Flags: []cli.Flag{
-			&cli.StringFlag{
-				Name:        "videoPath",
-				Aliases:     []string{"vp"},
-				Usage:       "Specify `video file path`",
-				Destination: &videoPath,
-				Required:    true,
-			},
-
-			&cli.StringFlag{
-				Name:        "subtitlesPath",
-				Aliases:     []string{"sp"},
-				Usage:       "Specify `subtitles file path`",
-				Destination: &subtitlesPath,
-				Required:    true,
-			},
-		},
-		Action: func(c *cli.Context) error {
-			videoPath = strings.TrimSpace(videoPath)
-			subtitlesPath = strings.TrimSpace(subtitlesPath)
-			if videoPath != "" && subtitlesPath != "" {
-				var fixerSetting = settings.NewTimelineFixerSettings()
-				var subTimelineFixerHelper = sub_timeline_fixer.NewSubTimelineFixerHelperEx(loggerBase, *fixerSetting)
-				if subTimelineFixerHelper.Check() {
-					subTimelineFixerHelper.Process(videoPath, subtitlesPath)
-				} else {
-					println("check subtitles timeline fixer helper failed.")
-				}
-			} else {
-				println("need provide video path (-vp) and subtitle path (-sp)")
-			}
-			return nil
-		},
-	}
+	//videoPath = "X:\\连续剧\\All Creatures Great and Small (2020)\\Season 1\\All Creatures Great and Small (2020) - S01E04 - A Tricki Case WEBDL-1080p.mkv"
+	////videoPath = "X:\\连续剧\\All Creatures Great and Small (2020)\\Season 1\\All Creatures Great and Small (2020) - S01E05 - All's Fair WEBDL-1080p.mkv"
+	////subtitlesPath = "D:\\Subtitle\\123.ass"
+	////subtitlesPath = "D:\\Subtitle\\123.srt"
+	////subtitlesPath = "D:\\Subtitle\\英_2.srt"
+	//subtitlesPath = "D:\\Subtitle\\All Creatures Great and Small (2020) - S01E04 - A Tricki Case WEBDL-1080p.chinese(简,manual).default.srt"
+	//
+	//var fixerSetting = settings.NewTimelineFixerSettings()
+	//fixerSetting.ThreadCount = 1
+	//fixerSetting.MinOffset = 3
+	//var subTimelineFixerHelper = sub_timeline_fixer.NewSubTimelineFixerHelperEx(loggerBase, *fixerSetting)
+	//if subTimelineFixerHelper.Check() {
+	//	err := subTimelineFixerHelper.Process(videoPath, subtitlesPath, sub_timeline_fixer.ProcessTypeByAudioFile)
+	//	if err != nil {
+	//		println(err)
+	//	}
+	//} else {
+	//	println("check subtitles timeline fixer helper failed.")
+	//}
+	//
+	//println("Done.")
 
-	err := app.Run(os.Args)
-	if err != nil {
-		log.Fatal(err)
-	}
+	//app := &cli.App{
+	//	Name:  "Subtitle Timeline Fixer",
+	//	Usage: "Fix the subtitle timeline according to the video",
+	//	Flags: []cli.Flag{
+	//		&cli.StringFlag{
+	//			Name:        "videoPath",
+	//			Aliases:     []string{"vp"},
+	//			Usage:       "Specify `video file path`",
+	//			Destination: &videoPath,
+	//			Required:    true,
+	//		},
+	//
+	//		&cli.StringFlag{
+	//			Name:        "subtitlesPath",
+	//			Aliases:     []string{"sp"},
+	//			Usage:       "Specify `subtitles file path`",
+	//			Destination: &subtitlesPath,
+	//			Required:    true,
+	//		},
+	//	},
+	//	Action: func(c *cli.Context) error {
+	//		videoPath = strings.TrimSpace(videoPath)
+	//		subtitlesPath = strings.TrimSpace(subtitlesPath)
+	//		if videoPath != "" && subtitlesPath != "" {
+	//			var fixerSetting = settings.NewTimelineFixerSettings()
+	//			var subTimelineFixerHelper = sub_timeline_fixer.NewSubTimelineFixerHelperEx(loggerBase, *fixerSetting)
+	//			if subTimelineFixerHelper.Check() {
+	//				subTimelineFixerHelper.Process(videoPath, subtitlesPath)
+	//			} else {
+	//				println("check subtitles timeline fixer helper failed.")
+	//			}
+	//		} else {
+	//			println("need provide video path (-vp) and subtitle path (-sp)")
+	//		}
+	//		return nil
+	//	},
+	//}
+	//
+	//err := app.Run(os.Args)
+	//if err != nil {
+	//	log.Fatal(err)
+	//}
 }

+ 15 - 0
pkg/sub_timeline_fixer/pipeline.go

@@ -39,6 +39,21 @@ func (p *Pipeline) CalcOffsetTime(infoBase, infoSrc *subparser.FileInfo, audioVa
 
 	if infoBase == nil && audioVadList != nil {
 		baseVADInfo = vad.GetFloatSlice(audioVadList, skipFrontAndEndPerBase)
+		//
+		//err := vad.WriteVADSlice2File(baseVADInfo, "D:\\tmp\\audio.txt")
+		//if err != nil {
+		//	return PipeResult{}, err
+		//}
+		//baseUnitNew, err := sub_helper.GetVADInfoFeatureFromSubNew(infoSrc, skipFrontAndEndPerBase)
+		//if err != nil {
+		//	return PipeResult{}, err
+		//}
+		//baseVADInfo = baseUnitNew.GetVADFloatSlice()
+		//err = vad.WriteVADSlice2File(baseVADInfo, "D:\\tmp\\subtitle.txt")
+		//if err != nil {
+		//	return PipeResult{}, err
+		//}
+		//
 		useSubtitleOrAudioAsBase = true
 	} else if infoBase != nil {
 		useSubtitleOrAudioAsBase = false

+ 17 - 0
pkg/vad/vad_helper.go

@@ -112,6 +112,23 @@ func GetFloatSlice(inVADs []VADInfo, skipFrontAndEndPerBase float64) []float64 {
 	return outVADFloats[skipStartIndex:skipEndIndex]
 }
 
+func WriteVADSlice2File(vadSliceFloat []float64, fileFullPath string) error {
+	f, err := os.Create(fileFullPath)
+	if err != nil {
+		return err
+	}
+	defer f.Close()
+
+	for _, v := range vadSliceFloat {
+		_, err = f.WriteString(fmt.Sprintf("%v\n", v))
+		if err != nil {
+			return err
+		}
+	}
+
+	return nil
+}
+
 // GetAudioIndex2Time 从 Audio 的 OffsetIndex 推算出它所在的时间,返回 float64 的秒
 func GetAudioIndex2Time(index int) float64 {
 	return float64(index*FrameDuration) / 1000.0