@@ -14,8 +14,8 @@ import (
14
14
"strconv"
15
15
"strings"
16
16
17
- "github.com/floostack /transcoder"
18
- "github.com/floostack /transcoder/utils"
17
+ "github.com/SumeruCCTV /transcoder"
18
+ "github.com/SumeruCCTV /transcoder/utils"
19
19
)
20
20
21
21
// Transcoder ...
@@ -40,11 +40,7 @@ func New(cfg *Config) transcoder.Transcoder {
40
40
41
41
// Start ...
42
42
func (t * Transcoder ) Start () (<- chan transcoder.Progress , error ) {
43
-
44
43
var stderrIn io.ReadCloser
45
-
46
- out := make (chan transcoder.Progress )
47
-
48
44
defer t .closePipes ()
49
45
50
46
// Validates config
@@ -101,7 +97,7 @@ func (t *Transcoder) Start() (<-chan transcoder.Progress, error) {
101
97
cmd = exec .CommandContext (* t .commandContext , t .config .FfmpegBinPath , args ... )
102
98
}
103
99
104
- // If progresss enabled, get stderr pipe and start progress process
100
+ // If progress is enabled, get stderr pipe and start progress process
105
101
if t .config .ProgressEnabled && ! t .config .Verbose {
106
102
stderrIn , err = cmd .StderrPipe ()
107
103
if err != nil {
@@ -120,19 +116,13 @@ func (t *Transcoder) Start() (<-chan transcoder.Progress, error) {
120
116
}
121
117
122
118
if t .config .ProgressEnabled && ! t .config .Verbose {
123
- go func () {
124
- t .progress (stderrIn , out )
125
- }()
126
-
127
- go func () {
128
- defer close (out )
129
- err = cmd .Wait ()
130
- }()
131
- } else {
132
- err = cmd .Wait ()
119
+ out := make (chan transcoder.Progress )
120
+ defer close (out )
121
+ go t .progress (stderrIn , out )
122
+ return out , cmd .Wait ()
133
123
}
134
124
135
- return out , nil
125
+ return nil , cmd . Wait ()
136
126
}
137
127
138
128
// Input ...
@@ -149,7 +139,7 @@ func (t *Transcoder) Output(arg string) transcoder.Transcoder {
149
139
150
140
// InputPipe ...
151
141
func (t * Transcoder ) InputPipe (w * io.WriteCloser , r * io.ReadCloser ) transcoder.Transcoder {
152
- if & t .input == nil {
142
+ if len ( t .input ) == 0 {
153
143
t .inputPipeWriter = w
154
144
t .inputPipeReader = r
155
145
}
@@ -158,7 +148,7 @@ func (t *Transcoder) InputPipe(w *io.WriteCloser, r *io.ReadCloser) transcoder.T
158
148
159
149
// OutputPipe ...
160
150
func (t * Transcoder ) OutputPipe (w * io.WriteCloser , r * io.ReadCloser ) transcoder.Transcoder {
161
- if & t .output == nil {
151
+ if len ( t .output ) == 0 {
162
152
t .outputPipeWriter = w
163
153
t .outputPipeReader = r
164
154
}
@@ -267,7 +257,6 @@ func (t *Transcoder) GetMetadata() (transcoder.Metadata, error) {
267
257
268
258
// progress sends through given channel the transcoding status
269
259
func (t * Transcoder ) progress (stream io.ReadCloser , out chan transcoder.Progress ) {
270
-
271
260
defer stream .Close ()
272
261
273
262
split := func (data []byte , atEOF bool ) (advance int , token []byte , spliterror error ) {
@@ -296,7 +285,7 @@ func (t *Transcoder) progress(stream io.ReadCloser, out chan transcoder.Progress
296
285
scanner .Buffer (buf , bufio .MaxScanTokenSize )
297
286
298
287
for scanner .Scan () {
299
- Progress := new (Progress )
288
+ progress := new (Progress )
300
289
line := scanner .Text ()
301
290
302
291
if strings .Contains (line , "time=" ) && strings .Contains (line , "bitrate=" ) {
@@ -338,15 +327,15 @@ func (t *Transcoder) progress(stream io.ReadCloser, out chan transcoder.Progress
338
327
timesec := utils .DurToSec (currentTime )
339
328
dursec , _ := strconv .ParseFloat (t .metadata .GetFormat ().GetDuration (), 64 )
340
329
341
- progress := (timesec * 100 ) / dursec
342
- Progress .Progress = progress
330
+ currentProgress := (timesec * 100 ) / dursec
331
+ progress .Progress = currentProgress
343
332
344
- Progress .CurrentBitrate = currentBitrate
345
- Progress .FramesProcessed = framesProcessed
346
- Progress .CurrentTime = currentTime
347
- Progress .Speed = currentSpeed
333
+ progress .CurrentBitrate = currentBitrate
334
+ progress .FramesProcessed = framesProcessed
335
+ progress .CurrentTime = currentTime
336
+ progress .Speed = currentSpeed
348
337
349
- out <- * Progress
338
+ out <- * progress
350
339
}
351
340
}
352
341
}
0 commit comments