command wrapper

making transcoder
This commit is contained in:
frr
2018-01-28 14:15:41 +01:00
parent 731b6145ac
commit e545a08502
2 changed files with 65 additions and 1 deletions

View File

@@ -6,6 +6,10 @@ import (
"errors"
"os"
"goffmpeg/models"
"os/exec"
"fmt"
"goffmpeg/ffmpeg"
"bytes"
)
type Transcoder struct {
@@ -15,14 +19,45 @@ type Transcoder struct {
MediaFile *models.Mediafile
}
func New(inputPath *string) (*Transcoder, error) {
func New(inputPath *string, configuration *ffmpeg.Configuration) (*Transcoder, error) {
transcoding := new(Transcoder)
if inputPath == nil {
return nil, errors.New("error: transcoder.Initialize -> inputPath missing")
}
_, err := os.Stat(*inputPath)
if os.IsNotExist(err) {
return nil, errors.New("error: transcoder.Initialize -> input file not found")
}
// Set input path
transcoding.InputPath = *inputPath
// TODO: Get file metadata from ffprobe and set MediaFile
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)
var out bytes.Buffer
cmd.Stdout = &out
cmdErr := cmd.Start()
if cmdErr != nil {
return nil, cmdErr
}
_, errProc := cmd.Process.Wait()
if errProc != nil {
return nil, errProc
}
stdout := out.String()
fmt.Println(stdout)
transcoding.MediaFile = new(models.Mediafile)
return transcoding, nil