mirror of
https://github.com/stashapp/stash.git
synced 2025-12-06 08:26:00 +01:00
* Refactor transaction hooks. Add preCommit * Add BlobStore * Use blobStore for tag images * Use blobStore for studio images * Use blobStore for performer images * Use blobStore for scene covers * Don't generate screenshots in legacy directory * Run post-hooks outside original transaction * Use blobStore for movie images * Remove unnecessary DestroyImage methods * Add missing filter for scene cover * Add covers to generate options * Add generate cover option to UI * Add screenshot migration * Delete thumb files as part of screenshot migration
66 lines
1.5 KiB
Go
66 lines
1.5 KiB
Go
package generate
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/stashapp/stash/pkg/ffmpeg/transcoder"
|
|
"github.com/stashapp/stash/pkg/fsutil"
|
|
"github.com/stashapp/stash/pkg/logger"
|
|
)
|
|
|
|
const (
|
|
// thumbnailWidth = 320
|
|
// thumbnailQuality = 5
|
|
|
|
screenshotQuality = 2
|
|
|
|
screenshotDurationProportion = 0.2
|
|
)
|
|
|
|
type ScreenshotOptions struct {
|
|
At *float64
|
|
}
|
|
|
|
func (g Generator) Screenshot(ctx context.Context, input string, videoWidth int, videoDuration float64, options ScreenshotOptions) ([]byte, error) {
|
|
lockCtx := g.LockManager.ReadLock(ctx, input)
|
|
defer lockCtx.Cancel()
|
|
|
|
logger.Infof("Creating screenshot for %s", input)
|
|
|
|
at := screenshotDurationProportion * videoDuration
|
|
if options.At != nil {
|
|
at = *options.At
|
|
}
|
|
|
|
ret, err := g.generateBytes(lockCtx, g.ScenePaths, jpgPattern, g.screenshot(input, screenshotOptions{
|
|
Time: at,
|
|
Quality: screenshotQuality,
|
|
// default Width is video width
|
|
}))
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
return ret, nil
|
|
}
|
|
|
|
type screenshotOptions struct {
|
|
Time float64
|
|
Width int
|
|
Quality int
|
|
}
|
|
|
|
func (g Generator) screenshot(input string, options screenshotOptions) generateFn {
|
|
return func(lockCtx *fsutil.LockContext, tmpFn string) error {
|
|
ssOptions := transcoder.ScreenshotOptions{
|
|
OutputPath: tmpFn,
|
|
OutputType: transcoder.ScreenshotOutputTypeImage2,
|
|
Quality: options.Quality,
|
|
Width: options.Width,
|
|
}
|
|
|
|
args := transcoder.ScreenshotTime(input, options.Time, ssOptions)
|
|
|
|
return g.generate(lockCtx, args)
|
|
}
|
|
}
|