-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
80 lines (68 loc) · 1.53 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
package main
import (
"flag"
"fmt"
"os"
)
type videoSize struct {
X int
Y int
}
const (
Standard = "SD"
Medium = "MD"
High = "HD"
)
var videoSizes = map[string]videoSize{
Standard: {640, 360},
Medium: {854, 480},
High: {1280, 720},
}
func init() {}
func main() {
//TODO: 1. wrap application into grpc service
//2. Run service in docker container
//3. Pass message with local file location
//4. Stream encoding progress from app to subscriber/client
//5. Limit memory consumption from Docker using env variables
//6. Test with different file sizes
inputFlag := flag.String("in", "", "folder with the files to process")
outputFlag := flag.String("out", "", "folder for processed files")
flag.Parse()
//inputPath := "D:/Study/go/vidConv/files/input/"
//outputPath := "D:/Study/go/vidConv/files/output/"
inputPath := *inputFlag
outputPath := *outputFlag
if err := checkDirectories(inputPath, outputPath); err != nil {
panic(err)
}
files, err := os.ReadDir(inputPath)
if err != nil {
panic(err)
}
runsCount := 0
conv := ConverterImpl{}
errChan := make(chan error)
defer close(errChan)
for sizeKey := range videoSizes {
for _, file := range files {
if !file.IsDir() {
runsCount++
go func(s string) {
errChan <- conv.resizeWithErr(file.Name(), inputPath, outputPath, s)
}(sizeKey)
}
}
}
// Selector approach
for {
select {
case err = <-errChan:
if err != nil {
fmt.Print(err)
}
}
return
}
fmt.Printf("All %v videos are converted successfully", runsCount)
}