From 6525c31dbf719f950d2b64f0c8bbb474839062e6 Mon Sep 17 00:00:00 2001 From: "Zed A. Shaw" Date: Sun, 7 Sep 2025 13:48:06 -0400 Subject: [PATCH] All of the main options are working, now to handle in/output directories and such. --- config/settings.go | 2 +- main.go | 39 +++++++++++++++++++++++++++++++-------- 2 files changed, 32 insertions(+), 9 deletions(-) diff --git a/config/settings.go b/config/settings.go index 7cc3b8f..3940332 100644 --- a/config/settings.go +++ b/config/settings.go @@ -29,7 +29,7 @@ type config struct { var Settings config func parseFlags(c *config) { - flag.IntVar(&c.Test, "test", 10, "Make a test video seconds long.") + 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") diff --git a/main.go b/main.go index e6f8bdb..441dcd9 100644 --- a/main.go +++ b/main.go @@ -2,12 +2,16 @@ package main import ( "fmt" + "log" "lcthw.dev/vidcrunch/config" "github.com/modfy/fluent-ffmpeg" ) -func Run(pass string) { +const DevNull = "NUL" + +func Run(pass int, output string) { pid := 1 + encode := fluentffmpeg.NewCommand("") mp4_opts := []string{ @@ -16,29 +20,48 @@ func Run(pass string) { "-pix_fmt", "yuv420p", "-tune", config.Settings.Tune, "-movflags", "faststart", - "-pass", pass, + "-pass", fmt.Sprint(pass), "-passlogfile", fmt.Sprintf("ffmpeg2pass-%d.log", pid), "-preset", config.Settings.Speed, - "-filter:v", fmt.Sprintf("fps=%d", config.Settings.FPS), - "-crf", fmt.Sprint(config.Settings.CRF), } - encode.Options(mp4_opts...) + if pass != 3 { + mp4_opts = append(mp4_opts, "-an") + } else { + encode.AudioCodec("aac") + mp4_opts = append(mp4_opts, + "-b:a", fmt.Sprint(config.Settings.AudioBitrate * 1024)) + } + + if config.Settings.Test > 0 { + encode.InputOptions( + "-ss", fmt.Sprintf("00:%d", config.Settings.TestStart)) + mp4_opts = append(mp4_opts, "-t", fmt.Sprint(config.Settings.Test)) + } + + encode.VideoCodec("libx264"). + VideoBitRate(config.Settings.VideoBitrate * 1024). + FrameRate(config.Settings.FPS). + ConstantRateFactor(config.Settings.CRF) + + encode.OutputOptions(mp4_opts...) cmd := encode.InputPath(config.Settings.Input). OutputFormat("mp4"). - OutputPath(config.Settings.Output). + OutputPath(output). Build() fmt.Println("COMMAND", cmd.String()) err := cmd.Run() - if err != nil { panic("fail") } + if err != nil { log.Fatalf("%v", err) } } func main() { config.Load() fmt.Println(config.Settings) - Run("1") + Run(1, DevNull) + Run(2, DevNull) + Run(3, config.Settings.Output) }