mirror of
https://github.com/xfrr/goffmpeg.git
synced 2025-10-17 13:30:48 +08:00
Get the ffmpeg command regardless of the platform
This commit is contained in:
@@ -4,19 +4,27 @@ import (
|
||||
"os/exec"
|
||||
"bytes"
|
||||
"strings"
|
||||
"goffmpeg/utils"
|
||||
)
|
||||
|
||||
type Configuration struct {
|
||||
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
|
||||
}
|
||||
|
@@ -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)
|
||||
|
||||
|
@@ -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]
|
||||
|
Reference in New Issue
Block a user