fix(transcode): don't leave half transcode cache files lying around
fixes #270
This commit is contained in:
@@ -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())
|
log.Printf("trancoding to %q with max bitrate %dk", profile.MIME(), profile.BitRate())
|
||||||
|
|
||||||
w.Header().Set("Content-Type", profile.MIME())
|
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)
|
return spec.NewError(0, "error transcoding: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -16,6 +16,7 @@ func NewFFmpegTranscoder() *FFmpegTranscoder {
|
|||||||
return &FFmpegTranscoder{}
|
return &FFmpegTranscoder{}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var ErrFFmpegKilled = fmt.Errorf("ffmpeg was killed early")
|
||||||
var ErrFFmpegExit = fmt.Errorf("ffmpeg exited with non 0 status code")
|
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 {
|
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
|
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)
|
return fmt.Errorf("waiting cmd: %w", err)
|
||||||
}
|
}
|
||||||
if code := cmd.ProcessState.ExitCode(); code > 1 {
|
if code := cmd.ProcessState.ExitCode(); code > 1 {
|
||||||
|
|||||||
Reference in New Issue
Block a user