fix(transcode): don't leave half transcode cache files lying around

fixes #270
This commit is contained in:
sentriz
2022-12-12 18:56:20 +00:00
parent b47c880ea5
commit ce31310571
2 changed files with 7 additions and 2 deletions

View File

@@ -330,7 +330,7 @@ func (c *Controller) ServeStream(w http.ResponseWriter, r *http.Request) *spec.R
log.Printf("trancoding to %q with max bitrate %dk", profile.MIME(), profile.BitRate())
w.Header().Set("Content-Type", profile.MIME())
if err := c.Transcoder.Transcode(r.Context(), profile, audioPath, w); err != nil {
if err := c.Transcoder.Transcode(r.Context(), profile, audioPath, w); err != nil && !errors.Is(err, transcode.ErrFFmpegKilled) {
return spec.NewError(0, "error transcoding: %v", err)
}

View File

@@ -16,6 +16,7 @@ func NewFFmpegTranscoder() *FFmpegTranscoder {
return &FFmpegTranscoder{}
}
var ErrFFmpegKilled = fmt.Errorf("ffmpeg was killed early")
var ErrFFmpegExit = fmt.Errorf("ffmpeg exited with non 0 status code")
func (*FFmpegTranscoder) Transcode(ctx context.Context, profile Profile, in string, out io.Writer) error {
@@ -32,7 +33,11 @@ func (*FFmpegTranscoder) Transcode(ctx context.Context, profile Profile, in stri
}
var exitErr *exec.ExitError
if err := cmd.Wait(); err != nil && !errors.As(err, &exitErr) {
switch err := cmd.Wait(); {
case errors.As(err, &exitErr):
return fmt.Errorf("waiting cmd: %v: %w", err, ErrFFmpegKilled)
case err != nil:
return fmt.Errorf("waiting cmd: %w", err)
}
if code := cmd.ProcessState.ExitCode(); code > 1 {