diff --git a/examples/example_test.go b/examples/example_test.go index 4304556..1a4706d 100644 --- a/examples/example_test.go +++ b/examples/example_test.go @@ -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) +} diff --git a/ffmpeg.go b/ffmpeg.go index ea8a4f1..e909bd1 100644 --- a/ffmpeg.go +++ b/ffmpeg.go @@ -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("", "") } diff --git a/node.go b/node.go index c9ca2a9..048ff01 100644 --- a/node.go +++ b/node.go @@ -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 != "" { diff --git a/run.go b/run.go index 010ce16..e0d3e4c 100644 --- a/run.go +++ b/run.go @@ -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()