fix merge output; support error to stdout

This commit is contained in:
wanglei.w
2021-06-25 18:54:51 +08:00
parent ea7295fb23
commit 6c40f6e9bb
4 changed files with 21 additions and 5 deletions

View File

@@ -49,3 +49,12 @@ func TestSimpleS3StreamExample(t *testing.T) {
Run()
assert.Nil(t, err)
}
func TestExampleMultipleOutput(t *testing.T) {
input := ffmpeg.Input("./sample_data/in1.mp4").Split()
out1 := input.Get("0").Filter("scale", ffmpeg.Args{"1920:-1"}).Output("./sample_data/1920.mp4", ffmpeg.KwArgs{"b:v": "5000k"})
out2 := input.Get("1").Filter("scale", ffmpeg.Args{"1280:-1"}).Output("./sample_data/1280.mp4", ffmpeg.KwArgs{"b:v": "2800k"})
err := ffmpeg.MergeOutputs(out1, out2).OverWriteOutput().ErrorToStdOut().Run()
assert.Nil(t, err)
}

View File

@@ -52,10 +52,7 @@ func (s *Stream) OverwriteOutput(stream *Stream) *Stream {
}
// Include all given outputs in one ffmpeg command line
func (s *Stream) MergeOutputs(streams ...*Stream) *Stream {
if s.Type != "OutputStream" {
panic("cannot merge outputs on non-OutputStream")
}
func MergeOutputs(streams ...*Stream) *Stream {
return NewMergeOutputsNode("merge_output", streams).Stream("", "")
}

View File

@@ -260,7 +260,7 @@ func (n *Node) GetFilter(outgoingEdges []DagEdge) string {
if n.name == "split" || n.name == "asplit" {
args = []string{fmt.Sprintf("%d", len(outgoingEdges))}
}
args = Args(args).EscapeWith("\\'=:")
// args = Args(args).EscapeWith("\\'=:")
for _, k := range kwargs.EscapeWith("\\'=:").SortedKeys() {
v := getString(kwargs[k])
if v != "" {

10
run.go
View File

@@ -4,6 +4,7 @@ import (
"context"
"fmt"
"io"
"os"
"os/exec"
"sort"
"strings"
@@ -225,6 +226,15 @@ func (s *Stream) WithOutput(out ...io.Writer) *Stream {
return s
}
func (s *Stream) WithErrorOutput(out io.Writer) *Stream {
s.Context = context.WithValue(s.Context, "Stderr", out)
return s
}
func (s *Stream) ErrorToStdOut() *Stream {
return s.WithErrorOutput(os.Stdout)
}
// for test
func (s *Stream) Compile() *exec.Cmd {
args := s.GetArgs()