From 543577c2e02a70f8ea6992553d9ba1d1dc29cb77 Mon Sep 17 00:00:00 2001 From: Gabe Kangas Date: Thu, 15 Apr 2021 21:34:51 -0700 Subject: [PATCH] Create hls directories at transcoder start to account for stream output changes. Fixes #940 --- core/core.go | 26 ------------------------- core/transcoder/transcoder.go | 1 + core/transcoder/utils.go | 36 +++++++++++++++++++++++++++++++++++ 3 files changed, 37 insertions(+), 26 deletions(-) diff --git a/core/core.go b/core/core.go index 953a9cdbb..4e6dcd5fa 100644 --- a/core/core.go +++ b/core/core.go @@ -4,7 +4,6 @@ import ( "os" "path" "path/filepath" - "strconv" log "github.com/sirupsen/logrus" @@ -132,31 +131,6 @@ func resetDirectories() { // Remove the previous thumbnail os.Remove(filepath.Join(config.WebRoot, "thumbnail.jpg")) - // Create private hls data dirs - if len(data.GetStreamOutputVariants()) != 0 { - for index := range data.GetStreamOutputVariants() { - err = os.MkdirAll(path.Join(config.PrivateHLSStoragePath, strconv.Itoa(index)), 0777) - if err != nil { - log.Fatalln(err) - } - - err = os.MkdirAll(path.Join(config.PublicHLSStoragePath, strconv.Itoa(index)), 0777) - if err != nil { - log.Fatalln(err) - } - } - } else { - err = os.MkdirAll(path.Join(config.PrivateHLSStoragePath, strconv.Itoa(0)), 0777) - if err != nil { - log.Fatalln(err) - } - - err = os.MkdirAll(path.Join(config.PublicHLSStoragePath, strconv.Itoa(0)), 0777) - if err != nil { - log.Fatalln(err) - } - } - // Remove the previous thumbnail logo := data.GetLogoPath() err = utils.Copy(path.Join("data", logo), "webroot/thumbnail.jpg") diff --git a/core/transcoder/transcoder.go b/core/transcoder/transcoder.go index f55607395..a7b0d0901 100644 --- a/core/transcoder/transcoder.go +++ b/core/transcoder/transcoder.go @@ -87,6 +87,7 @@ func (t *Transcoder) Start() { command := t.getString() log.Infof("Video transcoder started using %s with %d stream variants.", t.codec.DisplayName(), len(t.variants)) + createVariantDirectories() if config.EnableDebugFeatures { log.Println(command) diff --git a/core/transcoder/utils.go b/core/transcoder/utils.go index aba015468..4c422dd57 100644 --- a/core/transcoder/utils.go +++ b/core/transcoder/utils.go @@ -1,9 +1,14 @@ package transcoder import ( + "os" + "path" + "strconv" "strings" "sync" + "github.com/owncast/owncast/config" + "github.com/owncast/owncast/core/data" log "github.com/sirupsen/logrus" ) @@ -79,3 +84,34 @@ func handleTranscoderMessage(message string) { _lastTranscoderLogMessage = message } + +func createVariantDirectories() { + // Create private hls data dirs + if len(data.GetStreamOutputVariants()) != 0 { + for index := range data.GetStreamOutputVariants() { + err := os.MkdirAll(path.Join(config.PrivateHLSStoragePath, strconv.Itoa(index)), 0777) + if err != nil { + log.Fatalln(err) + } + dir := path.Join(config.PublicHLSStoragePath, strconv.Itoa(index)) + log.Traceln("Creating", dir) + err = os.MkdirAll(dir, 0777) + if err != nil { + log.Fatalln(err) + } + } + } else { + dir := path.Join(config.PrivateHLSStoragePath, strconv.Itoa(0)) + log.Traceln("Creating", dir) + err := os.MkdirAll(dir, 0777) + if err != nil { + log.Fatalln(err) + } + dir = path.Join(config.PublicHLSStoragePath, strconv.Itoa(0)) + log.Traceln("Creating", dir) + err = os.MkdirAll(dir, 0777) + if err != nil { + log.Fatalln(err) + } + } +}