-
-
Notifications
You must be signed in to change notification settings - Fork 77
/
config.go
113 lines (90 loc) · 2.48 KB
/
config.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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
package transcoder
import (
"encoding/json"
"io/ioutil"
"log"
"os"
"os/exec"
)
type Config struct {
// Current version of go-vod
Version string
// Is this server configured?
Configured bool
// Restart the server if incorrect version detected
VersionMonitor bool
// Bind address
Bind string `json:"bind"`
// FFmpeg binary
FFmpeg string `json:"ffmpeg"`
// FFprobe binary
FFprobe string `json:"ffprobe"`
// Temp files directory
TempDir string `json:"tempdir"`
// Size of each chunk in seconds
ChunkSize int `json:"chunkSize"`
// How many *chunks* to look behind before restarting transcoding
LookBehind int `json:"lookBehind"`
// Number of chunks in goal to restart encoding
GoalBufferMin int `json:"goalBufferMin"`
// Number of chunks in goal to stop encoding
GoalBufferMax int `json:"goalBufferMax"`
// Number of seconds to wait before shutting down encoding
StreamIdleTime int `json:"streamIdleTime"`
// Number of seconds to wait before shutting down a client
ManagerIdleTime int `json:"managerIdleTime"`
// Quality Factor (e.g. CRF / global_quality)
QF int `json:"qf"`
// Hardware acceleration configuration
// VA-API
VAAPI bool `json:"vaapi"`
VAAPILowPower bool `json:"vaapiLowPower"`
// NVENC
NVENC bool `json:"nvenc"`
NVENCTemporalAQ bool `json:"nvencTemporalAQ"`
NVENCScale string `json:"nvencScale"` // cuda, npp
// Use transpose workaround for streaming (VA-API)
UseTranspose bool `json:"useTranspose"`
// Force tranpose in software
ForceSwTranspose bool `json:"forceSwTranspose"`
// Use GOP size workaround for streaming (NVENC)
UseGopSize bool `json:"useGopSize"`
}
func (c *Config) FromFile(path string) {
// load json config
content, err := ioutil.ReadFile(path)
if err != nil {
log.Fatal("Error when opening file: ", err)
}
err = json.Unmarshal(content, &c)
if err != nil {
log.Fatal("Error loading config file", err)
}
// Set config as loaded
c.Configured = true
c.Print()
}
func (c *Config) AutoDetect() {
// Auto-detect ffmpeg and ffprobe paths
if c.FFmpeg == "" || c.FFprobe == "" {
ffmpeg, err := exec.LookPath("ffmpeg")
if err != nil {
log.Fatal("Could not find ffmpeg")
}
ffprobe, err := exec.LookPath("ffprobe")
if err != nil {
log.Fatal("Could not find ffprobe")
}
c.FFmpeg = ffmpeg
c.FFprobe = ffprobe
}
// Auto-choose tempdir
if c.TempDir == "" {
c.TempDir = os.TempDir() + "/go-vod"
}
// Print updated config
c.Print()
}
func (c *Config) Print() {
log.Printf("%+v\n", c)
}