-
Notifications
You must be signed in to change notification settings - Fork 9
/
format-convert.go
56 lines (48 loc) · 1.01 KB
/
format-convert.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
package main
import (
"os/exec"
"runtime"
"syscall"
ffmpeg "github.com/u2takey/ffmpeg-go"
)
func (a *App) Checkffmpeg() bool {
return Checkffmpeg()
}
// 检查系统中是否安装 ffmpeg
// (临时方案)
func Checkffmpeg() bool {
switch runtime.GOOS {
case "windows":
return checkffmpegOnWindows()
case "darwin":
return checkffmpegOnMacOS()
default:
return false
}
}
// windows
func checkffmpegOnWindows() bool {
cmd := exec.Command("where", "ffmpeg")
cmd.SysProcAttr = &syscall.SysProcAttr{
HideWindow: true,
}
_, err := cmd.Output()
return err == nil
}
// MacOS
func checkffmpegOnMacOS() bool {
cmd := exec.Command("which", "ffmpeg")
_, err := cmd.Output()
return err == nil
}
// 调用 ffmpeg 转码
func ConventFile(inputFile, outputFile string) error {
stream := ffmpeg.Input(inputFile).Output(outputFile, ffmpeg.KwArgs{"qscale": "0"})
cmd := stream.Compile()
cmd.SysProcAttr = &syscall.SysProcAttr{HideWindow: true}
err := cmd.Run()
if err != nil {
return err
}
return nil
}