From 51e2e6801709b52c0d57cff9deebe64fcbdcfd90 Mon Sep 17 00:00:00 2001 From: Gabe Kangas Date: Mon, 13 Jul 2020 14:32:12 -0700 Subject: [PATCH] Support default path of ffmpeg and not needing to specify it in the config --- config-example.yaml | 1 - config/config.go | 30 +++++++++++++++++++----------- core/ffmpeg/thumbnailGenerator.go | 2 +- core/ffmpeg/transcoder.go | 2 +- 4 files changed, 21 insertions(+), 14 deletions(-) diff --git a/config-example.yaml b/config-example.yaml index 33612938d..900039338 100644 --- a/config-example.yaml +++ b/config-example.yaml @@ -1,6 +1,5 @@ publicHLSPath: webroot/hls privateHLSPath: hls -ffmpegPath: /usr/bin/ffmpeg webServerPort: 8080 instanceDetails: diff --git a/config/config.go b/config/config.go index 9116ccd5d..35e0f3c69 100644 --- a/config/config.go +++ b/config/config.go @@ -2,8 +2,9 @@ package config import ( "errors" - "fmt" "io/ioutil" + "os/exec" + "strings" "github.com/gabek/owncast/utils" log "github.com/sirupsen/logrus" @@ -132,19 +133,26 @@ func (c *config) verifySettings() error { } } - // if !fileExists(config.PrivateHLSPath) { - // os.MkdirAll(path.Join(config.PrivateHLSPath, strconv.Itoa(0)), 0777) - // } + return nil +} - // if !fileExists(config.PublicHLSPath) { - // os.MkdirAll(path.Join(config.PublicHLSPath, strconv.Itoa(0)), 0777) - // } - - if !utils.DoesFileExists(c.FFMpegPath) { - return fmt.Errorf("ffmpeg does not exist at: %s", c.FFMpegPath) +func (c *config) GetFFMpegPath() string { + if c.FFMpegPath != "" { + return c.FFMpegPath } - return nil + cmd := exec.Command("which", "ffmpeg") + out, err := cmd.CombinedOutput() + if err != nil { + log.Panicln("Unable to determine path to ffmpeg. Please specify it in the config file.") + } + + path := strings.TrimSpace(string(out)) + + // Memoize it for future access + c.FFMpegPath = path + + return path } //Load tries to load the configuration file diff --git a/core/ffmpeg/thumbnailGenerator.go b/core/ffmpeg/thumbnailGenerator.go index cd5ecde13..388458a8b 100644 --- a/core/ffmpeg/thumbnailGenerator.go +++ b/core/ffmpeg/thumbnailGenerator.go @@ -72,7 +72,7 @@ func fireThumbnailGenerator(chunkPath string, variantIndex int) error { mostRecentFile := path.Join(framePath, names[0]) thumbnailCmdFlags := []string{ - config.Config.FFMpegPath, + config.Config.GetFFMpegPath(), "-y", // Overwrite file "-threads 1", // Low priority processing "-t 1", // Pull from frame 1 diff --git a/core/ffmpeg/transcoder.go b/core/ffmpeg/transcoder.go index 3b9bc872b..ff26e4a74 100644 --- a/core/ffmpeg/transcoder.go +++ b/core/ffmpeg/transcoder.go @@ -104,7 +104,7 @@ func (t *Transcoder) getString() string { ffmpegFlags := []string{ "cat", t.input, "|", - config.Config.FFMpegPath, + config.Config.GetFFMpegPath(), "-hide_banner", "-i pipe:", t.getVariantsString(),