-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcommand.go
51 lines (44 loc) · 1.19 KB
/
command.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
// Copyright 2015 Dave Gradwell
// Under BSD-style license (see LICENSE file)
// Package ff implements an ffmpeg (or ffprobe) command-line parameter builder
package ff
import (
"fmt"
)
// Represents the entire commandline for ffmpeg/ffprobe
type Command struct {
Path string
Input File
Outputs []File
}
// You can pass in only input (for ffprobe).
// You can pass in one or more outputs.
// Returns a new Command structure
func NewCommand(path string, input File, outputs ...File) (cmd *Command, err error) {
if path == "" {
return nil, fmt.Errorf("Cannot create a Command with no path")
}
if input == nil {
return nil, fmt.Errorf("Cannot create a Command with no input")
}
cmd = &Command{
Path: path,
Input: input,
}
for _, output := range outputs {
if output != nil {
cmd.Outputs = append(cmd.Outputs, output)
}
}
return cmd, nil
}
// Returns a []string slice of how a ffmpeg/ffprobe call should be represented.
// Does not include the command Path before it
func (c *Command) Slice() (results []string) {
results = []string{}
results = append(results, c.Input.Slice()...)
for _, output := range c.Outputs {
results = append(results, output.Slice()...)
}
return
}