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:
Gabe Kangas
2020-10-01 23:55:38 -07:00
committed by GitHub
parent 6946d4b3ea
commit 9b7784634b
15 changed files with 278 additions and 14 deletions

View File

@@ -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)
}
}