2020-01-19 12:50:44 +01:00
|
|
|
package photoprism
|
|
|
|
|
2020-07-14 18:00:32 +02:00
|
|
|
import (
|
|
|
|
"strings"
|
|
|
|
|
2022-04-15 09:42:07 +02:00
|
|
|
"github.com/photoprism/photoprism/pkg/clean"
|
2020-07-14 18:00:32 +02:00
|
|
|
)
|
2020-02-01 22:48:07 +01:00
|
|
|
|
2020-01-19 12:50:44 +01:00
|
|
|
type ConvertJob struct {
|
2022-04-03 12:26:07 +02:00
|
|
|
force bool
|
2021-02-11 21:37:44 +01:00
|
|
|
file *MediaFile
|
2020-01-19 12:50:44 +01:00
|
|
|
convert *Convert
|
|
|
|
}
|
|
|
|
|
2020-04-06 22:09:45 +02:00
|
|
|
func ConvertWorker(jobs <-chan ConvertJob) {
|
2021-02-11 21:37:44 +01:00
|
|
|
logError := func(err error, job ConvertJob) {
|
|
|
|
fileName := job.file.RelName(job.convert.conf.OriginalsPath())
|
2022-04-15 09:42:07 +02:00
|
|
|
log.Errorf("convert: %s for %s", strings.TrimSpace(err.Error()), clean.Log(fileName))
|
2021-02-11 21:37:44 +01:00
|
|
|
}
|
|
|
|
|
2020-01-19 12:50:44 +01:00
|
|
|
for job := range jobs {
|
2021-02-11 21:37:44 +01:00
|
|
|
switch {
|
|
|
|
case job.file == nil:
|
|
|
|
continue
|
|
|
|
case job.convert == nil:
|
|
|
|
continue
|
2022-04-13 22:17:59 +02:00
|
|
|
case job.file.IsAnimated():
|
2021-02-17 16:48:20 +01:00
|
|
|
_, _ = job.convert.ToJson(job.file)
|
|
|
|
|
2022-04-03 12:26:07 +02:00
|
|
|
// Create JPEG preview and AVC encoded version for videos.
|
|
|
|
if _, err := job.convert.ToJpeg(job.file, job.force); err != nil {
|
2021-02-11 21:37:44 +01:00
|
|
|
logError(err, job)
|
|
|
|
} else if metaData := job.file.MetaData(); metaData.CodecAvc() {
|
|
|
|
continue
|
2022-04-06 17:46:41 +02:00
|
|
|
} else if _, err := job.convert.ToAvc(job.file, job.convert.conf.FFmpegEncoder(), false, false); err != nil {
|
2021-02-11 21:37:44 +01:00
|
|
|
logError(err, job)
|
|
|
|
}
|
|
|
|
default:
|
2022-04-03 12:26:07 +02:00
|
|
|
if _, err := job.convert.ToJpeg(job.file, job.force); err != nil {
|
2021-02-11 21:37:44 +01:00
|
|
|
logError(err, job)
|
|
|
|
}
|
2020-01-19 12:50:44 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|