@@ -23,7 +23,8 @@ type Transcoder struct {
23
23
config * Config
24
24
input string
25
25
output []string
26
- options [][]string
26
+ inputOptions []string
27
+ outputOptions [][]string
27
28
metadata transcoder.Metadata
28
29
inputPipeReader * io.ReadCloser
29
30
outputPipeReader * io.ReadCloser
@@ -38,7 +39,7 @@ func New(cfg *Config) transcoder.Transcoder {
38
39
}
39
40
40
41
// Start ...
41
- func (t * Transcoder ) Start (opts transcoder. Options ) (<- chan transcoder.Progress , error ) {
42
+ func (t * Transcoder ) Start () (<- chan transcoder.Progress , error ) {
42
43
43
44
var stderrIn io.ReadCloser
44
45
@@ -58,24 +59,30 @@ func (t *Transcoder) Start(opts transcoder.Options) (<-chan transcoder.Progress,
58
59
}
59
60
60
61
// Append input file and standard options
61
- args := append ([]string {"-i" , t .input }, opts .GetStrArguments ()... )
62
+ var args []string
63
+
64
+ if len (t .inputOptions ) > 0 {
65
+ args = append (args , t .inputOptions ... )
66
+ }
67
+
68
+ args = append (args , []string {"-i" , t .input }... )
62
69
outputLength := len (t .output )
63
- optionsLength := len (t .options )
70
+ outputOptionsLength := len (t .outputOptions )
64
71
65
- if outputLength == 1 && optionsLength == 0 {
72
+ if outputLength == 1 && outputOptionsLength == 0 {
66
73
// Just append the 1 output file we've got
67
74
args = append (args , t .output [0 ])
68
75
} else {
69
76
for index , out := range t .output {
70
77
// Get executable flags
71
78
// If we are at the last output file but still have several options, append them all at once
72
- if index == outputLength - 1 && outputLength < optionsLength {
73
- for i := index ; i < len (t .options ); i ++ {
74
- args = append (args , t .options [i ]... )
79
+ if index == outputLength - 1 && outputLength < outputOptionsLength {
80
+ for i := index ; i < len (t .outputOptions ); i ++ {
81
+ args = append (args , t .outputOptions [i ]... )
75
82
}
76
83
// Otherwise just append the current options
77
84
} else {
78
- args = append (args , t .options [index ]... )
85
+ args = append (args , t .outputOptions [index ]... )
79
86
}
80
87
81
88
// Append output flag
@@ -158,15 +165,27 @@ func (t *Transcoder) OutputPipe(w *io.WriteCloser, r *io.ReadCloser) transcoder.
158
165
return t
159
166
}
160
167
161
- // WithOptions Sets the options object
162
- func (t * Transcoder ) WithOptions (opts transcoder.Options ) transcoder.Transcoder {
163
- t .options = [][]string {opts .GetStrArguments ()}
168
+ // WithInputOptions Sets the options object
169
+ func (t * Transcoder ) WithInputOptions (opts transcoder.Options ) transcoder.Transcoder {
170
+ t .inputOptions = opts .GetStrArguments ()
171
+ return t
172
+ }
173
+
174
+ // WithAdditionalInputOptions Appends an additional options object
175
+ func (t * Transcoder ) WithAdditionalInputOptions (opts transcoder.Options ) transcoder.Transcoder {
176
+ t .inputOptions = append (t .inputOptions , opts .GetStrArguments ()... )
177
+ return t
178
+ }
179
+
180
+ // WithOutputOptions Sets the options object
181
+ func (t * Transcoder ) WithOutputOptions (opts transcoder.Options ) transcoder.Transcoder {
182
+ t .outputOptions = [][]string {opts .GetStrArguments ()}
164
183
return t
165
184
}
166
185
167
- // WithAdditionalOptions Appends an additional options object
168
- func (t * Transcoder ) WithAdditionalOptions (opts transcoder.Options ) transcoder.Transcoder {
169
- t .options = append (t .options , opts .GetStrArguments ())
186
+ // WithAdditionalOutputOptions Appends an additional options object
187
+ func (t * Transcoder ) WithAdditionalOutputOptions (opts transcoder.Options ) transcoder.Transcoder {
188
+ t .outputOptions = append (t .outputOptions , opts .GetStrArguments ())
170
189
return t
171
190
}
172
191
@@ -196,7 +215,7 @@ func (t *Transcoder) validate() error {
196
215
197
216
// length of output files being greater than length of options would produce an invalid ffmpeg command
198
217
// unless there is only 1 output file, which obviously wouldn't be a problem
199
- if outputLength > len (t .options ) && outputLength != 1 {
218
+ if outputLength > len (t .outputOptions ) && outputLength != 1 {
200
219
return errors .New ("number of options and output files does not match" )
201
220
}
202
221
0 commit comments