5214d81264
* Query for installed codecs * Start modeling out codecs * Can now specify a codec and get the correct settings returned from the model * Return codecs in admin/serverconfig * Start handling transcoding errors and return messages to user * filter available codecs against a whitelist * Fix merge * Codecs are working * Switching between codecs work * Add apis for setting a custom video codec * Cleanup the logging of transcoder errors * Add v4l codec * Add fetching v4l * Add support for per-codec presets * Use updated nvenc encoding parameters * Update log message * Some more codec WIP * Turn off v4l. It is a mess. * Try to make the lowest latency level a bit more playable * Use a human redable display name in console messages * Turn on transcoder persistent connections * Add more codec-related user-facing error messages * Give the initial offline state transcoder an id * Force a minimum segment count of 3 * Disable qsv for now. set x264 specific params in VariantFlags * Close body in case * Ignore vbv underflow message, it is not actionable * Determine a dynamic gop value based on the length of segments * Add codec-specific tests * Cleanup * Ignore goconst lint warnings in codec file * Troubleshoot omx * Add more codec tests * Remove no longer accurate comment * Bundle admin from codec branch * Revert back to old setting * Cleanup list of codecs a bit * Remove old references to the encoder preset * Commit updated API documentation * Update admin bundle * Commit updated API documentation * Add codec setting to api spec * Commit updated API documentation Co-authored-by: Owncast <owncast@owncast.online>
167 lines
4.2 KiB
Go
167 lines
4.2 KiB
Go
package core
|
|
|
|
import (
|
|
"os"
|
|
"path"
|
|
"path/filepath"
|
|
"strconv"
|
|
|
|
log "github.com/sirupsen/logrus"
|
|
|
|
"github.com/owncast/owncast/config"
|
|
"github.com/owncast/owncast/core/chat"
|
|
"github.com/owncast/owncast/core/data"
|
|
"github.com/owncast/owncast/core/rtmp"
|
|
"github.com/owncast/owncast/core/transcoder"
|
|
"github.com/owncast/owncast/models"
|
|
"github.com/owncast/owncast/utils"
|
|
"github.com/owncast/owncast/yp"
|
|
)
|
|
|
|
var (
|
|
_stats *models.Stats
|
|
_storage models.StorageProvider
|
|
_transcoder *transcoder.Transcoder
|
|
_yp *yp.YP
|
|
_broadcaster *models.Broadcaster
|
|
)
|
|
|
|
var handler transcoder.HLSHandler
|
|
var fileWriter = transcoder.FileWriterReceiverService{}
|
|
|
|
// Start starts up the core processing.
|
|
func Start() error {
|
|
resetDirectories()
|
|
|
|
data.PopulateDefaults()
|
|
// Once a couple versions pass we can remove the old data migrators.
|
|
data.RunMigrations()
|
|
|
|
if err := data.VerifySettings(); err != nil {
|
|
log.Error(err)
|
|
return err
|
|
}
|
|
|
|
if err := setupStats(); err != nil {
|
|
log.Error("failed to setup the stats")
|
|
return err
|
|
}
|
|
|
|
// The HLS handler takes the written HLS playlists and segments
|
|
// and makes storage decisions. It's rather simple right now
|
|
// but will play more useful when recordings come into play.
|
|
handler = transcoder.HLSHandler{}
|
|
|
|
if err := setupStorage(); err != nil {
|
|
log.Errorln("storage error", err)
|
|
}
|
|
|
|
fileWriter.SetupFileWriterReceiverService(&handler)
|
|
|
|
if err := createInitialOfflineState(); err != nil {
|
|
log.Error("failed to create the initial offline state")
|
|
return err
|
|
}
|
|
|
|
_yp = yp.NewYP(GetStatus)
|
|
|
|
chat.Setup(ChatListenerImpl{})
|
|
|
|
// start the rtmp server
|
|
go rtmp.Start(setStreamAsConnected, setBroadcaster)
|
|
|
|
rtmpPort := data.GetRTMPPortNumber()
|
|
log.Infof("RTMP is accepting inbound streams on port %d.", rtmpPort)
|
|
|
|
return nil
|
|
}
|
|
|
|
func createInitialOfflineState() error {
|
|
// Provide default files
|
|
if !utils.DoesFileExists(filepath.Join(config.WebRoot, "thumbnail.jpg")) {
|
|
if err := utils.Copy("static/logo.png", filepath.Join(config.WebRoot, "thumbnail.jpg")); err != nil {
|
|
return err
|
|
}
|
|
}
|
|
|
|
transitionToOfflineVideoStreamContent()
|
|
|
|
return nil
|
|
}
|
|
|
|
// transitionToOfflineVideoStreamContent will overwrite the current stream with the
|
|
// offline video stream state only. No live stream HLS segments will continue to be
|
|
// referenced.
|
|
func transitionToOfflineVideoStreamContent() {
|
|
log.Traceln("Firing transcoder with offline stream state")
|
|
|
|
offlineFilename := "offline.ts"
|
|
offlineFilePath := "static/" + offlineFilename
|
|
_transcoder := transcoder.NewTranscoder()
|
|
_transcoder.SetInput(offlineFilePath)
|
|
_transcoder.SetIdentifier("offline")
|
|
_transcoder.Start()
|
|
|
|
// Copy the logo to be the thumbnail
|
|
logo := data.GetLogoPath()
|
|
err := utils.Copy(filepath.Join("data", logo), "webroot/thumbnail.jpg")
|
|
if err != nil {
|
|
log.Warnln(err)
|
|
}
|
|
|
|
// Delete the preview Gif
|
|
os.Remove(path.Join(config.WebRoot, "preview.gif"))
|
|
}
|
|
|
|
func resetDirectories() {
|
|
log.Trace("Resetting file directories to a clean slate.")
|
|
|
|
// Wipe the public, web-accessible hls data directory
|
|
os.RemoveAll(config.PublicHLSStoragePath)
|
|
os.RemoveAll(config.PrivateHLSStoragePath)
|
|
err := os.MkdirAll(config.PublicHLSStoragePath, 0777)
|
|
if err != nil {
|
|
log.Fatalln(err)
|
|
}
|
|
|
|
err = os.MkdirAll(config.PrivateHLSStoragePath, 0777)
|
|
if err != nil {
|
|
log.Fatalln(err)
|
|
}
|
|
|
|
// 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")
|
|
if err != nil {
|
|
log.Warnln(err)
|
|
}
|
|
}
|