@@ -39,6 +39,7 @@ func New(cfg *Config) transcoder.Transcoder {
39
39
func (t * Transcoder ) Start (opts transcoder.Options ) (<- chan transcoder.Progress , error ) {
40
40
41
41
var stderrIn io.ReadCloser
42
+ var err error
42
43
43
44
out := make (chan transcoder.Progress )
44
45
@@ -49,20 +50,24 @@ func (t *Transcoder) Start(opts transcoder.Options) (<-chan transcoder.Progress,
49
50
return nil , err
50
51
}
51
52
52
- // Get file metadata
53
- _ , err := t .GetMetadata ()
54
- if err != nil {
55
- return nil , err
56
- }
53
+ //Get file metadata
54
+ // _, err := t.GetMetadata()
55
+ // if err != nil {
56
+ // return nil, err
57
+ // }
57
58
58
59
// Append input file and standard options
59
- arg := []string { "-i" }
60
+ arg := make ( []string , 0 )
60
61
arg = append (arg , t .input ... )
61
- args := append (arg , opts .GetStrArguments ()... )
62
+ args := make ([]string , 0 )
63
+ for _ , input := range t .input {
64
+ args = append (args , opts .GetStrArguments ()... )
65
+ args = append (args , []string {"-i" , input }... )
66
+ }
62
67
outputLength := len (t .output )
63
68
optionsLength := len (t .options )
64
69
65
- if outputLength == 1 && optionsLength == 0 {
70
+ if optionsLength == 0 {
66
71
// Just append the 1 output file we've got
67
72
args = append (args , t .output [0 ])
68
73
} else {
@@ -90,7 +95,7 @@ func (t *Transcoder) Start(opts transcoder.Options) (<-chan transcoder.Progress,
90
95
if t .config .ProgressEnabled && ! t .config .Verbose {
91
96
stderrIn , err = cmd .StderrPipe ()
92
97
if err != nil {
93
- return nil , fmt .Errorf ("Failed getting transcoding progress (%s) with args (%s) with error %s" , t .config .FfmpegBinPath , args , err )
98
+ return nil , fmt .Errorf ("failed getting transcoding progress (%s) with args (%s) with error %s" , t .config .FfmpegBinPath , args , err )
94
99
}
95
100
}
96
101
@@ -101,7 +106,7 @@ func (t *Transcoder) Start(opts transcoder.Options) (<-chan transcoder.Progress,
101
106
// Start process
102
107
err = cmd .Start ()
103
108
if err != nil {
104
- return nil , fmt .Errorf ("Failed starting transcoding (%s) with args (%s) with error %s" , t .config .FfmpegBinPath , args , err )
109
+ return nil , fmt .Errorf ("failed starting transcoding (%s) with args (%s) with error %s" , t .config .FfmpegBinPath , args , err )
105
110
}
106
111
107
112
if t .config .ProgressEnabled && ! t .config .Verbose {
@@ -122,7 +127,16 @@ func (t *Transcoder) Start(opts transcoder.Options) (<-chan transcoder.Progress,
122
127
123
128
// Input ...
124
129
func (t * Transcoder ) Input (arg string ) transcoder.Transcoder {
125
- t .input = append (t .input ,arg )
130
+ //args := make([]string, 0)
131
+ //optionsLength := len(t.options)
132
+ //if optionsLength != 0 {
133
+ // args = append(args, t.options[0]...)
134
+ // t.options = t.options[1:]
135
+ //}
136
+ //args = append(args, "-i")
137
+ //args = append(args, arg)
138
+ //arg = strings.Join(args, " ")
139
+ t .input = append (t .input , arg )
126
140
return t
127
141
}
128
142
@@ -194,41 +208,37 @@ func (t *Transcoder) validate() error {
194
208
}
195
209
196
210
// GetMetadata Returns metadata for the specified input file
197
- func (t * Transcoder ) GetMetadata () ( transcoder.Metadata , error ) {
211
+ func (t * Transcoder ) GetMetadata () (transcoder.Metadata , error ) {
198
212
199
213
if t .config .FfprobeBinPath != "" {
200
214
var outb , errb bytes.Buffer
215
+ var metadata []Metadata
216
+ var metapice Metadata
201
217
202
- input := t .input
203
-
204
- if t .inputPipeReader != nil {
205
- input = []string {"pipe:" }
206
- }
207
-
208
- args := []string {"-i" }
209
- controlStr := []string {"-print_format" , "json" , "-show_format" , "-show_streams" , "-show_error" }
210
- args = append (args , input ... )
211
- args = append (args , controlStr ... )
212
- //args := []string{"-i", input, "-print_format", "json", "-show_format", "-show_streams", "-show_error"}
218
+ for _ , input := range t .input {
213
219
214
- cmd := exec . Command ( t . config . FfprobeBinPath , args ... )
215
- cmd . Stdout = & outb
216
- cmd . Stderr = & errb
220
+ if t . inputPipeReader != nil {
221
+ input = "pipe:"
222
+ }
217
223
218
- err := cmd .Run ()
219
- if err != nil {
220
- return nil , fmt .Errorf ("error executing (%s) with args (%s) | error: %s | message: %s %s" , t .config .FfprobeBinPath , args , err , outb .String (), errb .String ())
221
- }
224
+ args := []string {"-i" , input , "-print_format" , "json" , "-show_format" , "-show_streams" , "-show_error" }
222
225
223
- var metadata Metadata
226
+ cmd := exec .Command (t .config .FfprobeBinPath , args ... )
227
+ cmd .Stdout = & outb
228
+ cmd .Stderr = & errb
229
+ err := cmd .Run ()
230
+ if err != nil {
231
+ return nil , fmt .Errorf ("error executing (%s) with args (%s) | error: %s | message: %s %s" , t .config .FfprobeBinPath , args , err , outb .String (), errb .String ())
232
+ }
233
+ if err := json .Unmarshal ([]byte (outb .String ()), & metapice ); err != nil {
234
+ return nil , err
235
+ }
224
236
225
- if err = json . Unmarshal ([] byte ( outb . String ()), & metadata ); err != nil {
226
- return nil , err
237
+ t . metadata = metapice
238
+ metadata = append ( metadata , metapice )
227
239
}
228
240
229
- t .metadata = metadata
230
-
231
- return metadata , nil
241
+ return metapice , nil
232
242
}
233
243
234
244
return nil , errors .New ("ffprobe binary not found" )
@@ -324,11 +334,11 @@ func (t *Transcoder) progress(stream io.ReadCloser, out chan transcoder.Progress
324
334
func (t * Transcoder ) closePipes () {
325
335
if t .inputPipeReader != nil {
326
336
ipr := * t .inputPipeReader
327
- ipr .Close ()
337
+ _ = ipr .Close ()
328
338
}
329
339
330
340
if t .outputPipeWriter != nil {
331
341
opr := * t .outputPipeWriter
332
- opr .Close ()
342
+ _ = opr .Close ()
333
343
}
334
344
}
0 commit comments