diff --git a/internal/mp4/mp4.go b/internal/mp4/mp4.go index 15c51f71..9144a497 100644 --- a/internal/mp4/mp4.go +++ b/internal/mp4/mp4.go @@ -120,15 +120,6 @@ func handlerMP4(w http.ResponseWriter, r *http.Request) { return } - defer stream.RemoveConsumer(cons) - - header := w.Header() - header.Set("Content-Type", mp4.ContentType(cons.Codecs())) - - if filename := query.Get("filename"); filename != "" { - header.Set("Content-Disposition", `attachment; filename="`+filename+`"`) - } - if rotate := query.Get("rotate"); rotate != "" { cons.Rotate = core.Atoi(rotate) } @@ -140,6 +131,13 @@ func handlerMP4(w http.ResponseWriter, r *http.Request) { } } + header := w.Header() + header.Set("Content-Type", mp4.ContentType(cons.Codecs())) + + if filename := query.Get("filename"); filename != "" { + header.Set("Content-Disposition", `attachment; filename="`+filename+`"`) + } + var duration *time.Timer if s := query.Get("duration"); s != "" { if i, _ := strconv.Atoi(s); i > 0 { @@ -151,6 +149,8 @@ func handlerMP4(w http.ResponseWriter, r *http.Request) { _, _ = cons.WriteTo(w) + stream.RemoveConsumer(cons) + if duration != nil { duration.Stop() }