-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.go
92 lines (87 loc) · 2.42 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
81
82
83
84
85
86
87
88
89
90
91
92
package main
import (
"fmt"
"github.com/zhangyiming748/ConvertVideo/constant"
"github.com/zhangyiming748/ConvertVideo/conv"
mylog "github.com/zhangyiming748/ConvertVideo/log"
"github.com/zhangyiming748/ConvertVideo/mediainfo"
"github.com/zhangyiming748/ConvertVideo/util"
"log"
"os"
"path/filepath"
"runtime"
"time"
)
func main() {
t := new(util.ProcessDuration)
t.SetStart(time.Now())
defer func() {
log.Printf("程序总用时:%v分\n", t.GetDuration().Minutes())
}()
constant.SetTransTitle(os.Getenv("trans"))
if direction := os.Getenv("direction"); direction == "" {
log.Printf("$direction为空,使用默认值%v\n", constant.GetDirection())
} else {
constant.SetDirection(direction)
log.Printf("$direction不为空,修改为%v\n", constant.GetDirection())
}
if root := os.Getenv("root"); root == "" {
log.Printf("$root为空,使用默认值%v\n", constant.GetRoot())
} else {
constant.SetRoot(root)
log.Printf("$root不为空,修改为%v\n", constant.GetRoot())
}
if to := os.Getenv("to"); to == "" {
log.Printf("$to为空,使用默认值%v\n", constant.GetTo())
} else {
constant.SetTo(to)
log.Printf("$to不为空,修改为%v\n", constant.GetTo())
}
mylog.SetLog()
err := filepath.Walk(constant.GetRoot(), func(p string, info os.FileInfo, err error) error {
if err != nil {
return err
}
if info.IsDir() {
absPath, err := filepath.Abs(p)
if err != nil {
return err
}
log.Printf("准备处理的文件夹%v\n", info.Name())
files := util.GetFiles(absPath)
cpus := constant.GetCpuNums()
if cpus > constant.MaxCPU {
cpus = constant.MaxCPU
}
for _, file := range files {
switch constant.To {
case "vp9":
conv.ProcessVideo2VP9(*mediainfo.GetBasicInfo(file))
case "h265":
conv.ProcessVideo2H265(*mediainfo.GetBasicInfo(file))
case "rotate":
conv.RotateVideo(file, constant.GetDirection())
case "merge":
conv.MkvWithAss(*mediainfo.GetBasicInfo(file))
case "clip":
conv.ProcessVideo2clip(*mediainfo.GetBasicInfo(file))
default:
log.Fatalf("$to=%v参数错误\n", constant.GetTo())
}
}
}
return nil
})
if err != nil {
log.Println("Error:", err)
}
files := util.GetAllFiles(constant.Root)
log.Printf("符合条件的文件:%v\n", files)
t.SetEnd(time.Now())
}
func NumsOfGoroutine() {
for {
fmt.Printf("\r当前程序运行时协程个数:%d\n", runtime.NumGoroutine())
time.Sleep(1 * time.Second)
}
}