2021-02-17 18:19:52 +01:00
|
|
|
package config
|
|
|
|
|
2022-04-06 17:46:41 +02:00
|
|
|
import "github.com/photoprism/photoprism/internal/ffmpeg"
|
|
|
|
|
2021-02-17 18:19:52 +01:00
|
|
|
// FFmpegBin returns the ffmpeg executable file name.
|
|
|
|
func (c *Config) FFmpegBin() string {
|
2022-10-12 18:39:30 +02:00
|
|
|
return findBin(c.options.FFmpegBin, "ffmpeg")
|
2021-02-17 18:19:52 +01:00
|
|
|
}
|
|
|
|
|
2022-04-06 17:46:41 +02:00
|
|
|
// FFmpegEnabled checks if FFmpeg is enabled for video transcoding.
|
2021-04-30 14:24:01 +02:00
|
|
|
func (c *Config) FFmpegEnabled() bool {
|
|
|
|
return !c.DisableFFmpeg()
|
|
|
|
}
|
|
|
|
|
2022-04-06 17:46:41 +02:00
|
|
|
// FFmpegEncoder returns the FFmpeg AVC encoder name.
|
|
|
|
func (c *Config) FFmpegEncoder() ffmpeg.AvcEncoder {
|
2022-07-05 23:13:34 +02:00
|
|
|
if c.options.FFmpegEncoder == "" || c.options.FFmpegEncoder == ffmpeg.SoftwareEncoder.String() {
|
|
|
|
return ffmpeg.SoftwareEncoder
|
|
|
|
} else if c.NoSponsor() {
|
|
|
|
log.Infof("ffmpeg: hardware transcoding is available to sponsors only")
|
|
|
|
return ffmpeg.SoftwareEncoder
|
|
|
|
}
|
|
|
|
|
2022-04-06 17:46:41 +02:00
|
|
|
return ffmpeg.FindEncoder(c.options.FFmpegEncoder)
|
2021-02-17 18:19:52 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// FFmpegBitrate returns the ffmpeg bitrate limit in MBit/s.
|
|
|
|
func (c *Config) FFmpegBitrate() int {
|
|
|
|
switch {
|
|
|
|
case c.options.FFmpegBitrate <= 0:
|
|
|
|
return 50
|
|
|
|
case c.options.FFmpegBitrate >= 960:
|
|
|
|
return 960
|
|
|
|
default:
|
|
|
|
return c.options.FFmpegBitrate
|
|
|
|
}
|
|
|
|
}
|
2022-06-26 19:47:12 +02:00
|
|
|
|
|
|
|
// FFmpegBitrateExceeded tests if the ffmpeg bitrate limit is exceeded.
|
|
|
|
func (c *Config) FFmpegBitrateExceeded(mbit float64) bool {
|
|
|
|
if mbit <= 0 {
|
|
|
|
return false
|
|
|
|
} else if max := c.FFmpegBitrate(); max <= 0 {
|
|
|
|
return false
|
|
|
|
} else {
|
|
|
|
return mbit > float64(max)
|
|
|
|
}
|
|
|
|
}
|