|
|
@ -6,12 +6,25 @@ import ( |
|
|
|
"runtime" |
|
|
|
"runtime" |
|
|
|
"log" |
|
|
|
"log" |
|
|
|
"os" |
|
|
|
"os" |
|
|
|
// "errors"
|
|
|
|
"math/rand" |
|
|
|
// "io/fs"
|
|
|
|
"strings" |
|
|
|
"lcthw.dev/vidcrunch/config" |
|
|
|
"lcthw.dev/vidcrunch/config" |
|
|
|
"github.com/modfy/fluent-ffmpeg" |
|
|
|
"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) { |
|
|
|
func Run(pass int, pid int, input string, output string) { |
|
|
|
encode := fluentffmpeg.NewCommand("") |
|
|
|
encode := fluentffmpeg.NewCommand("") |
|
|
@ -23,7 +36,7 @@ func Run(pass int, pid int, input string, output string) { |
|
|
|
"-tune", config.Settings.Tune, |
|
|
|
"-tune", config.Settings.Tune, |
|
|
|
"-movflags", "faststart", |
|
|
|
"-movflags", "faststart", |
|
|
|
"-pass", fmt.Sprint(pass), |
|
|
|
"-pass", fmt.Sprint(pass), |
|
|
|
"-passlogfile", fmt.Sprintf("ffmpeg2pass-%d.log", pid), |
|
|
|
"-passlogfile", fmt.Sprintf("ffmpeg2pass-%x.log", pid), |
|
|
|
"-preset", config.Settings.Speed, |
|
|
|
"-preset", config.Settings.Speed, |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -53,7 +66,7 @@ func Run(pass int, pid int, input string, output string) { |
|
|
|
OutputPath(output). |
|
|
|
OutputPath(output). |
|
|
|
Build() |
|
|
|
Build() |
|
|
|
|
|
|
|
|
|
|
|
fmt.Println("COMMAND", cmd.String()) |
|
|
|
fmt.Println(">", cmd.String()) |
|
|
|
|
|
|
|
|
|
|
|
err := cmd.Run() |
|
|
|
err := cmd.Run() |
|
|
|
if err != nil { log.Fatalf("%v", err) } |
|
|
|
if err != nil { log.Fatalf("%v", err) } |
|
|
@ -68,9 +81,10 @@ func DevNull() string { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func RenderFile(pid int, path string, target string) { |
|
|
|
func RenderFile(pid int, path string, target string) { |
|
|
|
Run(1, pid, path, DevNull()) |
|
|
|
target = ModFile(target, config.Settings.Scale) |
|
|
|
Run(2, pid, path, DevNull()) |
|
|
|
Run(1, pid, path, DevNull()) |
|
|
|
Run(3, pid, path, target) |
|
|
|
Run(2, pid, path, DevNull()) |
|
|
|
|
|
|
|
Run(3, pid, path, target) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func RenderToDir() { |
|
|
|
func RenderToDir() { |
|
|
@ -84,10 +98,10 @@ func RenderToDir() { |
|
|
|
_, err := os.Stat(target) |
|
|
|
_, err := os.Stat(target) |
|
|
|
|
|
|
|
|
|
|
|
if err != nil { |
|
|
|
if err != nil { |
|
|
|
fmt.Println("PATH", path, "->", target) |
|
|
|
fmt.Println("--- PATH", path, "->", target) |
|
|
|
RenderFile(1, path, target) |
|
|
|
RenderFile(rand.Int(), path, target) |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
fmt.Println("SKIP", path, "->", target) |
|
|
|
fmt.Println("^^^ SKIP", path, "->", target) |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
@ -96,7 +110,7 @@ func main() { |
|
|
|
config.Load() |
|
|
|
config.Load() |
|
|
|
|
|
|
|
|
|
|
|
if config.Settings.Output != "" { |
|
|
|
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 != "" { |
|
|
|
} else if config.Settings.OutDir != "" { |
|
|
|
RenderToDir() |
|
|
|
RenderToDir() |
|
|
|
} else { |
|
|
|
} else { |
|
|
|