Skip to content

Commit

Permalink
fix(transcode): don't leave half transcode cache files lying around
Browse files Browse the repository at this point in the history
fixes #270
  • Loading branch information
sentriz committed Dec 12, 2022
1 parent b47c880 commit ce31310
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
2 changes: 1 addition & 1 deletion server/ctrlsubsonic/handlers_raw.go
Expand Up @@ -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)
}

Expand Down
7 changes: 6 additions & 1 deletion transcode/transcoder_ffmpeg.go
Expand Up @@ -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 {
Expand All @@ -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 {
Expand Down

0 comments on commit ce31310

Please sign in to comment.