Skip to content

Commit

Permalink
ffmpeg: separate out non-retryable errors
Browse files Browse the repository at this point in the history
  • Loading branch information
jailuthra committed Apr 5, 2021
1 parent b460151 commit 731af8d
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 6 deletions.
4 changes: 2 additions & 2 deletions ffmpeg/api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1232,8 +1232,8 @@ func audioOnlySegment(t *testing.T, accel Acceleration) {
Accel: accel,
}}
_, err := tc.Transcode(in, out)
if i == 2 && (err == nil || err.Error() != "No video parameters found while initializing stream") {
t.Error("Expected to fail for audio-only segment but did not")
if i == 2 && (err == nil || err.Error() != "TranscoderInvalidVideo") {
t.Errorf("Expected to fail for audio-only segment but did not, instead got err=%v", err)
} else if i != 2 && err != nil {
t.Error(err)
}
Expand Down
6 changes: 4 additions & 2 deletions ffmpeg/ffmpeg.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,12 @@ import "C"
var ErrTranscoderRes = errors.New("TranscoderInvalidResolution")
var ErrTranscoderHw = errors.New("TranscoderInvalidHardware")
var ErrTranscoderInp = errors.New("TranscoderInvalidInput")
var ErrTranscoderVid = errors.New("TranscoderInvalidVideo")
var ErrTranscoderStp = errors.New("TranscoderStopped")
var ErrTranscoderFmt = errors.New("TranscoderUnrecognizedFormat")
var ErrTranscoderPrf = errors.New("TranscoderUnrecognizedProfile")
var ErrTranscoderGOP = errors.New("TranscoderInvalidGOP")
var ErrTranscoderDev = errors.New("TranscoderIncompatibleDevices")

type Acceleration int

Expand Down Expand Up @@ -144,7 +146,7 @@ func configAccel(inAcc, outAcc Acceleration, inDev, outDev string) (string, stri
case Nvidia:
// If we encode on a different device from decode then need to transfer
if outDev != "" && outDev != inDev {
return "", "", ErrTranscoderInp // XXX not allowed
return "", "", ErrTranscoderDev // XXX not allowed
}
return "h264_nvenc", "scale_cuda", nil
}
Expand Down Expand Up @@ -195,7 +197,7 @@ func (t *Transcoder) Transcode(input *TranscodeOptionsIn, ps []TranscodeOptions)
t.started = true
} else {
// Audio-only segment, fail fast right here as we cannot handle them nicely
return nil, errors.New("No video parameters found while initializing stream")
return nil, ErrTranscoderVid
}
}
params := make([]C.output_params, len(ps))
Expand Down
32 changes: 30 additions & 2 deletions ffmpeg/ffmpeg_errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
"unsafe"
)

var LPMSErrors = []struct {
var lpmsErrors = []struct {
Code C.int
Desc string
}{
Expand Down Expand Up @@ -40,7 +40,7 @@ func error_map() map[int]error {
}

// Add in LPMS specific errors
for _, v := range LPMSErrors {
for _, v := range lpmsErrors {
m[int(v.Code)] = errors.New(v.Desc)
}

Expand All @@ -49,6 +49,34 @@ func error_map() map[int]error {

var ErrorMap = error_map()

func non_retryable_errs() []string {
errs := []string{}
// Add in Cgo LPMS specific errors
for _, v := range lpmsErrors {
errs = append(errs, v.Desc)
}
// Add in internal FFmpeg errors
// from https://ffmpeg.org/doxygen/trunk/error_8c_source.html#l00034
ffmpegErrors := []string{
"Decoder not found", "Demuxer not found", "Encoder not found",
"Muxer not found", "Option not found", "Invalid argument",
}
for _, v := range ffmpegErrors {
errs = append(errs, v)
}
// Add in ffmpeg.go transcoder specific errors
transcoderErrors := []error{
ErrTranscoderRes, ErrTranscoderVid, ErrTranscoderFmt,
ErrTranscoderPrf, ErrTranscoderGOP, ErrTranscoderDev,
}
for _, v := range transcoderErrors {
errs = append(errs, v.Error())
}
return errs
}

var NonRetryableErrs = non_retryable_errs()

// Use of this source code is governed by a MIT license that can be found in the LICENSE file.
// Corbatto (luca@corbatto.de)

Expand Down

0 comments on commit 731af8d

Please sign in to comment.