0
owncast/core/core.go
Gabe Kangas 04dc0796d8
New video transcoder (#27)
* New video transcoder

* Set a smaller max muxing size + logging tweaks

* No need to return an err since it wiill panic anyway

* Use a default encoder preset if one is not supplied

* Rename to NewTranscoder.  Add comments.

* Rename Bitrate to VideoBitrate. Config file changes required with this rename.

* Allow overrides of segment length. Allow offline stream to live in a single segment

* Append offline state video to existin HLS stream instead of overwriting because players do not like that

* Make properties private as they do not need to be exported
2020-06-25 17:44:47 -07:00

82 lines
2.0 KiB
Go

package core
import (
"os"
"path"
"strconv"
log "github.com/sirupsen/logrus"
"github.com/gabek/owncast/config"
"github.com/gabek/owncast/core/chat"
"github.com/gabek/owncast/core/ffmpeg"
"github.com/gabek/owncast/models"
"github.com/gabek/owncast/utils"
)
var (
_stats *models.Stats
_storage models.ChunkStorageProvider
)
//Start starts up the core processing
func Start() error {
resetDirectories()
if err := setupStats(); err != nil {
log.Println("failed to setup the stats")
return err
}
if err := setupStorage(); err != nil {
log.Println("failed to setup the storage")
return err
}
if err := createInitialOfflineState(); err != nil {
log.Println("failed to create the initial offline state")
return err
}
chat.Setup(ChatListenerImpl{})
return nil
}
func createInitialOfflineState() error {
// Provide default files
if !utils.DoesFileExists("webroot/thumbnail.jpg") {
if err := utils.Copy("static/logo.png", "webroot/thumbnail.jpg"); err != nil {
return err
}
}
ffmpeg.ShowStreamOfflineState()
return nil
}
func resetDirectories() {
log.Println("Resetting file directories to a clean slate.")
// Wipe the public, web-accessible hls data directory
os.RemoveAll(config.Config.PublicHLSPath)
os.RemoveAll(config.Config.PrivateHLSPath)
os.MkdirAll(config.Config.PublicHLSPath, 0777)
os.MkdirAll(config.Config.PrivateHLSPath, 0777)
// Remove the previous thumbnail
os.Remove("webroot/thumbnail.jpg")
// Create private hls data dirs
if !config.Config.VideoSettings.EnablePassthrough || len(config.Config.VideoSettings.StreamQualities) == 0 {
for index := range config.Config.VideoSettings.StreamQualities {
os.MkdirAll(path.Join(config.Config.PrivateHLSPath, strconv.Itoa(index)), 0777)
os.MkdirAll(path.Join(config.Config.PublicHLSPath, strconv.Itoa(index)), 0777)
}
} else {
os.MkdirAll(path.Join(config.Config.PrivateHLSPath, strconv.Itoa(0)), 0777)
os.MkdirAll(path.Join(config.Config.PublicHLSPath, strconv.Itoa(0)), 0777)
}
}