@@ -13,34 +13,35 @@ import (
13
13
"strconv"
14
14
"strings"
15
15
16
- "github.com/floostack/transcoder "
17
- "github.com/floostack/transcoder /utils"
16
+ "transcoderplus "
17
+ "transcoderplus /utils"
18
18
)
19
19
20
20
// Transcoder ...
21
21
type Transcoder struct {
22
22
config * Config
23
- input string
23
+ input [] string
24
24
output []string
25
25
options [][]string
26
- metadata transcoder .Metadata
26
+ metadata transcoderplus .Metadata
27
27
inputPipeReader * io.ReadCloser
28
28
outputPipeReader * io.ReadCloser
29
29
inputPipeWriter * io.WriteCloser
30
30
outputPipeWriter * io.WriteCloser
31
31
}
32
32
33
33
// New ...
34
- func New (cfg * Config ) transcoder .Transcoder {
34
+ func New (cfg * Config ) transcoderplus .Transcoder {
35
35
return & Transcoder {config : cfg }
36
36
}
37
37
38
38
// Start ...
39
- func (t * Transcoder ) Start (opts transcoder .Options ) (<- chan transcoder .Progress , error ) {
39
+ func (t * Transcoder ) Start (opts transcoderplus .Options ) (<- chan transcoderplus .Progress , error ) {
40
40
41
41
var stderrIn io.ReadCloser
42
+ var err error
42
43
43
- out := make (chan transcoder .Progress )
44
+ out := make (chan transcoderplus .Progress )
44
45
45
46
defer t .closePipes ()
46
47
@@ -49,18 +50,25 @@ 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
+ // 不能使用,因为ffprobe不支持mulaw格式的识别
54
+ //Get file metadata
55
+ //_, err = t.GetMetadata()
56
+ //if err != nil {
57
+ // return nil, err
58
+ //}
57
59
58
60
// Append input file and standard options
59
- args := append ([]string {"-i" , t .input }, opts .GetStrArguments ()... )
61
+ arg := make ([]string , 0 )
62
+ arg = append (arg , t .input ... )
63
+ args := make ([]string , 0 )
64
+ for _ , input := range t .input {
65
+ args = append (args , opts .GetStrArguments ()... )
66
+ args = append (args , []string {"-i" , input }... )
67
+ }
60
68
outputLength := len (t .output )
61
69
optionsLength := len (t .options )
62
70
63
- if outputLength == 1 && optionsLength == 0 {
71
+ if optionsLength == 0 {
64
72
// Just append the 1 output file we've got
65
73
args = append (args , t .output [0 ])
66
74
} else {
@@ -88,7 +96,7 @@ func (t *Transcoder) Start(opts transcoder.Options) (<-chan transcoder.Progress,
88
96
if t .config .ProgressEnabled && ! t .config .Verbose {
89
97
stderrIn , err = cmd .StderrPipe ()
90
98
if err != nil {
91
- return nil , fmt .Errorf ("Failed getting transcoding progress (%s) with args (%s) with error %s" , t .config .FfmpegBinPath , args , err )
99
+ return nil , fmt .Errorf ("failed getting transcoding progress (%s) with args (%s) with error %s" , t .config .FfmpegBinPath , args , err )
92
100
}
93
101
}
94
102
@@ -99,7 +107,7 @@ func (t *Transcoder) Start(opts transcoder.Options) (<-chan transcoder.Progress,
99
107
// Start process
100
108
err = cmd .Start ()
101
109
if err != nil {
102
- return nil , fmt .Errorf ("Failed starting transcoding (%s) with args (%s) with error %s" , t .config .FfmpegBinPath , args , err )
110
+ return nil , fmt .Errorf ("failed starting transcoding (%s) with args (%s) with error %s" , t .config .FfmpegBinPath , args , err )
103
111
}
104
112
105
113
if t .config .ProgressEnabled && ! t .config .Verbose {
@@ -119,19 +127,19 @@ func (t *Transcoder) Start(opts transcoder.Options) (<-chan transcoder.Progress,
119
127
}
120
128
121
129
// Input ...
122
- func (t * Transcoder ) Input (arg string ) transcoder .Transcoder {
123
- t .input = arg
130
+ func (t * Transcoder ) Input (arg string ) transcoderplus .Transcoder {
131
+ t .input = append ( t . input , arg )
124
132
return t
125
133
}
126
134
127
135
// Output ...
128
- func (t * Transcoder ) Output (arg string ) transcoder .Transcoder {
136
+ func (t * Transcoder ) Output (arg string ) transcoderplus .Transcoder {
129
137
t .output = append (t .output , arg )
130
138
return t
131
139
}
132
140
133
141
// InputPipe ...
134
- func (t * Transcoder ) InputPipe (w * io.WriteCloser , r * io.ReadCloser ) transcoder .Transcoder {
142
+ func (t * Transcoder ) InputPipe (w * io.WriteCloser , r * io.ReadCloser ) transcoderplus .Transcoder {
135
143
if & t .input == nil {
136
144
t .inputPipeWriter = w
137
145
t .inputPipeReader = r
@@ -140,7 +148,7 @@ func (t *Transcoder) InputPipe(w *io.WriteCloser, r *io.ReadCloser) transcoder.T
140
148
}
141
149
142
150
// OutputPipe ...
143
- func (t * Transcoder ) OutputPipe (w * io.WriteCloser , r * io.ReadCloser ) transcoder .Transcoder {
151
+ func (t * Transcoder ) OutputPipe (w * io.WriteCloser , r * io.ReadCloser ) transcoderplus .Transcoder {
144
152
if & t .output == nil {
145
153
t .outputPipeWriter = w
146
154
t .outputPipeReader = r
@@ -149,13 +157,13 @@ func (t *Transcoder) OutputPipe(w *io.WriteCloser, r *io.ReadCloser) transcoder.
149
157
}
150
158
151
159
// WithOptions Sets the options object
152
- func (t * Transcoder ) WithOptions (opts transcoder .Options ) transcoder .Transcoder {
160
+ func (t * Transcoder ) WithOptions (opts transcoderplus .Options ) transcoderplus .Transcoder {
153
161
t .options = [][]string {opts .GetStrArguments ()}
154
162
return t
155
163
}
156
164
157
165
// WithAdditionalOptions Appends an additional options object
158
- func (t * Transcoder ) WithAdditionalOptions (opts transcoder .Options ) transcoder .Transcoder {
166
+ func (t * Transcoder ) WithAdditionalOptions (opts transcoderplus .Options ) transcoderplus .Transcoder {
159
167
t .options = append (t .options , opts .GetStrArguments ())
160
168
return t
161
169
}
@@ -166,7 +174,7 @@ func (t *Transcoder) validate() error {
166
174
return errors .New ("ffmpeg binary path not found" )
167
175
}
168
176
169
- if t .input == "" {
177
+ if t .input == nil {
170
178
return errors .New ("missing input option" )
171
179
}
172
180
@@ -192,44 +200,43 @@ func (t *Transcoder) validate() error {
192
200
}
193
201
194
202
// GetMetadata Returns metadata for the specified input file
195
- func (t * Transcoder ) GetMetadata () ( transcoder .Metadata , error ) {
203
+ func (t * Transcoder ) GetMetadata () (transcoderplus .Metadata , error ) {
196
204
197
205
if t .config .FfprobeBinPath != "" {
198
- var outb , errb bytes.Buffer
199
-
200
- input := t .input
201
-
202
- if t .inputPipeReader != nil {
203
- input = "pipe:"
204
- }
206
+ //var metadata []Metadata
207
+ var metapice Metadata
205
208
206
- args := [] string { "-i" , input , "-print_format" , "json" , "-show_format" , "-show_streams" , "-show_error" }
209
+ input := t . input [ 0 ]
207
210
208
- cmd := exec .Command (t .config .FfprobeBinPath , args ... )
209
- cmd .Stdout = & outb
210
- cmd .Stderr = & errb
211
+ var outb , errb bytes.Buffer
211
212
212
- err := cmd .Run ()
213
- if err != nil {
214
- return nil , fmt .Errorf ("error executing (%s) with args (%s) | error: %s | message: %s %s" , t .config .FfprobeBinPath , args , err , outb .String (), errb .String ())
215
- }
213
+ if t .inputPipeReader != nil {
214
+ input = "pipe:"
215
+ }
216
216
217
- var metadata Metadata
217
+ args := [] string { "-i" , input , "-print_format" , "json" , "-show_format" , "-show_streams" , "-show_error" }
218
218
219
- if err = json .Unmarshal ([]byte (outb .String ()), & metadata ); err != nil {
220
- return nil , err
221
- }
219
+ cmd := exec .Command (t .config .FfprobeBinPath , args ... )
220
+ cmd .Stdout = & outb
221
+ cmd .Stderr = & errb
222
+ err := cmd .Run ()
223
+ if err != nil {
224
+ return nil , fmt .Errorf ("error executing (%s) with args (%s) | error: %s | message: %s %s" , t .config .FfprobeBinPath , args , err , outb .String (), errb .String ())
225
+ }
226
+ if err := json .Unmarshal ([]byte (outb .String ()), & metapice ); err != nil {
227
+ return nil , err
228
+ }
222
229
223
- t .metadata = metadata
230
+ t .metadata = metapice
224
231
225
- return metadata , nil
232
+ return metapice , nil
226
233
}
227
234
228
235
return nil , errors .New ("ffprobe binary not found" )
229
236
}
230
237
231
238
// progress sends through given channel the transcoding status
232
- func (t * Transcoder ) progress (stream io.ReadCloser , out chan transcoder .Progress ) {
239
+ func (t * Transcoder ) progress (stream io.ReadCloser , out chan transcoderplus .Progress ) {
233
240
234
241
defer stream .Close ()
235
242
@@ -298,6 +305,7 @@ func (t *Transcoder) progress(stream io.ReadCloser, out chan transcoder.Progress
298
305
}
299
306
}
300
307
308
+ // 都可以删,因为没有ffprobe
301
309
timesec := utils .DurToSec (currentTime )
302
310
dursec , _ := strconv .ParseFloat (t .metadata .GetFormat ().GetDuration (), 64 )
303
311
@@ -318,11 +326,11 @@ func (t *Transcoder) progress(stream io.ReadCloser, out chan transcoder.Progress
318
326
func (t * Transcoder ) closePipes () {
319
327
if t .inputPipeReader != nil {
320
328
ipr := * t .inputPipeReader
321
- ipr .Close ()
329
+ _ = ipr .Close ()
322
330
}
323
331
324
332
if t .outputPipeWriter != nil {
325
333
opr := * t .outputPipeWriter
326
- opr .Close ()
334
+ _ = opr .Close ()
327
335
}
328
336
}
0 commit comments