diff --git a/node.go b/node.go index 941a489..8722200 100644 --- a/node.go +++ b/node.go @@ -10,12 +10,11 @@ import ( ) type Stream struct { - Node *Node - Label Label - Selector Selector - Type string - FfmpegPath string - Context context.Context + Node *Node + Label Label + Selector Selector + Type string + Context context.Context } type RunHook struct { @@ -28,12 +27,11 @@ type RunHook struct { func NewStream(node *Node, streamType string, label Label, selector Selector) *Stream { return &Stream{ - Node: node, - Label: label, - Selector: selector, - Type: streamType, - FfmpegPath: "ffmpeg", - Context: context.Background(), + Node: node, + Label: label, + Selector: selector, + Type: streamType, + Context: context.Background(), } } diff --git a/run.go b/run.go index c08c9f2..63fba80 100644 --- a/run.go +++ b/run.go @@ -243,7 +243,7 @@ var GlobalCommandOptions = make([]CommandOption, 0) type CompilationOption func(s *Stream, cmd *exec.Cmd) func (s *Stream) SetFfmpegPath(path string) *Stream { - s.FfmpegPath = path + s.Context = context.WithValue(s.Context, "ffmpeg_path", path) return s } @@ -255,7 +255,11 @@ func (s *Stream) Silent(isSilent bool) *Stream { } func (s *Stream) Compile(options ...CompilationOption) *exec.Cmd { args := s.GetArgs() - cmd := exec.CommandContext(s.Context, s.FfmpegPath, args...) + ffmpegPath := "ffmpeg" + if a, ok := s.Context.Value("ffmpeg_path").(string); ok && a != "" { + ffmpegPath = a + } + cmd := exec.CommandContext(s.Context, ffmpegPath, args...) if a, ok := s.Context.Value("Stdin").(io.Reader); ok { cmd.Stdin = a } @@ -268,7 +272,7 @@ func (s *Stream) Compile(options ...CompilationOption) *exec.Cmd { for _, option := range GlobalCommandOptions { option(cmd) } - if LogCompiledCommand { + if LogCompiledCommand { log.Printf("compiled command: ffmpeg %s\n", strings.Join(args, " ")) } return cmd