memories/go-vod/transcoder/config.go

112 lines
2.4 KiB
Go
Raw Permalink Normal View History

2023-11-01 08:03:28 +00:00
package transcoder
2022-11-10 12:27:29 +00:00
2023-10-21 18:27:25 +00:00
import (
"encoding/json"
"io/ioutil"
"log"
"os"
"os/exec"
)
2022-11-10 12:27:29 +00:00
type Config struct {
2023-10-21 18:36:22 +00:00
// Current version of go-vod
Version string
2023-04-10 23:44:39 +00:00
// Is this server configured?
Configured bool
2023-10-20 21:12:09 +00:00
// Restart the server if incorrect version detected
VersionMonitor bool
2023-03-09 19:57:15 +00:00
// Bind address
Bind string `json:"bind"`
2022-11-11 02:01:33 +00:00
// FFmpeg binary
2023-03-09 19:57:15 +00:00
FFmpeg string `json:"ffmpeg"`
2022-11-11 02:01:33 +00:00
// FFprobe binary
2023-03-09 19:57:15 +00:00
FFprobe string `json:"ffprobe"`
2022-11-11 03:40:53 +00:00
// Temp files directory
2023-03-09 19:57:15 +00:00
TempDir string `json:"tempdir"`
2022-11-11 02:01:33 +00:00
// Size of each chunk in seconds
2023-03-09 19:57:15 +00:00
ChunkSize int `json:"chunkSize"`
2022-11-11 02:01:33 +00:00
// How many *chunks* to look behind before restarting transcoding
2023-03-09 19:57:15 +00:00
LookBehind int `json:"lookBehind"`
2022-11-11 02:20:47 +00:00
// Number of chunks in goal to restart encoding
2023-03-09 19:57:15 +00:00
GoalBufferMin int `json:"goalBufferMin"`
2022-11-11 02:20:47 +00:00
// Number of chunks in goal to stop encoding
2023-03-09 19:57:15 +00:00
GoalBufferMax int `json:"goalBufferMax"`
2022-11-11 05:20:23 +00:00
// Number of seconds to wait before shutting down encoding
2023-03-09 19:57:15 +00:00
StreamIdleTime int `json:"streamIdleTime"`
2022-11-11 05:20:23 +00:00
// Number of seconds to wait before shutting down a client
2023-03-09 19:57:15 +00:00
ManagerIdleTime int `json:"managerIdleTime"`
2023-10-25 00:17:36 +00:00
// Quality Factor (e.g. CRF / global_quality)
QF int `json:"qf"`
2023-03-09 19:57:15 +00:00
// Hardware acceleration configuration
2023-03-09 21:02:57 +00:00
// VA-API
2023-03-09 20:39:43 +00:00
VAAPI bool `json:"vaapi"`
VAAPILowPower bool `json:"vaapiLowPower"`
2023-03-09 21:02:57 +00:00
// NVENC
NVENC bool `json:"nvenc"`
NVENCTemporalAQ bool `json:"nvencTemporalAQ"`
NVENCScale string `json:"nvencScale"` // cuda, npp
2023-09-29 17:25:00 +00:00
// Use transpose workaround for streaming (VA-API)
UseTranspose bool `json:"useTranspose"`
2023-09-29 17:25:00 +00:00
// Use GOP size workaround for streaming (NVENC)
UseGopSize bool `json:"useGopSize"`
2022-11-10 12:27:29 +00:00
}
2023-10-21 18:27:25 +00:00
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)
}