mirror of
https://github.com/stashapp/stash.git
synced 2025-12-17 20:34:37 +03:00
Support image clips/gifs (#3583)
Co-authored-by: WithoutPants <53250216+WithoutPants@users.noreply.github.com>
This commit is contained in:
68
internal/manager/task_generate_clip_preview.go
Normal file
68
internal/manager/task_generate_clip_preview.go
Normal file
@@ -0,0 +1,68 @@
|
||||
package manager
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"github.com/stashapp/stash/pkg/file"
|
||||
"github.com/stashapp/stash/pkg/fsutil"
|
||||
"github.com/stashapp/stash/pkg/image"
|
||||
"github.com/stashapp/stash/pkg/logger"
|
||||
"github.com/stashapp/stash/pkg/models"
|
||||
)
|
||||
|
||||
type GenerateClipPreviewTask struct {
|
||||
Image models.Image
|
||||
Overwrite bool
|
||||
}
|
||||
|
||||
func (t *GenerateClipPreviewTask) GetDescription() string {
|
||||
return fmt.Sprintf("Generating Preview for image Clip %s", t.Image.Path)
|
||||
}
|
||||
|
||||
func (t *GenerateClipPreviewTask) Start(ctx context.Context) {
|
||||
if !t.required() {
|
||||
return
|
||||
}
|
||||
|
||||
prevPath := GetInstance().Paths.Generated.GetClipPreviewPath(t.Image.Checksum, models.DefaultGthumbWidth)
|
||||
filePath := t.Image.Files.Primary().Base().Path
|
||||
|
||||
clipPreviewOptions := image.ClipPreviewOptions{
|
||||
InputArgs: GetInstance().Config.GetTranscodeInputArgs(),
|
||||
OutputArgs: GetInstance().Config.GetTranscodeOutputArgs(),
|
||||
Preset: GetInstance().Config.GetPreviewPreset().String(),
|
||||
}
|
||||
|
||||
encoder := image.NewThumbnailEncoder(GetInstance().FFMPEG, GetInstance().FFProbe, clipPreviewOptions)
|
||||
data, err := encoder.GetPreview(t.Image.Files.Primary(), models.DefaultGthumbWidth)
|
||||
if err != nil {
|
||||
logger.Errorf("getting preview for image %s: %w", filePath, err)
|
||||
return
|
||||
}
|
||||
|
||||
err = fsutil.WriteFile(prevPath, data)
|
||||
if err != nil {
|
||||
logger.Errorf("writing preview for image %s: %w", filePath, err)
|
||||
return
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func (t *GenerateClipPreviewTask) required() bool {
|
||||
_, ok := t.Image.Files.Primary().(*file.VideoFile)
|
||||
if !ok {
|
||||
return false
|
||||
}
|
||||
|
||||
if t.Overwrite {
|
||||
return true
|
||||
}
|
||||
|
||||
prevPath := GetInstance().Paths.Generated.GetClipPreviewPath(t.Image.Checksum, models.DefaultGthumbWidth)
|
||||
if exists, _ := fsutil.FileExists(prevPath); exists {
|
||||
return false
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
Reference in New Issue
Block a user