mirror of
https://github.com/stashapp/stash.git
synced 2025-12-06 08:26:00 +01:00
Feature Request: Vips AVIF Support (#6337)
This commit is contained in:
parent
de8139cf1b
commit
c6ae43c1d6
2 changed files with 44 additions and 4 deletions
|
|
@ -96,10 +96,14 @@ func (e *ThumbnailEncoder) GetThumbnail(f models.File, maxSize int) ([]byte, err
|
||||||
|
|
||||||
// AVIF cannot be read from stdin, must use file path
|
// AVIF cannot be read from stdin, must use file path
|
||||||
// AVIF in zip files is not supported
|
// AVIF in zip files is not supported
|
||||||
|
// Note: No Windows check needed here since we use file path, not stdin
|
||||||
if format == "avif" {
|
if format == "avif" {
|
||||||
if f.Base().ZipFileID != nil {
|
if f.Base().ZipFileID != nil {
|
||||||
return nil, fmt.Errorf("%w: AVIF in zip file", ErrNotSupportedForThumbnail)
|
return nil, fmt.Errorf("%w: AVIF in zip file", ErrNotSupportedForThumbnail)
|
||||||
}
|
}
|
||||||
|
if e.vips != nil {
|
||||||
|
return e.vips.ImageThumbnailPath(f.Base().Path, maxSize)
|
||||||
|
}
|
||||||
return e.ffmpegImageThumbnailPath(f.Base().Path, maxSize)
|
return e.ffmpegImageThumbnailPath(f.Base().Path, maxSize)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -110,11 +114,15 @@ func (e *ThumbnailEncoder) GetThumbnail(f models.File, maxSize int) ([]byte, err
|
||||||
}
|
}
|
||||||
|
|
||||||
// vips has issues loading files from stdin on Windows
|
// vips has issues loading files from stdin on Windows
|
||||||
if e.vips != nil && runtime.GOOS != "windows" {
|
if e.vips != nil {
|
||||||
return e.vips.ImageThumbnail(buf, maxSize)
|
if runtime.GOOS == "windows" && f.Base().ZipFileID == nil {
|
||||||
} else {
|
return e.vips.ImageThumbnailPath(f.Base().Path, maxSize)
|
||||||
return e.ffmpegImageThumbnail(buf, maxSize)
|
}
|
||||||
|
if runtime.GOOS != "windows" {
|
||||||
|
return e.vips.ImageThumbnail(buf, maxSize)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
return e.ffmpegImageThumbnail(buf, maxSize)
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetPreview returns the preview clip of the provided image clip resized to
|
// GetPreview returns the preview clip of the provided image clip resized to
|
||||||
|
|
|
||||||
|
|
@ -24,6 +24,38 @@ func (e *vipsEncoder) ImageThumbnail(image *bytes.Buffer, maxSize int) ([]byte,
|
||||||
return []byte(data), err
|
return []byte(data), err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ImageThumbnailPath generates a thumbnail from a file path instead of stdin.
|
||||||
|
// This is required for formats like AVIF that need random file access (seeking)
|
||||||
|
// which stdin cannot provide.
|
||||||
|
func (e *vipsEncoder) ImageThumbnailPath(path string, maxSize int) ([]byte, error) {
|
||||||
|
// vips thumbnail syntax: thumbnail input output width [options]
|
||||||
|
// Using .jpg[Q=70,strip] as output writes to stdout
|
||||||
|
args := []string{
|
||||||
|
"thumbnail",
|
||||||
|
path,
|
||||||
|
".jpg[Q=70,strip]",
|
||||||
|
fmt.Sprint(maxSize),
|
||||||
|
"--size", "down",
|
||||||
|
}
|
||||||
|
|
||||||
|
cmd := exec.Command(string(*e), args...)
|
||||||
|
|
||||||
|
var stdout, stderr bytes.Buffer
|
||||||
|
cmd.Stdout = &stdout
|
||||||
|
cmd.Stderr = &stderr
|
||||||
|
|
||||||
|
if err := cmd.Start(); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := cmd.Wait(); err != nil {
|
||||||
|
logger.Errorf("image encoder error when running command <%s>: %s", strings.Join(cmd.Args, " "), stderr.String())
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return stdout.Bytes(), nil
|
||||||
|
}
|
||||||
|
|
||||||
func (e *vipsEncoder) run(args []string, stdin *bytes.Buffer) (string, error) {
|
func (e *vipsEncoder) run(args []string, stdin *bytes.Buffer) (string, error) {
|
||||||
cmd := exec.Command(string(*e), args...)
|
cmd := exec.Command(string(*e), args...)
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue