2022-10-08 02:36:15 +03:00
|
|
|
package main
|
|
|
|
|
|
|
|
|
|
import "fmt"
|
|
|
|
|
|
2024-12-20 21:51:05 +02:00
|
|
|
var SupportedVideoEncoders = []string{
|
|
|
|
|
"libx264",
|
|
|
|
|
"libx265",
|
|
|
|
|
"libvpx-vp9",
|
|
|
|
|
"librav1e",
|
|
|
|
|
"libsvtav1",
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var SupportedAudioEncoders = []string{
|
|
|
|
|
"aac",
|
|
|
|
|
"libopus",
|
|
|
|
|
"libvorbis",
|
|
|
|
|
}
|
|
|
|
|
|
2022-10-08 02:36:15 +03:00
|
|
|
var Configs = []Config{
|
|
|
|
|
{Name: "Delete old video(s)?", Opts: []string{"No", "Yes"}, FocusedOption: 1},
|
2024-12-26 20:52:12 +02:00
|
|
|
{Name: "On name conflict?", Opts: []string{"Ignore", "Overwrite"}},
|
2024-12-20 21:51:05 +02:00
|
|
|
{Name: "Video Encoder", Opts: []string{"copy"}},
|
|
|
|
|
{Name: "Audio Encoder", Opts: []string{"None", "copy"}, FocusedOption: 1},
|
2024-12-19 10:10:51 +02:00
|
|
|
{Name: "Preset", Opts: []string{"ultrafast", "superfast", "veryfast", "faster", "fast", "medium", "slow", "slower", "veryslow"}, FocusedOption: 4},
|
2022-10-08 02:36:15 +03:00
|
|
|
{Name: "Constant Rate Factor (CRF)", Opts: []string{"10", "15", "20", "25", "30", "35", "40", "45", "50"}, FocusedOption: 4},
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
type Config struct {
|
|
|
|
|
Name string
|
|
|
|
|
Opts []string
|
|
|
|
|
FocusedOption int
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
type ParsedConfig struct {
|
2024-12-26 20:52:12 +02:00
|
|
|
DeleteOldVideo bool
|
|
|
|
|
IgnoreConflictingName bool
|
|
|
|
|
VideoEncoder string
|
|
|
|
|
AudioEncoder string
|
|
|
|
|
Preset string
|
|
|
|
|
CRF string
|
2022-10-08 02:36:15 +03:00
|
|
|
}
|
|
|
|
|
|
2024-12-19 12:49:49 +02:00
|
|
|
func find(cfgs []Config, name string) Config {
|
2022-10-08 02:36:15 +03:00
|
|
|
for _, cfg := range cfgs {
|
|
|
|
|
if cfg.Name == name {
|
|
|
|
|
return cfg
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
err := fmt.Sprintf("Couldn't find requested cfg: %s", name)
|
|
|
|
|
panic(err)
|
|
|
|
|
}
|
2024-12-19 12:49:49 +02:00
|
|
|
|
|
|
|
|
func filter(cfgs []Config, names ...string) []Config {
|
|
|
|
|
filtered := make([]Config, 0)
|
|
|
|
|
|
|
|
|
|
cfgloop:
|
|
|
|
|
for _, cfg := range cfgs {
|
|
|
|
|
for _, name := range names {
|
|
|
|
|
if cfg.Name == name {
|
|
|
|
|
continue cfgloop
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
filtered = append(filtered, cfg)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return filtered
|
|
|
|
|
}
|
|
|
|
|
|
2024-12-20 21:51:05 +02:00
|
|
|
func contains[T comparable](slice []T, elem T) bool {
|
|
|
|
|
for _, e := range slice {
|
|
|
|
|
if e == elem {
|
|
|
|
|
return true
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return false
|
|
|
|
|
}
|
|
|
|
|
|
2024-12-19 12:49:49 +02:00
|
|
|
func getVisibleConfigs(cfgs []Config) []Config {
|
|
|
|
|
parsed := parseConfig(cfgs)
|
|
|
|
|
|
|
|
|
|
switch parsed.VideoEncoder {
|
|
|
|
|
case "copy", "librav1e":
|
|
|
|
|
return filter(cfgs, "Preset", "Constant Rate Factor (CRF)")
|
|
|
|
|
case "libvpx-vp9", "libsvtav1":
|
|
|
|
|
return filter(cfgs, "Preset")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return cfgs
|
|
|
|
|
}
|