-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
/
convert_worker.go
57 lines (47 loc) Β· 1.34 KB
/
convert_worker.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
package photoprism
import (
"strings"
"github.com/photoprism/photoprism/pkg/clean"
)
type ConvertJob struct {
force bool
file *MediaFile
convert *Convert
}
func ConvertWorker(jobs <-chan ConvertJob) {
convertErr := func(err error, job ConvertJob) {
fileName := job.file.RelName(job.convert.conf.OriginalsPath())
log.Errorf("convert: %s for %s", strings.TrimSpace(err.Error()), clean.Log(fileName))
}
for job := range jobs {
// File and convert service must not be nil.
if job.file == nil || job.convert == nil {
continue
}
// f is the media file to be converted.
f := job.file
switch {
case f.IsAnimated():
// Extract metadata.
_, _ = job.convert.ToJson(f, false)
// Create cover image.
if _, err := job.convert.ToImage(f, job.force); err != nil {
convertErr(err, job)
}
// Check if the file has a playable format or has already been transcoded.
if f.SkipTranscoding() {
log.Debugf("convert: %s does not require transcoding", clean.Log(f.RelName(job.convert.conf.OriginalsPath())))
continue
}
// Transcode to MP4 AVC.
if _, err := job.convert.ToAvc(f, job.convert.conf.FFmpegEncoder(), false, false); err != nil {
convertErr(err, job)
}
default:
// Create preview image.
if _, err := job.convert.ToImage(f, job.force); err != nil {
convertErr(err, job)
}
}
}
}