mirror of
https://github.com/stashapp/stash.git
synced 2025-12-18 12:54:38 +03:00
Improve image scanning performance and thumbnail generation (#1655)
* Improve image scanning performance and thumbnail generation * Add vips-tools to build image * Add option to write generated thumbnails to disk * Fallback to image if thumbnail generation fails Co-authored-by: WithoutPants <53250216+WithoutPants@users.noreply.github.com>
This commit is contained in:
@@ -84,6 +84,9 @@ const previewExcludeStartDefault = "0"
|
||||
const PreviewExcludeEnd = "preview_exclude_end"
|
||||
const previewExcludeEndDefault = "0"
|
||||
|
||||
const WriteImageThumbnails = "write_image_thumbnails"
|
||||
const writeImageThumbnailsDefault = true
|
||||
|
||||
const Host = "host"
|
||||
const Port = "port"
|
||||
const ExternalHost = "external_host"
|
||||
@@ -595,6 +598,14 @@ func (i *Instance) GetMaxStreamingTranscodeSize() models.StreamingResolutionEnum
|
||||
return models.StreamingResolutionEnum(ret)
|
||||
}
|
||||
|
||||
// IsWriteImageThumbnails returns true if image thumbnails should be written
|
||||
// to disk after generating on the fly.
|
||||
func (i *Instance) IsWriteImageThumbnails() bool {
|
||||
i.RLock()
|
||||
defer i.RUnlock()
|
||||
return viper.GetBool(WriteImageThumbnails)
|
||||
}
|
||||
|
||||
func (i *Instance) GetAPIKey() string {
|
||||
i.RLock()
|
||||
defer i.RUnlock()
|
||||
@@ -968,6 +979,8 @@ func (i *Instance) setDefaultValues() error {
|
||||
viper.SetDefault(PreviewAudio, previewAudioDefault)
|
||||
viper.SetDefault(SoundOnPreview, false)
|
||||
|
||||
viper.SetDefault(WriteImageThumbnails, writeImageThumbnailsDefault)
|
||||
|
||||
viper.SetDefault(Database, defaultDatabaseFilePath)
|
||||
|
||||
// Set generated to the metadata path for backwards compat
|
||||
|
||||
@@ -103,6 +103,7 @@ func (j *ScanJob) Execute(ctx context.Context, progress *job.Progress) {
|
||||
GenerateImagePreview: utils.IsTrue(input.ScanGenerateImagePreviews),
|
||||
GenerateSprite: utils.IsTrue(input.ScanGenerateSprites),
|
||||
GeneratePhash: utils.IsTrue(input.ScanGeneratePhashes),
|
||||
GenerateThumbnails: utils.IsTrue(input.ScanGenerateThumbnails),
|
||||
progress: progress,
|
||||
CaseSensitiveFs: csFs,
|
||||
ctx: ctx,
|
||||
@@ -221,6 +222,7 @@ type ScanTask struct {
|
||||
GeneratePhash bool
|
||||
GeneratePreview bool
|
||||
GenerateImagePreview bool
|
||||
GenerateThumbnails bool
|
||||
zipGallery *models.Gallery
|
||||
progress *job.Progress
|
||||
CaseSensitiveFs bool
|
||||
@@ -1275,20 +1277,26 @@ func (t *ScanTask) associateImageWithFolderGallery(imageID int, qb models.Galler
|
||||
}
|
||||
|
||||
func (t *ScanTask) generateThumbnail(i *models.Image) {
|
||||
if !t.GenerateThumbnails {
|
||||
return
|
||||
}
|
||||
|
||||
thumbPath := GetInstance().Paths.Generated.GetThumbnailPath(i.Checksum, models.DefaultGthumbWidth)
|
||||
exists, _ := utils.FileExists(thumbPath)
|
||||
if exists {
|
||||
return
|
||||
}
|
||||
|
||||
srcImage, err := image.GetSourceImage(i)
|
||||
config, _, err := image.DecodeSourceImage(i)
|
||||
if err != nil {
|
||||
logger.Errorf("error reading image %s: %s", i.Path, err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
if image.ThumbnailNeeded(srcImage, models.DefaultGthumbWidth) {
|
||||
data, err := image.GetThumbnail(srcImage, models.DefaultGthumbWidth)
|
||||
if config.Height > models.DefaultGthumbWidth || config.Width > models.DefaultGthumbWidth {
|
||||
encoder := image.NewThumbnailEncoder(instance.FFMPEGPath)
|
||||
data, err := encoder.GetThumbnail(i, models.DefaultGthumbWidth)
|
||||
|
||||
if err != nil {
|
||||
logger.Errorf("error getting thumbnail for image %s: %s", i.Path, err.Error())
|
||||
return
|
||||
|
||||
Reference in New Issue
Block a user