|
|
|
@ -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") |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|