diff --git a/ffmpeg/ffmpeg.go b/ffmpeg/ffmpeg.go index c5e8171..5670051 100644 --- a/ffmpeg/ffmpeg.go +++ b/ffmpeg/ffmpeg.go @@ -4,19 +4,27 @@ import ( "os/exec" "bytes" "strings" + "goffmpeg/utils" ) type Configuration struct { - FfmpegBin string + FfmpegBin string FfprobeBin string + ExecCmd string + ExecArgs string } func Configure() (Configuration, error) { var outFFmpeg bytes.Buffer var outProbe bytes.Buffer - cmdFFmpeg := exec.Command("/bin/sh", "-c", "which ffmpeg") - cmdProbe := exec.Command("/bin/sh", "-c", "which ffprobe") + execCmd := utils.GetExec() + execFFmpegCommand := utils.GetFFmpegExec() + execFFprobeCommand := utils.GetFFprobeExec() + execArgs := utils.GetExecArgs() + + cmdFFmpeg := exec.Command(execCmd, execArgs, execFFmpegCommand) + cmdProbe := exec.Command(execCmd, execArgs, execFFprobeCommand) cmdFFmpeg.Stdout = &outFFmpeg cmdProbe.Stdout = &outProbe @@ -44,7 +52,7 @@ func Configure() (Configuration, error) { ffmpeg := strings.Replace(outFFmpeg.String(), "\n", "", -1) fprobe := strings.Replace(outProbe.String(), "\n", "", -1) - cnf := Configuration{ffmpeg, fprobe} + cnf := Configuration{ffmpeg, fprobe, execCmd, execArgs} return cnf, nil } diff --git a/transcoder/transcoder.go b/transcoder/transcoder.go index dbe8aa9..e8e17d1 100644 --- a/transcoder/transcoder.go +++ b/transcoder/transcoder.go @@ -106,7 +106,7 @@ func (t *Transcoder) Initialize(inputPath string, outputPath string) (error) { command := fmt.Sprintf("%s -i %s -print_format json -show_format -show_streams -show_error", configuration.FfprobeBin, inputPath) - cmd := exec.Command("/bin/sh", "-c", command) + cmd := exec.Command(configuration.ExecCmd, configuration.ExecArgs, command) fmt.Println("FFprobe command: " + command) @@ -153,7 +153,7 @@ func (t *Transcoder) Run() (<-chan bool, error) { fmt.Println("FFmpeg command: " + command) - proc := exec.Command("/bin/sh", "-c", command) + proc := exec.Command(t.configuration.ExecCmd, t.configuration.ExecArgs, command) t.SetProccess(proc) diff --git a/utils/utils.go b/utils/utils.go index 06c80ec..e79660a 100644 --- a/utils/utils.go +++ b/utils/utils.go @@ -4,6 +4,7 @@ import ( "strings" "strconv" "goffmpeg/models" + "runtime" ) func DurToSec(dur string) (sec float64) { @@ -21,6 +22,70 @@ func DurToSec(dur string) (sec float64) { return secs } +func GetExec() string { + var platform = runtime.GOOS + var command = "" + + switch platform { + case "windows": + command = "cmd" + break + default: + command = "/bin/sh" + break + } + + return command +} + +func GetExecArgs() string { + var platform = runtime.GOOS + var args = "" + + switch platform { + case "windows": + args = "/C" + break + default: + args = "-c" + break + } + + return args +} + +func GetFFmpegExec() string { + var platform = runtime.GOOS + var command = "" + + switch platform { + case "windows": + command = "where ffmpeg" + break + default: + command = "which ffmpeg" + break + } + + return command +} + +func GetFFprobeExec() string { + var platform = runtime.GOOS + var command = "" + + switch platform { + case "windows": + command = "where ffprobe" + break + default: + command = "which ffprobe" + break + } + + return command +} + func CheckFileType(streams []models.Streams) string { for i := 0; i < len(streams); i++ { st := streams[i]