From be44bcec226c7bf40548728a7e8e888db906a98f Mon Sep 17 00:00:00 2001 From: "Zed A. Shaw" Date: Wed, 19 Nov 2025 23:31:56 -0500 Subject: [PATCH] Confirmed everything works on Windows. --- config.json | 8 ++++---- go.mod | 5 +---- go.sum | 2 -- main.go | 35 +++++++++++++++++++++-------------- 4 files changed, 26 insertions(+), 24 deletions(-) diff --git a/config.json b/config.json index 03d8c32..cd75f5d 100644 --- a/config.json +++ b/config.json @@ -2,21 +2,21 @@ { "Format": "webm", "Variants": [ - { + { "Scale": "1920:1080", "Resize": false, "VideoBitrate": 900, "AudioCodec": "none", "VideoCodec": "libvpx-vp9" }, - { + { "Scale": "1280:720", "Resize": true, "VideoBitrate": 600, "AudioCodec": "none", "VideoCodec": "libvpx-vp9" }, - { + { "Scale": "640:360", "Resize": true, "VideoBitrate": 300, @@ -31,7 +31,7 @@ ], "CRF": 30, "FPS": 30, - "Input": "test_video.mp4", + "Input": "test*.mp4", "OutDir": "dash_test", "Passes": 1, "Dash": true, diff --git a/go.mod b/go.mod index 8b735ce..7e1f2c3 100644 --- a/go.mod +++ b/go.mod @@ -2,10 +2,7 @@ module lcthw.dev/go/vidcrunch go 1.24.2 -require ( - github.com/modfy/fluent-ffmpeg v0.1.0 - github.com/zencoder/go-dash v0.0.0-20201006100653-2f93b14912b2 -) +require github.com/modfy/fluent-ffmpeg v0.1.0 require ( github.com/fatih/structs v1.1.0 // indirect diff --git a/go.sum b/go.sum index fcf9b72..891cde9 100644 --- a/go.sum +++ b/go.sum @@ -4,5 +4,3 @@ github.com/modfy/fluent-ffmpeg v0.1.0 h1:9T191rhSK6KfoDo9Y/+0Tph3khrudvLQEEi05O+ github.com/modfy/fluent-ffmpeg v0.1.0/go.mod h1:GauXGqGYAmYFupCWG8n1eyuLZMKmLxGTGvszYkJ0Oyo= github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4= github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= -github.com/zencoder/go-dash v0.0.0-20201006100653-2f93b14912b2 h1:0iAY2pL6yYhNYpdc1DbFq0p7ocyu5MlgKmkealhz3nk= -github.com/zencoder/go-dash v0.0.0-20201006100653-2f93b14912b2/go.mod h1:c8Gxxfmh0jmZ6G+ISlpa315WBVkzd8mEhu6gN9mn5Qg= diff --git a/main.go b/main.go index 341b596..17c872c 100644 --- a/main.go +++ b/main.go @@ -15,7 +15,6 @@ import ( "os/exec" "slices" "iter" - "path" ) func AudioOnly(codec config.CodecOpts) bool { @@ -42,6 +41,7 @@ func ExtractBase(source_path string, outdir string) (string, string) { func SetCodecTarget(codec *config.CodecOpts, source_path string, encoding config.EncodeOpts) { dir, base := ExtractBase(source_path, encoding.OutDir) + dot_or_dash := "."; if encoding.Dash { dot_or_dash = "/" } if AudioOnly(*codec) { @@ -52,6 +52,8 @@ func SetCodecTarget(codec *config.CodecOpts, source_path string, encoding config renamed := fmt.Sprint(base, dot_or_dash, dim, ".", encoding.Format) codec.Target = filepath.Join(dir, renamed) } + + codec.Target = filepath.ToSlash(codec.Target) } func Run(encoding config.EncodeOpts, codec config.CodecOpts, pass int, pid int, input string, output string) { @@ -62,7 +64,7 @@ func Run(encoding config.EncodeOpts, codec config.CodecOpts, pass int, pid int, } if encoding.Passes > 1 { - extras = append(extras, + extras = append(extras, "-pass", fmt.Sprint(pass), "-passlogfile", fmt.Sprintf("ffmpegpass-%x.log", pid)) } @@ -114,7 +116,7 @@ func Run(encoding config.EncodeOpts, codec config.CodecOpts, pass int, pid int, Overwrite(true). Build() - fmt.Println(">", cmd.String()) + fmt.Println("====== FFMPEG ======\n", cmd.String(), "\n============") err := cmd.Run() if err != nil { log.Fatalf("%v", err) } @@ -128,6 +130,11 @@ func DevNull() string { } } +func FileExists(path string) bool { + _, err := os.Stat(path) + return err == nil +} + func RenderFile(encoding config.EncodeOpts, pid int, source_path string, force bool) { for i := 0; i < len(encoding.Variants); i++ { codec := &encoding.Variants[i] @@ -135,15 +142,16 @@ func RenderFile(encoding config.EncodeOpts, pid int, source_path string, force b SetCodecTarget(codec, source_path, encoding) // ensure the target directories exist - target_dir := path.Dir(codec.Target) - err := os.MkdirAll(target_dir, 0750) - if err != nil { - log.Fatal("failed to make target path: %s: %v", target_dir, err) - } + target_dir := filepath.Dir(codec.Target) - _, err = os.Stat(codec.Target) + if !FileExists(codec.Target) { + err := os.MkdirAll(target_dir, 0750) + if err != nil { + log.Fatal("failed to make target path: %s: %v", target_dir, err) + } + } - if err == nil && !force { + if FileExists(codec.Target) && !force { fmt.Println("^^^ SKIP", source_path, "->", codec.Target) return } @@ -205,11 +213,11 @@ func SaveMPD(source_path string, encoding config.EncodeOpts) { args = append(args, adapt_set) dir, base := ExtractBase(source_path, encoding.OutDir) - args = append(args, filepath.Join(dir, base, "manifest.mpd")) - - fmt.Println("\n\n\n\nARGS", args) + mpd_path := filepath.ToSlash(filepath.Join(dir, base, "manifest.mpd")) + args = append(args, mpd_path) ffmpeg := exec.Command("ffmpeg", args...) + fmt.Println("==== MPD COMMAND ====\n", ffmpeg.String(), "\n==============") out, err := ffmpeg.CombinedOutput() os.Stdout.Write(out) @@ -240,7 +248,6 @@ func main() { log.Fatal(http.ListenAndServe(settings.Port, nil)) } else { for i := 0; i < len(settings.Encodings); i++ { - fmt.Println("LOOP", i) encoding := &settings.Encodings[i]; if encoding.OutDir != "" {