Now works with a directory and glob and won't duplicate work. Fuck os.Stat.

master
Zed A. Shaw 2 days ago
parent 6525c31dbf
commit b172d1e63a
  1. 4
      config.toml
  2. 3
      config/settings.go
  3. 56
      main.go

@ -6,5 +6,5 @@ CleanFilename = false
CRF = 20
FPS = 30
Tune = "animation"
Input = "test.mp4"
Output = "test_render.mp4"
Input = "test*.mp4"
OutDir = "renders"

@ -9,7 +9,6 @@ import (
type config struct {
Test int
TestStart int
InitOutdir bool
Debug int
Progress bool
ConfigPath string
@ -24,6 +23,7 @@ type config struct {
Tune string
Input string
Output string
OutDir string
}
var Settings config
@ -31,7 +31,6 @@ var Settings config
func parseFlags(c *config) {
flag.IntVar(&c.Test, "test", 0, "Make a test video <int> 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")
flag.BoolVar(&c.Progress, "progress", false, "Show percent progress. Not accurate (thanks ffmpeg)")
flag.StringVar(&c.ConfigPath, "config", "config.toml", "config.toml to load")

@ -2,16 +2,18 @@ package main
import (
"fmt"
"path/filepath"
"runtime"
"log"
"os"
// "errors"
// "io/fs"
"lcthw.dev/vidcrunch/config"
"github.com/modfy/fluent-ffmpeg"
)
const DevNull = "NUL"
func Run(pass int, output string) {
pid := 1
func Run(pass int, pid int, input string, output string) {
encode := fluentffmpeg.NewCommand("")
mp4_opts := []string{
@ -46,7 +48,7 @@ func Run(pass int, output string) {
encode.OutputOptions(mp4_opts...)
cmd := encode.InputPath(config.Settings.Input).
cmd := encode.InputPath(input).
OutputFormat("mp4").
OutputPath(output).
Build()
@ -57,11 +59,47 @@ func Run(pass int, output string) {
if err != nil { log.Fatalf("%v", err) }
}
func DevNull() string {
if runtime.GOOS == "windows" {
return "NUL"
} else {
return "/dev/null"
}
}
func RenderFile(pid int, path string, target string) {
Run(1, pid, path, DevNull())
Run(2, pid, path, DevNull())
Run(3, pid, path, target)
}
func RenderToDir() {
matches, err := filepath.Glob(config.Settings.Input)
if err != nil { log.Fatalf("%v", err) }
for _, path := range matches {
base := filepath.Base(path)
target := filepath.Join(config.Settings.OutDir, base)
_, err := os.Stat(target)
if err != nil {
fmt.Println("PATH", path, "->", target)
RenderFile(1, path, target)
} else {
fmt.Println("SKIP", path, "->", target)
}
}
}
func main() {
config.Load()
fmt.Println(config.Settings)
Run(1, DevNull)
Run(2, DevNull)
Run(3, config.Settings.Output)
if config.Settings.Output != "" {
RenderFile(1, config.Settings.Input, config.Settings.Output)
} else if config.Settings.OutDir != "" {
RenderToDir()
} else {
log.Fatal("config file needs either Output or OutDir")
}
}

Loading…
Cancel
Save