mirror of
https://github.com/u2takey/ffmpeg-go.git
synced 2025-10-04 23:52:42 +08:00
fix merge output; support error to stdout
This commit is contained in:
@@ -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)
|
||||
}
|
||||
|
@@ -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("", "")
|
||||
}
|
||||
|
||||
|
2
node.go
2
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 != "" {
|
||||
|
10
run.go
10
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()
|
||||
|
Reference in New Issue
Block a user