photoprism/internal/photoprism/convert_worker.go

45 lines
1.1 KiB
Go
Raw Normal View History

package photoprism
import (
"strings"
"github.com/photoprism/photoprism/pkg/sanitize"
)
type ConvertJob struct {
force bool
file *MediaFile
convert *Convert
}
func ConvertWorker(jobs <-chan ConvertJob) {
logError := func(err error, job ConvertJob) {
fileName := job.file.RelName(job.convert.conf.OriginalsPath())
log.Errorf("convert: %s for %s", strings.TrimSpace(err.Error()), sanitize.Log(fileName))
}
for job := range jobs {
switch {
case job.file == nil:
continue
case job.convert == nil:
continue
case job.file.IsVideo():
_, _ = job.convert.ToJson(job.file)
// Create JPEG preview and AVC encoded version for videos.
if _, err := job.convert.ToJpeg(job.file, job.force); err != nil {
logError(err, job)
} else if metaData := job.file.MetaData(); metaData.CodecAvc() {
continue
} else if _, err := job.convert.ToAvc(job.file, job.convert.conf.FFmpegEncoder(), false, false); err != nil {
logError(err, job)
}
default:
if _, err := job.convert.ToJpeg(job.file, job.force); err != nil {
logError(err, job)
}
}
}
}