summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGrail Finder <wohilas@gmail.com>2023-02-16 15:35:14 +0600
committerGrail Finder <wohilas@gmail.com>2023-02-16 15:35:14 +0600
commit84a3dd05d1623d61e694d3f763c3121be3b9b43c (patch)
tree0e8767c526c343dbe0c37e75af78747792633949
parent71571f513b664dee0a9908015012ba86d785be72 (diff)
Feat: filter out bad times
-rw-r--r--ffmpeg.go7
-rw-r--r--main.go34
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))
}