Support image clips/gifs (#3583)

Co-authored-by: WithoutPants <53250216+WithoutPants@users.noreply.github.com>
This commit is contained in:
yoshnopa
2023-05-17 01:30:51 +02:00
committed by GitHub
parent 0e199a525f
commit a2e477e1a7
62 changed files with 999 additions and 363 deletions

View File

@@ -9,12 +9,15 @@ import (
_ "image/jpeg"
_ "image/png"
"github.com/stashapp/stash/pkg/ffmpeg"
"github.com/stashapp/stash/pkg/file"
"github.com/stashapp/stash/pkg/file/video"
_ "golang.org/x/image/webp"
)
// Decorator adds image specific fields to a File.
type Decorator struct {
FFProbe ffmpeg.FFProbe
}
func (d *Decorator) Decorate(ctx context.Context, fs file.FS, f file.File) (file.File, error) {
@@ -25,16 +28,38 @@ func (d *Decorator) Decorate(ctx context.Context, fs file.FS, f file.File) (file
}
defer r.Close()
c, format, err := image.DecodeConfig(r)
probe, err := d.FFProbe.NewVideoFile(base.Path)
if err != nil {
return f, fmt.Errorf("decoding image file %q: %w", base.Path, err)
fmt.Printf("Warning: File %q could not be read with ffprobe: %s, assuming ImageFile", base.Path, err)
c, format, err := image.DecodeConfig(r)
if err != nil {
return f, fmt.Errorf("decoding image file %q: %w", base.Path, err)
}
return &file.ImageFile{
BaseFile: base,
Format: format,
Width: c.Width,
Height: c.Height,
}, nil
}
isClip := true
// This list is derived from ffmpegImageThumbnail in pkg/image/thumbnail. If one gets updated, the other should be as well
for _, item := range []string{"png", "mjpeg", "webp"} {
if item == probe.VideoCodec {
isClip = false
}
}
if isClip {
videoFileDecorator := video.Decorator{FFProbe: d.FFProbe}
return videoFileDecorator.Decorate(ctx, fs, f)
}
return &file.ImageFile{
BaseFile: base,
Format: format,
Width: c.Width,
Height: c.Height,
Format: probe.VideoCodec,
Width: probe.Width,
Height: probe.Height,
}, nil
}