From 32887187ca3144decf4edc95fc87d6b61fdbf120 Mon Sep 17 00:00:00 2001 From: "Zed A. Shaw" Date: Mon, 8 Sep 2025 10:44:43 -0400 Subject: [PATCH] Bring back the scale added to files. --- .gitignore | 1 + main.go | 36 +++++++++++++++++++++++++----------- 2 files changed, 26 insertions(+), 11 deletions(-) diff --git a/.gitignore b/.gitignore index 8ff5ff0..199cf28 100644 --- a/.gitignore +++ b/.gitignore @@ -28,3 +28,4 @@ coverage/* *.gz public *.mp4 +ffmpeg* diff --git a/main.go b/main.go index 9205673..fd476c2 100644 --- a/main.go +++ b/main.go @@ -6,12 +6,25 @@ import ( "runtime" "log" "os" - // "errors" - // "io/fs" + "math/rand" + "strings" "lcthw.dev/vidcrunch/config" "github.com/modfy/fluent-ffmpeg" ) +func ModFile(fname string, scale string) string { + cleaned := filepath.Clean(fname) + dir, file := filepath.Split(cleaned) + ext := filepath.Ext(file) + + base, found := strings.CutSuffix(file, ext) + if !found { panic("no extension found?!") } + + dim := strings.Replace(scale, ":", ".", 1) + renamed := fmt.Sprint(base, ".", dim, ext) + return filepath.Join(dir, renamed) +} + func Run(pass int, pid int, input string, output string) { encode := fluentffmpeg.NewCommand("") @@ -23,7 +36,7 @@ func Run(pass int, pid int, input string, output string) { "-tune", config.Settings.Tune, "-movflags", "faststart", "-pass", fmt.Sprint(pass), - "-passlogfile", fmt.Sprintf("ffmpeg2pass-%d.log", pid), + "-passlogfile", fmt.Sprintf("ffmpeg2pass-%x.log", pid), "-preset", config.Settings.Speed, } @@ -53,7 +66,7 @@ func Run(pass int, pid int, input string, output string) { OutputPath(output). Build() - fmt.Println("COMMAND", cmd.String()) + fmt.Println(">", cmd.String()) err := cmd.Run() if err != nil { log.Fatalf("%v", err) } @@ -68,9 +81,10 @@ func DevNull() string { } func RenderFile(pid int, path string, target string) { - Run(1, pid, path, DevNull()) - Run(2, pid, path, DevNull()) - Run(3, pid, path, target) + target = ModFile(target, config.Settings.Scale) + Run(1, pid, path, DevNull()) + Run(2, pid, path, DevNull()) + Run(3, pid, path, target) } func RenderToDir() { @@ -84,10 +98,10 @@ func RenderToDir() { _, err := os.Stat(target) if err != nil { - fmt.Println("PATH", path, "->", target) - RenderFile(1, path, target) + fmt.Println("--- PATH", path, "->", target) + RenderFile(rand.Int(), path, target) } else { - fmt.Println("SKIP", path, "->", target) + fmt.Println("^^^ SKIP", path, "->", target) } } } @@ -96,7 +110,7 @@ func main() { config.Load() if config.Settings.Output != "" { - RenderFile(1, config.Settings.Input, config.Settings.Output) + RenderFile(rand.Int(), config.Settings.Input, config.Settings.Output) } else if config.Settings.OutDir != "" { RenderToDir() } else {