Get the ffmpeg command regardless of the platform

This commit is contained in:
frr
2018-02-27 13:58:56 +01:00
parent aa676ed4f3
commit 2e2a6c763c
3 changed files with 79 additions and 6 deletions

View File

@@ -4,19 +4,27 @@ import (
"os/exec" "os/exec"
"bytes" "bytes"
"strings" "strings"
"goffmpeg/utils"
) )
type Configuration struct { type Configuration struct {
FfmpegBin string FfmpegBin string
FfprobeBin string FfprobeBin string
ExecCmd string
ExecArgs string
} }
func Configure() (Configuration, error) { func Configure() (Configuration, error) {
var outFFmpeg bytes.Buffer var outFFmpeg bytes.Buffer
var outProbe bytes.Buffer var outProbe bytes.Buffer
cmdFFmpeg := exec.Command("/bin/sh", "-c", "which ffmpeg") execCmd := utils.GetExec()
cmdProbe := exec.Command("/bin/sh", "-c", "which ffprobe") execFFmpegCommand := utils.GetFFmpegExec()
execFFprobeCommand := utils.GetFFprobeExec()
execArgs := utils.GetExecArgs()
cmdFFmpeg := exec.Command(execCmd, execArgs, execFFmpegCommand)
cmdProbe := exec.Command(execCmd, execArgs, execFFprobeCommand)
cmdFFmpeg.Stdout = &outFFmpeg cmdFFmpeg.Stdout = &outFFmpeg
cmdProbe.Stdout = &outProbe cmdProbe.Stdout = &outProbe
@@ -44,7 +52,7 @@ func Configure() (Configuration, error) {
ffmpeg := strings.Replace(outFFmpeg.String(), "\n", "", -1) ffmpeg := strings.Replace(outFFmpeg.String(), "\n", "", -1)
fprobe := strings.Replace(outProbe.String(), "\n", "", -1) fprobe := strings.Replace(outProbe.String(), "\n", "", -1)
cnf := Configuration{ffmpeg, fprobe} cnf := Configuration{ffmpeg, fprobe, execCmd, execArgs}
return cnf, nil return cnf, nil
} }

View File

@@ -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) 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) fmt.Println("FFprobe command: " + command)
@@ -153,7 +153,7 @@ func (t *Transcoder) Run() (<-chan bool, error) {
fmt.Println("FFmpeg command: " + command) 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) t.SetProccess(proc)

View File

@@ -4,6 +4,7 @@ import (
"strings" "strings"
"strconv" "strconv"
"goffmpeg/models" "goffmpeg/models"
"runtime"
) )
func DurToSec(dur string) (sec float64) { func DurToSec(dur string) (sec float64) {
@@ -21,6 +22,70 @@ func DurToSec(dur string) (sec float64) {
return secs 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 { func CheckFileType(streams []models.Streams) string {
for i := 0; i < len(streams); i++ { for i := 0; i < len(streams); i++ {
st := streams[i] st := streams[i]