summaryrefslogtreecommitdiff
path: root/mkvlib/ass2pgs_windows.go
diff options
context:
space:
mode:
Diffstat (limited to 'mkvlib/ass2pgs_windows.go')
-rw-r--r--mkvlib/ass2pgs_windows.go68
1 files changed, 68 insertions, 0 deletions
diff --git a/mkvlib/ass2pgs_windows.go b/mkvlib/ass2pgs_windows.go
new file mode 100644
index 0000000..8068e31
--- /dev/null
+++ b/mkvlib/ass2pgs_windows.go
@@ -0,0 +1,68 @@
+//go:build windows && amd64
+
+package mkvlib
+
+import (
+ "fmt"
+ "path"
+ "strconv"
+ "syscall"
+ "unsafe"
+)
+
+func ass2Pgs(input []string, resolution, frameRate int, fontsDir string, output string, lcb logCallback) bool {
+ fonts := findFonts(fontsDir)
+ r := addFontResource(fonts, lcb)
+ if r {
+ for _, item := range input {
+ _, _, _, _f := splitPath(item)
+ fn := path.Join(output, _f+".pgs")
+ args := make([]string, 0)
+ args = append(args, "-x0")
+ args = append(args, "-v144")
+ args = append(args, "-s", strconv.Itoa(resolution))
+ args = append(args, "-r", strconv.Itoa(frameRate))
+ args = append(args, "-i", item)
+ args = append(args, fn)
+ if p, err := newProcess(nil, nil, nil, "", spp2pgs, args...); err == nil {
+ s, err := p.Wait()
+ r = err == nil && s.ExitCode() == 1
+ if !r {
+ printLog(lcb, fmt.Sprintf(`Failed to Ass2Pgs:"%s"`, item))
+ }
+ }
+ }
+ }
+ removeFontResource(fonts, lcb)
+ return r
+}
+
+var gdi32 = syscall.NewLazyDLL("gdi32.dll")
+var addFontResourceW = gdi32.NewProc("AddFontResourceW")
+var removeFontResourceW = gdi32.NewProc("RemoveFontResourceW")
+
+func addFontResource(fonts []string, lcb logCallback) bool {
+ ec := 0
+ for _, item := range fonts {
+ p, _ := syscall.UTF16FromString(item)
+ r, _, _ := addFontResourceW.Call(uintptr(unsafe.Pointer(&p[0])))
+ if r == 0 {
+ printLog(lcb, fmt.Sprintf(`Failed to load font:"%s"`, item))
+ ec++
+ }
+ }
+ return ec == 0
+}
+
+func removeFontResource(fonts []string, lcb logCallback) bool {
+ ec := 0
+ for _, item := range fonts {
+ p, _ := syscall.UTF16FromString(item)
+ r, _, _ := removeFontResourceW.Call(uintptr(unsafe.Pointer(&p[0])))
+ if r == 0 {
+ printLog(lcb, fmt.Sprintf(`Failed to unload font:"%s"`, item))
+ ec++
+ }
+ }
+ return ec == 0
+}