From 597a2ba7c14696fadd94ffdcac42c66ca81f9b6e Mon Sep 17 00:00:00 2001 From: "Zed A. Shaw" Date: Mon, 17 Nov 2025 00:34:45 -0500 Subject: [PATCH] Can now do dash encodings and handles 2 passes or 1 pass dash. Also doesn't do the ffmpeg log if it's only one pass. --- config.json | 56 +++++++++++++++++++++++++++++++++++++++++----- config/settings.go | 1 + main.go | 35 ++++++++++++++++++++--------- 3 files changed, 76 insertions(+), 16 deletions(-) diff --git a/config.json b/config.json index 024ffab..db76945 100644 --- a/config.json +++ b/config.json @@ -7,14 +7,60 @@ "AudioBitrate": 192, "VideoCodec": "libvpx-vp9", "CleanFilename": false, - "CRF": 20, + "CRF": 30, "FPS": 30, - "Tune": "animation", - "Input": "LGo*.mp4", + "Input": "test_video.mp4", "OutDir": "dash_test", - "Passes": 1, + "Passes": 2, + "Extras": [ + "-row-mt", "1", + "-cpu-used", "8", + "-g", "150", + "-keyint_min", "150", + "-tile-columns", "4", + "-tile-rows", "2", + "-frame-parallel", "1", + "-tune-content", "1" + ] + }, + { + "Format": "webm", + "Scale": "1280:720", + "Resize": false, + "VideoBitrate": 600, + "AudioBitrate": 192, + "VideoCodec": "libvpx-vp9", + "CleanFilename": false, + "CRF": 30, + "FPS": 30, + "Input": "test_video.mp4", + "OutDir": "dash_test", + "Passes": 2, + "Extras": [ + "-row-mt", "1", + "-cpu-used", "8", + "-g", "150", + "-keyint_min", "150", + "-tile-columns", "4", + "-tile-rows", "2", + "-frame-parallel", "1", + "-tune-content", "1" + ] + }, + { + "Format": "webm", + "Scale": "640:360", + "Resize": false, + "VideoBitrate": 300, + "AudioBitrate": 192, + "VideoCodec": "libvpx-vp9", + "CleanFilename": false, + "CRF": 30, + "FPS": 30, + "Input": "test_video.mp4", + "OutDir": "dash_test", + "Passes": 2, "Extras": [ - "-deadline", "realtime", "-row-mt", "1", "-cpu-used", "8", "-g", "150", diff --git a/config/settings.go b/config/settings.go index fdf8865..b62e1f9 100644 --- a/config/settings.go +++ b/config/settings.go @@ -17,6 +17,7 @@ type VideoOpts struct { AudioCodec string Preset string CleanFilename bool + Dash bool CRF int FPS int Tune string diff --git a/main.go b/main.go index 00f4110..7d486d7 100644 --- a/main.go +++ b/main.go @@ -31,8 +31,12 @@ func Run(encoding config.VideoOpts, pass int, pid int, input string, output stri extras := []string{ "-pix_fmt", "yuv420p", - "-pass", fmt.Sprint(pass), - "-passlogfile", fmt.Sprintf("ffmpegpass-%x.log", pid), + } + + if encoding.Passes > 1 { + extras = append(extras, + "-pass", fmt.Sprint(pass), + "-passlogfile", fmt.Sprintf("ffmpegpass-%x.log", pid)) } if encoding.Preset != "" { @@ -45,7 +49,8 @@ func Run(encoding config.VideoOpts, pass int, pid int, input string, output stri "-aspect", encoding.Scale) } - if pass != encoding.Passes { + if pass != encoding.Passes || encoding.Dash { + // BUG: warn that dash removes audio extras = append(extras, "-an") } else { encode.AudioCodec(encoding.AudioCodec) @@ -53,25 +58,33 @@ func Run(encoding config.VideoOpts, pass int, pid int, input string, output stri "-b:a", fmt.Sprint(encoding.AudioBitrate * 1024)) } + if encoding.Test > 0 { encode.InputOptions("-ss", fmt.Sprintf("00:%d", encoding.TestStart)) extras = append(extras, "-t", fmt.Sprint(encoding.Test)) } encode.VideoCodec(encoding.VideoCodec). - VideoBitRate(encoding.VideoBitrate * 1024). - FrameRate(encoding.FPS). - ConstantRateFactor(encoding.CRF) + VideoBitRate(encoding.VideoBitrate * 1024). + FrameRate(encoding.FPS). + ConstantRateFactor(encoding.CRF) + extras = append(extras, encoding.Extras...) + + if encoding.Dash { + extras = append(extras, "-dash", "1") + } + encode.OutputOptions(extras...) + cmd := encode.InputPath(input). - OutputFormat(encoding.Format). - OutputPath(output). - OutputLogs(os.Stdout). - Overwrite(true). - Build() + OutputFormat(encoding.Format). + OutputPath(output). + OutputLogs(os.Stdout). + Overwrite(true). + Build() fmt.Println(">", cmd.String())