Bring back the scale added to files.

master
Zed A. Shaw 24 hours ago
parent b172d1e63a
commit 32887187ca
  1. 1
      .gitignore
  2. 36
      main.go

1
.gitignore vendored

@ -28,3 +28,4 @@ coverage/*
*.gz
public
*.mp4
ffmpeg*

@ -6,12 +6,25 @@ import (
"runtime"
"log"
"os"
// "errors"
// "io/fs"
"math/rand"
"strings"
"lcthw.dev/vidcrunch/config"
"github.com/modfy/fluent-ffmpeg"
)
func ModFile(fname string, scale string) string {
cleaned := filepath.Clean(fname)
dir, file := filepath.Split(cleaned)
ext := filepath.Ext(file)
base, found := strings.CutSuffix(file, ext)
if !found { panic("no extension found?!") }
dim := strings.Replace(scale, ":", ".", 1)
renamed := fmt.Sprint(base, ".", dim, ext)
return filepath.Join(dir, renamed)
}
func Run(pass int, pid int, input string, output string) {
encode := fluentffmpeg.NewCommand("")
@ -23,7 +36,7 @@ func Run(pass int, pid int, input string, output string) {
"-tune", config.Settings.Tune,
"-movflags", "faststart",
"-pass", fmt.Sprint(pass),
"-passlogfile", fmt.Sprintf("ffmpeg2pass-%d.log", pid),
"-passlogfile", fmt.Sprintf("ffmpeg2pass-%x.log", pid),
"-preset", config.Settings.Speed,
}
@ -53,7 +66,7 @@ func Run(pass int, pid int, input string, output string) {
OutputPath(output).
Build()
fmt.Println("COMMAND", cmd.String())
fmt.Println(">", cmd.String())
err := cmd.Run()
if err != nil { log.Fatalf("%v", err) }
@ -68,9 +81,10 @@ func DevNull() string {
}
func RenderFile(pid int, path string, target string) {
Run(1, pid, path, DevNull())
Run(2, pid, path, DevNull())
Run(3, pid, path, target)
target = ModFile(target, config.Settings.Scale)
Run(1, pid, path, DevNull())
Run(2, pid, path, DevNull())
Run(3, pid, path, target)
}
func RenderToDir() {
@ -84,10 +98,10 @@ func RenderToDir() {
_, err := os.Stat(target)
if err != nil {
fmt.Println("PATH", path, "->", target)
RenderFile(1, path, target)
fmt.Println("--- PATH", path, "->", target)
RenderFile(rand.Int(), path, target)
} else {
fmt.Println("SKIP", path, "->", target)
fmt.Println("^^^ SKIP", path, "->", target)
}
}
}
@ -96,7 +110,7 @@ func main() {
config.Load()
if config.Settings.Output != "" {
RenderFile(1, config.Settings.Input, config.Settings.Output)
RenderFile(rand.Int(), config.Settings.Input, config.Settings.Output)
} else if config.Settings.OutDir != "" {
RenderToDir()
} else {

Loading…
Cancel
Save