mirror of
https://github.com/stashapp/stash.git
synced 2025-12-17 20:34:37 +03:00
Restructure ffmpeg (#2392)
* Refactor transcode generation * Move phash generation into separate package * Refactor image thumbnail generation * Move JSONTime to separate package * Ffmpeg refactoring * Refactor live transcoding * Refactor scene marker preview generation * Refactor preview generation * Refactor screenshot generation * Refactor sprite generation * Change ffmpeg.IsStreamable to return error * Move frame rate calculation into ffmpeg * Refactor file locking * Refactor title set during scan * Add missing lockmanager instance * Return error instead of logging in MatchContainer
This commit is contained in:
@@ -2,6 +2,7 @@ package image
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"image"
|
||||
@@ -10,19 +11,24 @@ import (
|
||||
"sync"
|
||||
|
||||
"github.com/stashapp/stash/pkg/ffmpeg"
|
||||
"github.com/stashapp/stash/pkg/ffmpeg/transcoder"
|
||||
"github.com/stashapp/stash/pkg/models"
|
||||
)
|
||||
|
||||
const ffmpegImageQuality = 5
|
||||
|
||||
var vipsPath string
|
||||
var once sync.Once
|
||||
|
||||
var (
|
||||
ErrUnsupportedImageFormat = errors.New("unsupported image format")
|
||||
|
||||
// ErrNotSupportedForThumbnail is returned if the image format is not supported for thumbnail generation
|
||||
ErrNotSupportedForThumbnail = errors.New("unsupported image format for thumbnail")
|
||||
)
|
||||
|
||||
type ThumbnailEncoder struct {
|
||||
ffmpeg ffmpeg.Encoder
|
||||
ffmpeg ffmpeg.FFMpeg
|
||||
vips *vipsEncoder
|
||||
}
|
||||
|
||||
@@ -33,7 +39,7 @@ func GetVipsPath() string {
|
||||
return vipsPath
|
||||
}
|
||||
|
||||
func NewThumbnailEncoder(ffmpegEncoder ffmpeg.Encoder) ThumbnailEncoder {
|
||||
func NewThumbnailEncoder(ffmpegEncoder ffmpeg.FFMpeg) ThumbnailEncoder {
|
||||
ret := ThumbnailEncoder{
|
||||
ffmpeg: ffmpegEncoder,
|
||||
}
|
||||
@@ -86,6 +92,30 @@ func (e *ThumbnailEncoder) GetThumbnail(img *models.Image, maxSize int) ([]byte,
|
||||
if e.vips != nil && runtime.GOOS != "windows" {
|
||||
return e.vips.ImageThumbnail(buf, maxSize)
|
||||
} else {
|
||||
return e.ffmpeg.ImageThumbnail(buf, format, maxSize, img.Path)
|
||||
return e.ffmpegImageThumbnail(buf, format, maxSize)
|
||||
}
|
||||
}
|
||||
|
||||
func (e *ThumbnailEncoder) ffmpegImageThumbnail(image *bytes.Buffer, format string, maxSize int) ([]byte, error) {
|
||||
var ffmpegFormat ffmpeg.ImageFormat
|
||||
|
||||
switch format {
|
||||
case "jpeg":
|
||||
ffmpegFormat = ffmpeg.ImageFormatJpeg
|
||||
case "png":
|
||||
ffmpegFormat = ffmpeg.ImageFormatPng
|
||||
case "webp":
|
||||
ffmpegFormat = ffmpeg.ImageFormatWebp
|
||||
default:
|
||||
return nil, ErrUnsupportedImageFormat
|
||||
}
|
||||
|
||||
args := transcoder.ImageThumbnail("-", transcoder.ImageThumbnailOptions{
|
||||
InputFormat: ffmpegFormat,
|
||||
OutputPath: "-",
|
||||
MaxDimensions: maxSize,
|
||||
Quality: ffmpegImageQuality,
|
||||
})
|
||||
|
||||
return e.ffmpeg.GenerateOutput(context.TODO(), args)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user