Initial commit
This commit is contained in:
commit
73d8aa9111
5
go.mod
Normal file
5
go.mod
Normal file
@ -0,0 +1,5 @@
|
||||
module git.narnian.us/lordwelch/other-benchmark
|
||||
|
||||
go 1.15
|
||||
|
||||
require github.com/jaypipes/ghw v0.8.0
|
31
go.sum
Normal file
31
go.sum
Normal file
@ -0,0 +1,31 @@
|
||||
github.com/StackExchange/wmi v0.0.0-20190523213315-cbe66965904d h1:G0m3OIz70MZUWq3EgK3CesDbo8upS2Vm9/P3FtgI+Jk=
|
||||
github.com/StackExchange/wmi v0.0.0-20190523213315-cbe66965904d/go.mod h1:3eOhrUMpNV+6aFIbp5/iudMxNCF27Vw2OZgy4xEx0Fg=
|
||||
github.com/ghodss/yaml v1.0.0 h1:wQHKEahhL6wmXdzwWG11gIVCkOv05bNOh+Rxn0yngAk=
|
||||
github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04=
|
||||
github.com/go-ole/go-ole v1.2.4 h1:nNBDSCOigTSiarFpYE9J/KtEA1IOW4CNeqT9TQDqCxI=
|
||||
github.com/go-ole/go-ole v1.2.4/go.mod h1:XCwSNxSkXRo4vlyPy93sltvi/qJq0jqQhjqQNIwKuxM=
|
||||
github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANytuPF1OarO4DADm73n8=
|
||||
github.com/jaypipes/ghw v0.8.0 h1:02q1pTm9CD83vuhBsEZZhOCS128pq87uyaQeJZkp3sQ=
|
||||
github.com/jaypipes/ghw v0.8.0/go.mod h1:+gR9bjm3W/HnFi90liF+Fj9GpCe/Dsibl9Im8KmC7c4=
|
||||
github.com/jaypipes/pcidb v0.6.0 h1:VIM7GKVaW4qba30cvB67xSCgJPTzkG8Kzw/cbs5PHWU=
|
||||
github.com/jaypipes/pcidb v0.6.0/go.mod h1:L2RGk04sfRhp5wvHO0gfRAMoLY/F3PKv/nwJeVoho0o=
|
||||
github.com/jessevdk/go-flags v1.4.0/go.mod h1:4FA24M0QyGHXBuZZK/XkWh8h0e1EYbRYJSGM75WSRxI=
|
||||
github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI=
|
||||
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
|
||||
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
|
||||
github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE=
|
||||
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
|
||||
github.com/mitchellh/go-homedir v1.0.0 h1:vKb8ShqSby24Yrqr/yDYkuFz8d0WUjys40rvnGC8aR0=
|
||||
github.com/mitchellh/go-homedir v1.0.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0=
|
||||
github.com/pkg/errors v0.8.0 h1:WdK/asTD0HN+q6hsWO3/vpuAkAr+tw6aNJNDFFf0+qw=
|
||||
github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
|
||||
github.com/spf13/cobra v0.0.3/go.mod h1:1l0Ry5zgKvJasoi3XT1TypsSe7PqH0Sj9dhYf7v3XqQ=
|
||||
github.com/spf13/pflag v1.0.2/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnInEg4=
|
||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 h1:qIbj1fsPNlZgppZ+VLlY7N33q108Sa+fhmuc+sWQYwY=
|
||||
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||
gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
||||
gopkg.in/yaml.v2 v2.2.2 h1:ZCJp+EgiOT7lHqUV2J862kp8Qj64Jo6az82+3Td9dZw=
|
||||
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
||||
howett.net/plist v0.0.0-20181124034731-591f970eefbb h1:jhnBjNi9UFpfpl8YZhA9CrOqpnJdvzuiHsl/dnxl11M=
|
||||
howett.net/plist v0.0.0-20181124034731-591f970eefbb/go.mod h1:vMygbs4qMhSZSc4lCUl2OEE+rDiIIJAIdR4m7MiMcm0=
|
143
other-benchmark.go
Normal file
143
other-benchmark.go
Normal file
@ -0,0 +1,143 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"flag"
|
||||
"fmt"
|
||||
"os"
|
||||
"os/exec"
|
||||
"path/filepath"
|
||||
"runtime"
|
||||
"strings"
|
||||
|
||||
"github.com/jaypipes/ghw"
|
||||
)
|
||||
|
||||
func main() {
|
||||
var (
|
||||
file = flag.String("file", "", "file to transcode")
|
||||
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)")
|
||||
runs = flag.Int("runs", 1, "number of times to do the same encode")
|
||||
args = []string{}
|
||||
format = "x264"
|
||||
filename string
|
||||
)
|
||||
flag.Parse()
|
||||
basename := filepath.Base(*file)
|
||||
if *outname == "" {
|
||||
filename = filepath.Base(*file)
|
||||
} else {
|
||||
filename = *outname
|
||||
if filepath.Ext(filename) == "" {
|
||||
filename += ".mkv"
|
||||
}
|
||||
}
|
||||
|
||||
gpu, err := ghw.GPU()
|
||||
if err != nil {
|
||||
fmt.Printf("Error getting GPU info: %v", err)
|
||||
}
|
||||
|
||||
cpu, err := ghw.CPU()
|
||||
if err != nil {
|
||||
fmt.Printf("Error getting CPU info: %v", err)
|
||||
}
|
||||
cpuName := strings.ToLower(cpu.Processors[0].Model)
|
||||
for _, rep := range []struct {
|
||||
old string
|
||||
new string
|
||||
}{
|
||||
{"amd", ""},
|
||||
{"ryzen ", "r"},
|
||||
{"8-core", ""},
|
||||
{"7-core", ""},
|
||||
{"6-core", ""},
|
||||
{"5-core", ""},
|
||||
{"4-core", ""},
|
||||
{"processor", ""},
|
||||
} {
|
||||
cpuName = strings.ReplaceAll(cpuName, rep.old, rep.new)
|
||||
}
|
||||
|
||||
cpuName = strings.ReplaceAll(strings.TrimSpace(cpuName), " ", "-")
|
||||
gpuName := strings.ToLower(gpu.GraphicsCards[0].DeviceInfo.Product.Name)
|
||||
if strings.Contains(gpuName, "[") {
|
||||
gpuName = strings.Split(strings.Split(gpuName, "[")[1], "]")[0]
|
||||
}
|
||||
for _, rep := range []struct {
|
||||
old string
|
||||
new string
|
||||
}{
|
||||
{"amd", ""},
|
||||
{"radeon ", "r"},
|
||||
{"nvidia", ""},
|
||||
{"geforce", ""},
|
||||
{"processor", ""},
|
||||
} {
|
||||
gpuName = strings.ReplaceAll(gpuName, rep.old, rep.new)
|
||||
}
|
||||
|
||||
gpuName = strings.ReplaceAll(strings.TrimSpace(gpuName), " ", "-")
|
||||
|
||||
hardwareName := gpuName
|
||||
|
||||
if *hevc {
|
||||
args = []string{"--hevc"}
|
||||
format = "x265"
|
||||
}
|
||||
|
||||
if *lib {
|
||||
hardwareName = cpuName
|
||||
if *hevc {
|
||||
args = []string{"--x265"}
|
||||
} else {
|
||||
args = []string{"--x264"}
|
||||
}
|
||||
}
|
||||
args = append(args, *file)
|
||||
GOOS := runtime.GOOS
|
||||
if len(GOOS) > 5 {
|
||||
GOOS = GOOS[:5]
|
||||
}
|
||||
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)
|
||||
} else {
|
||||
for i := 1; i <= *runs; i++ {
|
||||
transcode(args, basename, o, i)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func transcode(args []string, basename, outname string, run int) {
|
||||
fmt.Println("other-transcode", args)
|
||||
cmd := exec.Command("other-transcode", args...)
|
||||
cmd.Stdout = os.Stdout
|
||||
cmd.Stderr = os.Stderr
|
||||
err := cmd.Run()
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
stat, err := os.Stat(basename)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
var result string
|
||||
if run > 0 {
|
||||
result = fmt.Sprintf(outname+".%03d.%012d%s", run, stat.Size(), filepath.Ext(basename))
|
||||
} else {
|
||||
result = fmt.Sprintf(outname+".%012d%s", stat.Size(), filepath.Ext(basename))
|
||||
}
|
||||
fmt.Println(result)
|
||||
err = os.Rename(basename, result)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
err = os.Rename(basename+".log", result+".log")
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user