From bb51688a6ad7db2d387d1b43a15cfc240940e3ae Mon Sep 17 00:00:00 2001 From: "Zed A. Shaw" Date: Fri, 14 Nov 2025 23:43:12 -0500 Subject: [PATCH] Fixes a few things to make testing encoding quicker. --- config.json | 66 +++++++++++----------------------------------- config/settings.go | 6 ++--- main.go | 11 +++++--- 3 files changed, 25 insertions(+), 58 deletions(-) diff --git a/config.json b/config.json index 51be934..8be3639 100644 --- a/config.json +++ b/config.json @@ -1,18 +1,19 @@ [ { "Format": "mp4", - "Scale": "1280:720", - "Resize": true, + "Scale": "1920:1080", + "Resize": false, "VideoBitrate": 900, "AudioBitrate": 192, - "Speed": "veryfast", + "VideoCodec": "libx264", + "Preset": "veryfast", "CleanFilename": false, - "CRF": 20, + "CRF": 30, "FPS": 30, "Tune": "animation", - "Input": "*.mp4", - "OutDir": "renders", - "Passes": 3, + "Input": "LGo*.mp4", + "OutDir": "mp4_test", + "Passes": 1, "Extras": [ "-movflags", "faststart", "-tune", "animation" @@ -20,59 +21,22 @@ }, { "Format": "webm", - "VideoBitrate": 600, - "Scale": "1280:720", - "Resize": true, "VideoCodec": "libvpx-vp9", - "AudioBitrate": 192, - "AudioCodec": "libopus", - "Speed": "veryfast", - "CleanFilename": false, - "CRF": 20, - "FPS": 30, - "Tune": "animation", - "Input": "*.mp4", - "OutDir": "renders", - "Passes": 2, - "Extras": [ - ] - }, - { - "Format": "mp4", "Scale": "1920:1080", "Resize": false, "VideoBitrate": 900, "AudioBitrate": 192, - "Speed": "veryfast", "CleanFilename": false, - "CRF": 20, + "CRF": 30, "FPS": 30, "Tune": "animation", - "Input": "*.mp4", - "OutDir": "renders", - "Passes": 3, + "Input": "LGo*.mp4", + "OutDir": "webm_test", + "Passes": 1, "Extras": [ - "-movflags", "faststart", - "-tune", "animation" + "-deadline", "realtime", + "-row-mt", "1", + "-cpu-used", "8" ] - }, - { - "Format": "webm", - "Scale": "1920:1080", - "Resize": false, - "VideoBitrate": 600, - "VideoCodec": "libvpx-vp9", - "AudioBitrate": 192, - "AudioCodec": "libopus", - "Speed": "veryfast", - "CleanFilename": false, - "CRF": 20, - "FPS": 30, - "Tune": "animation", - "Input": "*.mp4", - "OutDir": "renders", - "Passes": 2, - "Extras": [ - ] } ] diff --git a/config/settings.go b/config/settings.go index 38f6eba..5cde046 100644 --- a/config/settings.go +++ b/config/settings.go @@ -15,7 +15,7 @@ type VideoOpts struct { VideoCodec string AudioBitrate int AudioCodec string - Speed string + Preset string CleanFilename bool CRF int FPS int @@ -30,14 +30,14 @@ type VideoOpts struct { type Settings struct { Debug int - Progress bool + Force bool ConfigPath string Encodings []VideoOpts } func ParseFlags(c *Settings) { 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.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.Parse() diff --git a/main.go b/main.go index 6bb8474..5b9c303 100644 --- a/main.go +++ b/main.go @@ -33,7 +33,10 @@ func Run(encoding config.VideoOpts, pass int, pid int, input string, output stri "-pix_fmt", "yuv420p", "-pass", fmt.Sprint(pass), "-passlogfile", fmt.Sprintf("ffmpeg2pass-%x.log", pid), - "-preset", encoding.Speed, + } + + if encoding.Preset != "" { + extras = append(extras, "-preset", encoding.Preset) } if encoding.Resize { @@ -94,7 +97,7 @@ func RenderFile(encoding config.VideoOpts, pid int, path string, target string) Run(encoding, encoding.Passes, pid, path, target) } -func RenderToDir(encoding config.VideoOpts) { +func RenderToDir(encoding config.VideoOpts, force bool) { matches, err := filepath.Glob(encoding.Input) if err != nil { log.Fatalf("%v", err) } @@ -105,7 +108,7 @@ func RenderToDir(encoding config.VideoOpts) { _, err := os.Stat(target) - if err != nil { + if err != nil || force { fmt.Println("--- PATH", path, "->", target) RenderFile(encoding, rand.Int(), path, target) } else { @@ -119,7 +122,7 @@ func main() { for _, encoding := range settings.Encodings { if encoding.OutDir != "" { - RenderToDir(encoding) + RenderToDir(encoding, settings.Force) } else { log.Fatal("config file needs either Output or OutDir") }