First pass at YP registration/configuration (#209)
* Spike: Ping YP service with instance details * WIP: Add to the config to support YP * Add YP response endpoint * Handle YP errors. Use config. Off by default * Show message about YP support on launch * Add animated gif preview when generating thumb * Increase quality of preview gif and only create it if YP is enabled * Do not allow re-registration by clearing the key * Make large and small logos actually structured * Change log level * Fix default YP service URL * Point to default hostname * Set default value for YP to false
This commit is contained in:
@@ -133,7 +133,7 @@ func (s *server) sendWelcomeMessageToClient(c *Client) {
|
||||
time.Sleep(7 * time.Second)
|
||||
|
||||
initialChatMessageText := fmt.Sprintf("Welcome to %s! %s", config.Config.InstanceDetails.Title, config.Config.InstanceDetails.Summary)
|
||||
initialMessage := models.ChatMessage{"owncast-server", config.Config.InstanceDetails.Name, initialChatMessageText, config.Config.InstanceDetails.Logo["small"], "initial-message-1", "CHAT", true, time.Now()}
|
||||
initialMessage := models.ChatMessage{"owncast-server", config.Config.InstanceDetails.Name, initialChatMessageText, config.Config.InstanceDetails.Logo.Small, "initial-message-1", "CHAT", true, time.Now()}
|
||||
c.Write(initialMessage)
|
||||
}()
|
||||
|
||||
|
||||
@@ -13,12 +13,14 @@ import (
|
||||
"github.com/gabek/owncast/core/ffmpeg"
|
||||
"github.com/gabek/owncast/models"
|
||||
"github.com/gabek/owncast/utils"
|
||||
"github.com/gabek/owncast/yp"
|
||||
)
|
||||
|
||||
var (
|
||||
_stats *models.Stats
|
||||
_storage models.ChunkStorageProvider
|
||||
_cleanupTimer *time.Timer
|
||||
_yp *yp.YP
|
||||
)
|
||||
|
||||
//Start starts up the core processing
|
||||
@@ -40,6 +42,12 @@ func Start() error {
|
||||
return err
|
||||
}
|
||||
|
||||
if config.Config.YP.Enabled {
|
||||
_yp = yp.NewYP(GetStatus)
|
||||
} else {
|
||||
yp.DisplayInstructions()
|
||||
}
|
||||
|
||||
chat.Setup(ChatListenerImpl{})
|
||||
|
||||
return nil
|
||||
|
||||
@@ -40,6 +40,7 @@ func StartThumbnailGenerator(chunkPath string, variantIndex int) {
|
||||
func fireThumbnailGenerator(chunkPath string, variantIndex int) error {
|
||||
// JPG takes less time to encode than PNG
|
||||
outputFile := path.Join("webroot", "thumbnail.jpg")
|
||||
previewGifFile := path.Join("webroot", "preview.gif")
|
||||
|
||||
framePath := path.Join(chunkPath, strconv.Itoa(variantIndex))
|
||||
files, err := ioutil.ReadDir(framePath)
|
||||
@@ -83,12 +84,32 @@ func fireThumbnailGenerator(chunkPath string, variantIndex int) error {
|
||||
}
|
||||
|
||||
ffmpegCmd := strings.Join(thumbnailCmdFlags, " ")
|
||||
|
||||
// fmt.Println(ffmpegCmd)
|
||||
|
||||
if _, err := exec.Command("sh", "-c", ffmpegCmd).Output(); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// If YP support is enabled also create an animated GIF preview
|
||||
if config.Config.YP.Enabled {
|
||||
makeAnimatedGifPreview(mostRecentFile, previewGifFile)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func makeAnimatedGifPreview(sourceFile string, outputFile string) {
|
||||
// Filter is pulled from https://engineering.giphy.com/how-to-make-gifs-with-ffmpeg/
|
||||
animatedGifFlags := []string{
|
||||
config.Config.GetFFMpegPath(),
|
||||
"-y", // Overwrite file
|
||||
"-threads 1", // Low priority processing
|
||||
"-i", sourceFile, // Input
|
||||
"-t 1", // Output is one second in length
|
||||
"-filter_complex", "\"[0:v] fps=8,scale=w=480:h=-1:flags=lanczos,split [a][b];[a] palettegen=stats_mode=full [p];[b][p] paletteuse=new=1\"",
|
||||
outputFile,
|
||||
}
|
||||
|
||||
ffmpegCmd := strings.Join(animatedGifFlags, " ")
|
||||
if _, err := exec.Command("sh", "-c", ffmpegCmd).Output(); err != nil {
|
||||
log.Errorln(err)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -38,6 +38,10 @@ func SetStreamAsConnected() {
|
||||
chunkPath = config.Config.GetPrivateHLSSavePath()
|
||||
}
|
||||
|
||||
if _yp != nil {
|
||||
_yp.Start()
|
||||
}
|
||||
|
||||
ffmpeg.StartThumbnailGenerator(chunkPath, config.Config.VideoSettings.HighestQualityStreamIndex)
|
||||
}
|
||||
|
||||
@@ -46,6 +50,10 @@ func SetStreamAsDisconnected() {
|
||||
_stats.StreamConnected = false
|
||||
_stats.LastDisconnectTime = utils.NullTime{time.Now(), true}
|
||||
|
||||
if _yp != nil {
|
||||
_yp.Stop()
|
||||
}
|
||||
|
||||
ffmpeg.ShowStreamOfflineState()
|
||||
startCleanupTimer()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user