From 84a3dd05d1623d61e694d3f763c3121be3b9b43c Mon Sep 17 00:00:00 2001 From: Grail Finder Date: Thu, 16 Feb 2023 15:35:14 +0600 Subject: Feat: filter out bad times --- ffmpeg.go | 7 ++----- main.go | 34 +++++++++++++--------------------- 2 files changed, 15 insertions(+), 26 deletions(-) diff --git a/ffmpeg.go b/ffmpeg.go index 77a2195..329ae01 100644 --- a/ffmpeg.go +++ b/ffmpeg.go @@ -6,7 +6,7 @@ import ( ffmpeg "github.com/u2takey/ffmpeg-go" ) -func cutoutClipAndTranscode(ut *Utterance) { +func cutoutClipAndTranscode(ut *Utterance) error { err := ffmpeg.Input(ut.FD.AudioPath, ffmpeg.KwArgs{ "ss": ut.LeftTime, @@ -17,8 +17,5 @@ func cutoutClipAndTranscode(ut *Utterance) { "metadata": fmt.Sprintf(`source="%s"`, ut.FD.VttPath), }).OverWriteOutput().ErrorToStdOut().Run() - if err != nil { - panic(err) - } - return + return err } diff --git a/main.go b/main.go index 302439c..a2eae60 100644 --- a/main.go +++ b/main.go @@ -78,6 +78,10 @@ func linesToUtterances(lines []string, fd *FileData) []*Utterance { } u.OutPath = fmt.Sprintf("%s/%s_%s_%s.wav", outdir, fd.AudioBase, u.LeftTime, u.RightTime) + + if u.LeftTime == u.RightTime { + continue + } resp = append(resp, u) } @@ -235,27 +239,15 @@ func main() { panic(err) } - ffmpegCommands := make(map[string]struct{}) - // // needs to be oneline command to be unique - // ffCommandsRaw := readLines(ffCmdOut) - // for _, ff := range ffCommandsRaw { - // ffmpegCommands[ff] = struct{}{} - // } - for _, ut := range utterances { - ffmpegCommands[buildFFmpegCall(ut)] = struct{}{} - cutoutClipAndTranscode(ut) - } - fflines := keysToSlice(ffmpegCommands) - fmt.Println("# lines: ", len(fflines)) - writeLines(fflines, ffCmdOut) - - metadata := readJson(metadataPath) - newMeta := utterancesToFileTextMap(utterances) + filteredUtterances := []*Utterance{} - for k, v := range newMeta { - metadata[k] = v + for _, ut := range utterances { + if _, err := os.Stat(ut.OutPath); os.IsNotExist(err) { + if err := cutoutClipAndTranscode(ut); err == nil { + filteredUtterances = append(filteredUtterances, ut) + } + } } - - writeJson(metadata) - writeCSV(mapToCSV(metadata)) + newMeta := utterancesToFileTextMap(filteredUtterances) + writeCSV(mapToCSV(newMeta)) } -- cgit v1.2.3