Skip to content
This repository was archived by the owner on Sep 29, 2023. It is now read-only.
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 11 additions & 20 deletions ffmpeg/ffmpeg.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@ type Transcoder struct {
outputOptions [][]string
metadata transcoder.Metadata
inputPipeReader *io.ReadCloser
outputPipeReader *io.ReadCloser
inputPipeWriter *io.WriteCloser
outputPipeWriter *io.WriteCloser
commandContext *context.Context
}
Expand Down Expand Up @@ -105,7 +103,7 @@ func (t *Transcoder) Start() (<-chan transcoder.Progress, error) {
if t.config.ProgressEnabled && !t.config.Verbose {
stderrIn, err = cmd.StderrPipe()
if err != nil {
return nil, fmt.Errorf("Failed getting transcoding progress (%s) with args (%s) with error %s", t.config.FfmpegBinPath, args, err)
return nil, fmt.Errorf("failed getting transcoding progress (%s) with args (%s) with error %s", t.config.FfmpegBinPath, args, err)
}
}

Expand All @@ -116,7 +114,7 @@ func (t *Transcoder) Start() (<-chan transcoder.Progress, error) {
// Start process
err = cmd.Start()
if err != nil {
return nil, fmt.Errorf("Failed starting transcoding (%s) with args (%s) with error %s", t.config.FfmpegBinPath, args, err)
return nil, fmt.Errorf("failed starting transcoding (%s) with args (%s) with error %s", t.config.FfmpegBinPath, args, err)
}

if t.config.ProgressEnabled && !t.config.Verbose {
Expand Down Expand Up @@ -148,20 +146,16 @@ func (t *Transcoder) Output(arg string) transcoder.Transcoder {
}

// InputPipe ...
func (t *Transcoder) InputPipe(w *io.WriteCloser, r *io.ReadCloser) transcoder.Transcoder {
if &t.input == nil {
t.inputPipeWriter = w
t.inputPipeReader = r
}
func (t *Transcoder) InputPipe(r *io.ReadCloser) transcoder.Transcoder {
t.input = "pipe:"
t.inputPipeReader = r
return t
}

// OutputPipe ...
func (t *Transcoder) OutputPipe(w *io.WriteCloser, r *io.ReadCloser) transcoder.Transcoder {
if &t.output == nil {
t.outputPipeWriter = w
t.outputPipeReader = r
}
func (t *Transcoder) OutputPipe(w *io.WriteCloser) transcoder.Transcoder {
t.output = []string{}
t.outputPipeWriter = w
return t
}

Expand Down Expand Up @@ -235,16 +229,14 @@ func (t *Transcoder) GetMetadata() (transcoder.Metadata, error) {
var outb, errb bytes.Buffer

input := t.input

if t.inputPipeReader != nil {
input = "pipe:"
}

args := []string{"-i", input, "-print_format", "json", "-show_format", "-show_streams", "-show_error"}

cmd := exec.Command(t.config.FfprobeBinPath, args...)
cmd.Stdout = &outb
cmd.Stderr = &errb
if t.inputPipeReader != nil {
cmd.Stdin = *t.inputPipeReader
}

err := cmd.Run()
if err != nil {
Expand All @@ -256,7 +248,6 @@ func (t *Transcoder) GetMetadata() (transcoder.Metadata, error) {
if err = json.Unmarshal([]byte(outb.String()), &metadata); err != nil {
return nil, err
}

t.metadata = metadata

return metadata, nil
Expand Down
Loading