Skip to content
This repository was archived by the owner on Sep 29, 2023. It is now read-only.

Commit cbe703f

Browse files
committed
update
1 parent c9ef797 commit cbe703f

File tree

1 file changed

+16
-6
lines changed

1 file changed

+16
-6
lines changed

ffmpeg/ffmpeg.go

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -135,8 +135,7 @@ func (t *Transcoder) Start(opts transcoder.Options) (<-chan transcoder.Progress,
135135
defer close(out)
136136
err = cmd.Wait()
137137
if err != nil {
138-
b, _ := io.ReadAll(io.LimitReader(stderrIn, 100))
139-
err = fmt.Errorf("failed to transcoding (%s) with args (%s) with error %w: %s", t.config.FfmpegBinPath, args, err, string(b))
138+
err = fmt.Errorf("failed to transcoding (%s) with args (%s) with error %w", t.config.FfmpegBinPath, args, err)
140139
log.Println(err)
141140
out <- &Progress{Error: err}
142141
}
@@ -145,8 +144,7 @@ func (t *Transcoder) Start(opts transcoder.Options) (<-chan transcoder.Progress,
145144
} else {
146145
err = cmd.Wait()
147146
if err != nil {
148-
b, _ := io.ReadAll(io.LimitReader(stderrIn, 100))
149-
return nil, fmt.Errorf("failed to transcoding (%s) with args (%s) with error %w: %s", t.config.FfmpegBinPath, args, err, string(b))
147+
return nil, fmt.Errorf("failed to transcoding (%s) with args (%s) with error %w", t.config.FfmpegBinPath, args, err)
150148
}
151149
}
152150

@@ -286,6 +284,8 @@ func (t *Transcoder) GetMetadata() (transcoder.Metadata, error) {
286284
}
287285

288286
var reEQ = regexp.MustCompile(`=\s+`)
287+
var mgError = `Error `
288+
var mgFailed = `Conversion failed!`
289289

290290
// progress sends through given channel the transcoding status
291291
func (t *Transcoder) progress(stream io.ReadCloser, out chan transcoder.Progress) {
@@ -317,11 +317,18 @@ func (t *Transcoder) progress(stream io.ReadCloser, out chan transcoder.Progress
317317
buf := make([]byte, 2)
318318
scanner.Buffer(buf, bufio.MaxScanTokenSize)
319319

320+
var isFailed bool
321+
var errMessages []string
322+
320323
for scanner.Scan() {
321324
Progress := new(Progress)
322325
line := scanner.Text()
323-
324-
if strings.Contains(line, "time=") && strings.Contains(line, "bitrate=") {
326+
//println(`========>`, `[`+line+`]`)
327+
if strings.HasPrefix(line, mgError) {
328+
errMessages = append(errMessages, line)
329+
} else if strings.HasPrefix(line, mgFailed) {
330+
isFailed = true
331+
} else if strings.Contains(line, "time=") && strings.Contains(line, "bitrate=") {
325332
st := reEQ.ReplaceAllString(line, `=`)
326333
f := strings.Fields(st)
327334
var framesProcessed string
@@ -368,6 +375,9 @@ func (t *Transcoder) progress(stream io.ReadCloser, out chan transcoder.Progress
368375
out <- *Progress
369376
}
370377
}
378+
if isFailed && len(errMessages) > 0 {
379+
out <- &Progress{Error: errors.New(strings.Join(errMessages, "\n"))}
380+
}
371381
}
372382

373383
// closePipes Closes pipes if opened

0 commit comments

Comments
 (0)