summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGrail Finder <wohilas@gmail.com>2023-02-15 21:06:32 +0600
committerGrail Finder <wohilas@gmail.com>2023-02-15 21:06:32 +0600
commit41582a3c316acf6e446364d6a4ba43b0c3ef1cea (patch)
tree4f6571c990f352a310fb9944bf891738ace9f840
parent9de5f6901653523b7c74b870aa8c0764af91cabc (diff)
Feat: add ffmpeg inside of go
-rw-r--r--ffmpeg.go24
-rw-r--r--go.mod8
-rw-r--r--go.sum62
-rw-r--r--main.go22
-rw-r--r--readme.md1
5 files changed, 109 insertions, 8 deletions
diff --git a/ffmpeg.go b/ffmpeg.go
new file mode 100644
index 0000000..77a2195
--- /dev/null
+++ b/ffmpeg.go
@@ -0,0 +1,24 @@
+package main
+
+import (
+ "fmt"
+
+ ffmpeg "github.com/u2takey/ffmpeg-go"
+)
+
+func cutoutClipAndTranscode(ut *Utterance) {
+ err := ffmpeg.Input(ut.FD.AudioPath,
+ ffmpeg.KwArgs{
+ "ss": ut.LeftTime,
+ "to": ut.RightTime,
+ },
+ ).Output(ut.OutPath, ffmpeg.KwArgs{
+ "ar": "22050",
+ "metadata": fmt.Sprintf(`source="%s"`, ut.FD.VttPath),
+ }).OverWriteOutput().ErrorToStdOut().Run()
+
+ if err != nil {
+ panic(err)
+ }
+ return
+}
diff --git a/go.mod b/go.mod
index 88466ed..66cc990 100644
--- a/go.mod
+++ b/go.mod
@@ -1,3 +1,11 @@
module prep-dataset
go 1.20
+
+require github.com/u2takey/ffmpeg-go v0.4.1
+
+require (
+ github.com/aws/aws-sdk-go v1.38.20 // indirect
+ github.com/jmespath/go-jmespath v0.4.0 // indirect
+ github.com/u2takey/go-utils v0.3.1 // indirect
+)
diff --git a/go.sum b/go.sum
new file mode 100644
index 0000000..aa3dc13
--- /dev/null
+++ b/go.sum
@@ -0,0 +1,62 @@
+github.com/aws/aws-sdk-go v1.38.20 h1:QbzNx/tdfATbdKfubBpkt84OM6oBkxQZRw6+bW2GyeA=
+github.com/aws/aws-sdk-go v1.38.20/go.mod h1:hcU610XS61/+aQV88ixoOzUoG7v3b31pl2zKMmprdro=
+github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
+github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
+github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
+github.com/disintegration/imaging v1.6.2/go.mod h1:44/5580QXChDfwIclfc/PCwrr44amcmDAg8hxG0Ewe4=
+github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo=
+github.com/go-logr/logr v0.1.0/go.mod h1:ixOQHD9gLJUVQQ2ZOR7zLEifBX6tGkNJF4QyIY7sIas=
+github.com/gogo/protobuf v1.3.1/go.mod h1:SlYgWuQ5SjCEi6WLHjHCa1yvBfUnHcTbrrZtXPKa29o=
+github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
+github.com/google/uuid v1.1.1/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
+github.com/hashicorp/golang-lru v0.5.4/go.mod h1:iADmTwqILo4mZ8BN3D2Q6+9jd8WM5uGBxy+E8yxSoD4=
+github.com/jmespath/go-jmespath v0.4.0 h1:BEgLn5cpjn8UN1mAw4NjwDrS35OdebyEtFe+9YPoQUg=
+github.com/jmespath/go-jmespath v0.4.0/go.mod h1:T8mJZnbsbmF+m6zOOFylbeCJqk5+pHWvzYPziyZiYoo=
+github.com/jmespath/go-jmespath/internal/testify v1.5.1 h1:shLQSRRSCCPj3f2gpwzGwWFoC7ycTf1rcQZHOlsJ6N8=
+github.com/jmespath/go-jmespath/internal/testify v1.5.1/go.mod h1:L3OGu8Wl2/fWfCI6z80xFu9LTZmf1ZRjMHUOPmWr69U=
+github.com/json-iterator/go v1.1.10/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4=
+github.com/kisielk/errcheck v1.2.0/go.mod h1:/BMXB+zMLi60iA8Vv6Ksmxu/1UDYcXs4uQLJ+jE2L00=
+github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck=
+github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
+github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
+github.com/modern-go/reflect2 v0.0.0-20180701023420-4b7aa43c6742/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0=
+github.com/modern-go/reflect2 v1.0.1/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0=
+github.com/panjf2000/ants/v2 v2.4.2/go.mod h1:f6F0NZVFsGCp5A7QW/Zj/m92atWwOkY0OIhFxRNFr4A=
+github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
+github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
+github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
+github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
+github.com/spf13/afero v1.2.2/go.mod h1:9ZxEEn6pIJ8Rxe320qSDBk6AsU0r9pR7Q4OcevTdifk=
+github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
+github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
+github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
+github.com/stretchr/testify v1.5.1 h1:nOGnQDM7FYENwehXlg/kFVnos3rEvtKTjRvOWSzb6H4=
+github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA=
+github.com/u2takey/ffmpeg-go v0.4.1 h1:l5ClIwL3N2LaH1zF3xivb3kP2HW95eyG5xhHE1JdZ9Y=
+github.com/u2takey/ffmpeg-go v0.4.1/go.mod h1:ruZWkvC1FEiUNjmROowOAps3ZcWxEiOpFoHCvk97kGc=
+github.com/u2takey/go-utils v0.3.1 h1:TaQTgmEZZeDHQFYfd+AdUT1cT4QJgJn/XVPELhHw4ys=
+github.com/u2takey/go-utils v0.3.1/go.mod h1:6e+v5vEZ/6gu12w/DC2ixZdZtCrNokVxD0JUklcqdCs=
+gocv.io/x/gocv v0.25.0/go.mod h1:Rar2PS6DV+T4FL+PM535EImD/h13hGVaHhnCu1xarBs=
+golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
+golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
+golang.org/x/image v0.0.0-20191009234506-e7c1f5e7dbb8/go.mod h1:FeLwcggjj3mMvU+oOTbSwawSJRM1uh48EjtB4UJZlP0=
+golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
+golang.org/x/net v0.0.0-20201110031124-69a78807bb2b h1:uwuIcX0g4Yl1NC5XAz37xsr2lTtcqevgzYNVt49waME=
+golang.org/x/net v0.0.0-20201110031124-69a78807bb2b/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU=
+golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
+golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
+golang.org/x/sys v0.0.0-20200602225109-6fdc65e7d980/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
+golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
+golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
+golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk=
+golang.org/x/text v0.3.3 h1:cokOdA+Jmi5PJGXLlLllQSgYigAEfHXJAERHVMaCc2k=
+golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
+golang.org/x/time v0.0.0-20190308202827-9d24e82272b4/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
+golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
+golang.org/x/tools v0.0.0-20181030221726-6c7e314b6563/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
+gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
+gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
+gopkg.in/yaml.v2 v2.2.7/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
+gopkg.in/yaml.v2 v2.2.8 h1:obN1ZagJSUGI0Ek/LBmuj4SNLPfIny3KsKFopxRdj10=
+gopkg.in/yaml.v2 v2.2.8/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
+sigs.k8s.io/yaml v1.2.0/go.mod h1:yfXDCHCao9+ENCvLSE62v9VSji2MKu5jeNfTrofGhJc=
diff --git a/main.go b/main.go
index 32a49e5..c82d538 100644
--- a/main.go
+++ b/main.go
@@ -46,7 +46,7 @@ func NewFileData(vttPath string) *FileData {
}
func keysToSlice(req map[string]struct{}) []string {
- resp := make([]string, len(req))
+ resp := []string{}
for k := range req {
resp = append(resp, k)
}
@@ -105,9 +105,9 @@ func readLines(filepath string) []string {
// writeLines writes the lines to the given file.
func writeLines(lines []string, path string) error {
- // file, err := os.Create(path)
- file, err := os.OpenFile(path,
- os.O_APPEND|os.O_WRONLY|os.O_CREATE, 0666)
+ file, err := os.Create(path)
+ // file, err := os.OpenFile(path,
+ // os.O_APPEND|os.O_WRONLY|os.O_CREATE, 0666)
if err != nil {
return err
}
@@ -160,9 +160,9 @@ func writeCSV(data [][]string) {
func buildFFmpegCall(ut *Utterance) string {
return fmt.Sprintf(
- `yes no | ffmpeg -i %s -ss %s -to %s \
+ `yes no | ffmpeg -i "%s" -ss %s -to %s \
-metadata text_source="%s" \
- -ar 22050 %s`,
+ -ar 22050 "%s"`,
ut.FD.AudioPath, ut.LeftTime, ut.RightTime,
ut.FD.VttPath, ut.OutPath,
)
@@ -217,7 +217,6 @@ func getVttList(dirpath string) []string {
func main() {
vttFilepath := flag.String("f", "", "path to a vtt file")
vttDir := flag.String("d", "", "path to a vtt dir")
- // vttFilepath := os.Args[1]
flag.Parse()
utterances := []*Utterance{}
@@ -233,10 +232,17 @@ func main() {
fmt.Println("sum of utterances:", len(utterances))
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{}{}
}
- writeLines(keysToSlice(ffmpegCommands), ffCmdOut)
+ fflines := keysToSlice(ffmpegCommands)
+ fmt.Println("# lines: ", len(fflines))
+ writeLines(fflines, ffCmdOut)
metadata := readJson(metadataPath)
newMeta := utterancesToFileTextMap(utterances)
diff --git a/readme.md b/readme.md
index fde427b..8e5c4e7 100644
--- a/readme.md
+++ b/readme.md
@@ -5,3 +5,4 @@
- change metadata format from json to csv for lower memory consumption;
- add config file; move constance to config file;
- ffmpeg call should be unique;
+- ffmpeg commands are slow, split to clips inside of this module;