diff options
| author | b5f0d6c3 <[email protected]> | 2022-03-10 00:24:55 +0800 |
|---|---|---|
| committer | b5f0d6c3 <[email protected]> | 2022-03-10 00:24:55 +0800 |
| commit | 4ab65022538472627dba5819b2e62d431b37fe6d (patch) | |
| tree | c66bb57a899afb294cc8acc0eea6be49405687f9 /mkvlib/ass2pgs_windows.go | |
| parent | ebfdeb65631a0681373c3c2e6ce9661eb8c7aefa (diff) | |
update mkvlib: add ass to psg support.
Diffstat (limited to 'mkvlib/ass2pgs_windows.go')
| -rw-r--r-- | mkvlib/ass2pgs_windows.go | 68 |
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 +} |
