HEIF: Use heif-convert.sh as wrapper if exists #2726

Signed-off-by: Michael Mayer <michael@photoprism.app>
This commit is contained in:
Michael Mayer 2022-10-06 21:55:31 +02:00
parent 4fdbeed621
commit 07816bfb77
4 changed files with 18 additions and 1 deletions

View file

@ -106,6 +106,11 @@ func (c *Config) HeifConvertBin() string {
return findExecutable(c.options.HeifConvertBin, "heif-convert")
}
// HeifConvertScript returns the heif-convert wrapper script name.
func (c *Config) HeifConvertScript() string {
return findExecutable("heif-convert.sh", "")
}
// HeifConvertEnabled checks if heif-convert is enabled for HEIF conversion.
func (c *Config) HeifConvertEnabled() bool {
return !c.DisableHeifConvert()

View file

@ -81,6 +81,13 @@ func TestConfig_HeifConvertBin(t *testing.T) {
assert.Contains(t, bin, "/bin/heif-convert")
}
func TestConfig_HeifConvertScript(t *testing.T) {
c := NewConfig(CliTestContext())
bin := c.HeifConvertScript()
assert.Contains(t, bin, "/bin/heif-convert.sh")
}
func TestConfig_HeifConvertEnabled(t *testing.T) {
c := NewConfig(CliTestContext())
assert.True(t, c.HeifConvertEnabled())

View file

@ -149,6 +149,7 @@ func (c *Config) Report() (rows [][]string, cols []string) {
{"sips-bin", c.SipsBin()},
{"sips-blacklist", c.SipsBlacklist()},
{"heifconvert-bin", c.HeifConvertBin()},
{"heifconvert-script", c.HeifConvertScript()},
{"ffmpeg-bin", c.FFmpegBin()},
{"ffmpeg-encoder", c.FFmpegEncoder().String()},
{"ffmpeg-bitrate", fmt.Sprintf("%d", c.FFmpegBitrate())},

View file

@ -182,7 +182,11 @@ func (c *Convert) JpegConvertCommand(f *MediaFile, jpegName string, xmpName stri
} else if f.IsVideo() && c.conf.FFmpegEnabled() {
result = exec.Command(c.conf.FFmpegBin(), "-y", "-i", f.FileName(), "-ss", "00:00:00.001", "-vframes", "1", jpegName)
} else if f.IsHEIF() && c.conf.HeifConvertEnabled() {
result = exec.Command(c.conf.HeifConvertBin(), f.FileName(), jpegName)
if scriptName := c.conf.HeifConvertScript(); scriptName != "" {
result = exec.Command(scriptName, f.FileName(), jpegName)
} else {
result = exec.Command(c.conf.HeifConvertBin(), f.FileName(), jpegName)
}
} else {
return nil, useMutex, fmt.Errorf("file type %s not supported", f.FileType())
}