You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
73 lines
1.4 KiB
73 lines
1.4 KiB
package config
|
|
|
|
import (
|
|
"flag"
|
|
"log"
|
|
"os"
|
|
"encoding/json"
|
|
)
|
|
|
|
type CodecOpts struct {
|
|
Scale string
|
|
Resize bool
|
|
VideoBitrate int
|
|
VideoCodec string
|
|
AudioBitrate int
|
|
AudioCodec string
|
|
// used internally, shouldn't set int json
|
|
Target string
|
|
Source string
|
|
}
|
|
|
|
type EncodeOpts struct {
|
|
Format string
|
|
Variants []CodecOpts
|
|
Preset string
|
|
Dash bool
|
|
CRF int
|
|
FPS int
|
|
Tune string
|
|
Input string
|
|
OutDir string
|
|
Test int
|
|
TestStart int
|
|
Passes int
|
|
Extras []string
|
|
}
|
|
|
|
type Settings struct {
|
|
Debug int
|
|
Force bool
|
|
Serve string
|
|
Port string
|
|
ConfigPath string
|
|
Encodings []EncodeOpts
|
|
}
|
|
|
|
func ParseFlags(c *Settings) {
|
|
flag.IntVar(&c.Debug, "debug", 0, "1=print the ffmpeg command, 2=and its stderr output")
|
|
flag.BoolVar(&c.Force, "force", false, "Force the render even if the file exists.")
|
|
flag.StringVar(&c.ConfigPath, "config", "config.json", "config.json to load")
|
|
flag.StringVar(&c.Serve, "serve", "", "serve a directory webserver")
|
|
flag.StringVar(&c.Port, "port", ":8099", "start a simple HTTP server for testing")
|
|
|
|
flag.Parse()
|
|
}
|
|
|
|
func Load() Settings {
|
|
var config Settings
|
|
|
|
ParseFlags(&config)
|
|
|
|
data, err := os.ReadFile(config.ConfigPath)
|
|
if err != nil {
|
|
log.Fatalf("error reading config %s: %v", config.ConfigPath, err);
|
|
}
|
|
|
|
err = json.Unmarshal(data, &config.Encodings)
|
|
if err != nil {
|
|
log.Fatalf("error loading %s: %v", config.ConfigPath, err)
|
|
}
|
|
|
|
return config
|
|
}
|
|
|