From 27594be92b1e1bf40ed56f814f02575834c527aa Mon Sep 17 00:00:00 2001 From: lordwelch Date: Wed, 16 Jun 2021 19:08:34 -0700 Subject: [PATCH] Add -keep flag to keep mkv files after a transcode Change default class to blu --- other-benchmark.go | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/other-benchmark.go b/other-benchmark.go index b60981d..919d957 100644 --- a/other-benchmark.go +++ b/other-benchmark.go @@ -18,7 +18,8 @@ func main() { outname = flag.String("out", "", "file base name to rename result to") hevc = flag.Bool("hevc", false, "transcodes to x265 instead of x264") lib = flag.Bool("lib", false, "uses the x264/x265 software encoder instead of hardware encoder") - class = flag.String("class", "blr", "class of source file (e.g. dvd, blr for bluray)") + keep = flag.Bool("keep", false, "Keeps video file after transcodes") + class = flag.String("class", "blu", "class of source file (e.g. dvd, blu for bluray)") runs = flag.Int("runs", 1, "number of times to do the same encode") args = []string{} format = "x264" @@ -103,15 +104,15 @@ func main() { } o := fmt.Sprintf("%s.% 5s.% 8s.%s.%s", strings.TrimSuffix(filename, filepath.Ext(filename)), GOOS, hardwareName, format, *class) if *runs < 2 { - transcode(args, basename, o, 0) + transcode(args, basename, o, 0, *keep) } else { for i := 1; i <= *runs; i++ { - transcode(args, basename, o, i) + transcode(args, basename, o, i, *keep) } } } -func transcode(args []string, basename, outname string, run int) { +func transcode(args []string, basename, outname string, run int, keep bool) { fmt.Println("other-transcode", args) cmd := exec.Command("other-transcode", args...) cmd.Stdout = os.Stdout @@ -132,9 +133,13 @@ func transcode(args []string, basename, outname string, run int) { result = fmt.Sprintf(outname+".%012d%s", stat.Size(), filepath.Ext(basename)) } fmt.Println(result) - err = os.Rename(basename, result) - if err != nil { - panic(err) + if keep { + err = os.Rename(basename, result) + if err != nil { + panic(err) + } + } else { + os.Remove(basename) } err = os.Rename(basename+".log", result+".log") if err != nil {