Skip to content

Commit

Permalink
Fixed config handler
Browse files Browse the repository at this point in the history
  • Loading branch information
frr committed Jan 15, 2019
1 parent e29085b commit 33bbff0
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 12 deletions.
11 changes: 2 additions & 9 deletions ffmpeg/ffmpeg.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package ffmpeg

import (
"bytes"
"os/exec"
"strings"

"github.com/xfrr/goffmpeg/utils"
Expand All @@ -22,18 +21,12 @@ func Configure() (Configuration, error) {
execFFmpegCommand := utils.GetFFmpegExec()
execFFprobeCommand := utils.GetFFprobeExec()

cmdFFmpeg := exec.Command(execFFmpegCommand[0], execFFmpegCommand[1])
cmdProbe := exec.Command(execFFprobeCommand[0], execFFprobeCommand[1])

cmdFFmpeg.Stdout = &outFFmpeg
cmdProbe.Stdout = &outProbe

err := cmdFFmpeg.Run()
outFFmpeg, err := utils.TestCmd(execFFmpegCommand[0], execFFmpegCommand[1])
if err != nil {
return Configuration{}, err
}

err = cmdProbe.Run()
outProbe, err = utils.TestCmd(execFFprobeCommand[0], execFFprobeCommand[1])
if err != nil {
return Configuration{}, err
}
Expand Down
3 changes: 1 addition & 2 deletions transcoder/transcoder.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,6 @@ func (t *Transcoder) Initialize(inputPath string, outputPath string) error {
if len(cfg.FfmpegBin) == 0 || len(cfg.FfprobeBin) == 0 {
cfg, err = ffmpeg.Configure()
if err != nil {
fmt.Println(err)
return err
}
}
Expand All @@ -111,7 +110,7 @@ func (t *Transcoder) Initialize(inputPath string, outputPath string) error {

err = cmd.Run()
if err != nil {
return fmt.Errorf("Failed FFPROBE (%s) with %s, message %s", command, err, out.String())
return fmt.Errorf("error executing (%s) | error: %s", command, err)
}

if err = json.Unmarshal([]byte(out.String()), &Metadata); err != nil {
Expand Down
21 changes: 20 additions & 1 deletion utils/utils.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
package utils

import (
"github.com/xfrr/goffmpeg/models"
"bytes"
"os/exec"
"runtime"
"strconv"
"strings"

"github.com/xfrr/goffmpeg/models"
)

func DurToSec(dur string) (sec float64) {
Expand Down Expand Up @@ -72,3 +75,19 @@ func LineSeparator() string {
return "\n"
}
}

// TestCmd ...
func TestCmd(command string, args string) (bytes.Buffer, error) {
var out bytes.Buffer

cmd := exec.Command(command, args)

cmd.Stdout = &out

err := cmd.Run()
if err != nil {
return out, err
}

return out, nil
}

0 comments on commit 33bbff0

Please sign in to comment.