From b172d1e63a329c40bbc7c99caae2e3acb2230a92 Mon Sep 17 00:00:00 2001 From: "Zed A. Shaw" Date: Sun, 7 Sep 2025 15:11:06 -0400 Subject: [PATCH] Now works with a directory and glob and won't duplicate work. Fuck os.Stat. --- config.toml | 4 ++-- config/settings.go | 3 +-- main.go | 56 ++++++++++++++++++++++++++++++++++++++-------- 3 files changed, 50 insertions(+), 13 deletions(-) diff --git a/config.toml b/config.toml index 65e3b79..ba72e4e 100644 --- a/config.toml +++ b/config.toml @@ -6,5 +6,5 @@ CleanFilename = false CRF = 20 FPS = 30 Tune = "animation" -Input = "test.mp4" -Output = "test_render.mp4" +Input = "test*.mp4" +OutDir = "renders" diff --git a/config/settings.go b/config/settings.go index 3940332..1727506 100644 --- a/config/settings.go +++ b/config/settings.go @@ -9,7 +9,6 @@ import ( type config struct { Test int TestStart int - InitOutdir bool Debug int Progress bool ConfigPath string @@ -24,6 +23,7 @@ type config struct { Tune string Input string Output string + OutDir string } var Settings config @@ -31,7 +31,6 @@ var Settings config func parseFlags(c *config) { flag.IntVar(&c.Test, "test", 0, "Make a test video seconds long.") flag.IntVar(&c.TestStart, "test-start", 60, "When to start the test clip.") - flag.BoolVar(&c.InitOutdir, "init-outdir", false, "if outdir doesn't exist create it") flag.IntVar(&c.Debug, "debug", 0, "1=print the ffmpeg command, 2=and its stderr output") flag.BoolVar(&c.Progress, "progress", false, "Show percent progress. Not accurate (thanks ffmpeg)") flag.StringVar(&c.ConfigPath, "config", "config.toml", "config.toml to load") diff --git a/main.go b/main.go index 441dcd9..9205673 100644 --- a/main.go +++ b/main.go @@ -2,16 +2,18 @@ package main import ( "fmt" + "path/filepath" + "runtime" "log" + "os" + // "errors" + // "io/fs" "lcthw.dev/vidcrunch/config" "github.com/modfy/fluent-ffmpeg" ) -const DevNull = "NUL" - -func Run(pass int, output string) { - pid := 1 +func Run(pass int, pid int, input string, output string) { encode := fluentffmpeg.NewCommand("") mp4_opts := []string{ @@ -46,7 +48,7 @@ func Run(pass int, output string) { encode.OutputOptions(mp4_opts...) - cmd := encode.InputPath(config.Settings.Input). + cmd := encode.InputPath(input). OutputFormat("mp4"). OutputPath(output). Build() @@ -57,11 +59,47 @@ func Run(pass int, output string) { if err != nil { log.Fatalf("%v", err) } } +func DevNull() string { + if runtime.GOOS == "windows" { + return "NUL" + } else { + return "/dev/null" + } +} + +func RenderFile(pid int, path string, target string) { + Run(1, pid, path, DevNull()) + Run(2, pid, path, DevNull()) + Run(3, pid, path, target) +} + +func RenderToDir() { + matches, err := filepath.Glob(config.Settings.Input) + if err != nil { log.Fatalf("%v", err) } + + for _, path := range matches { + base := filepath.Base(path) + target := filepath.Join(config.Settings.OutDir, base) + + _, err := os.Stat(target) + + if err != nil { + fmt.Println("PATH", path, "->", target) + RenderFile(1, path, target) + } else { + fmt.Println("SKIP", path, "->", target) + } + } +} + func main() { config.Load() - fmt.Println(config.Settings) - Run(1, DevNull) - Run(2, DevNull) - Run(3, config.Settings.Output) + if config.Settings.Output != "" { + RenderFile(1, config.Settings.Input, config.Settings.Output) + } else if config.Settings.OutDir != "" { + RenderToDir() + } else { + log.Fatal("config file needs either Output or OutDir") + } }