Add timeout and no-stdin for thumbnail jobs

This commit is contained in:
Stu Leak 2026-01-07 16:04:40 -05:00
parent a0bcdd55e2
commit 6dc03201af
2 changed files with 19 additions and 2 deletions

View File

@ -334,6 +334,7 @@ func (g *Generator) generateIndividual(ctx context.Context, config Config, durat
// Build FFmpeg command // Build FFmpeg command
args := []string{ args := []string{
"-ss", fmt.Sprintf("%.2f", ts), "-ss", fmt.Sprintf("%.2f", ts),
"-nostdin",
"-i", config.VideoPath, "-i", config.VideoPath,
"-vf", g.buildThumbFilter(thumbWidth, thumbHeight, config.ShowTimestamp), "-vf", g.buildThumbFilter(thumbWidth, thumbHeight, config.ShowTimestamp),
"-frames:v", "1", "-frames:v", "1",
@ -420,6 +421,7 @@ func (g *Generator) generateContactSheet(ctx context.Context, config Config, dur
// Build FFmpeg command // Build FFmpeg command
args := []string{ args := []string{
"-nostdin",
"-i", config.VideoPath, "-i", config.VideoPath,
"-vf", vfilter, "-vf", vfilter,
"-frames:v", "1", "-frames:v", "1",

View File

@ -6,6 +6,7 @@ import (
"os" "os"
"path/filepath" "path/filepath"
"strings" "strings"
"time"
"fyne.io/fyne/v2" "fyne.io/fyne/v2"
"fyne.io/fyne/v2/container" "fyne.io/fyne/v2/container"
@ -562,6 +563,20 @@ func (s *appState) executeThumbJob(ctx context.Context, job *queue.Job, progress
progressCallback(0) progressCallback(0)
} }
totalThumbs := count
if contactSheet {
totalThumbs = columns * rows
}
perThumb := 20 * time.Second
timeout := time.Duration(totalThumbs) * perThumb
if timeout < 2*time.Minute {
timeout = 2 * time.Minute
} else if timeout > 20*time.Minute {
timeout = 20 * time.Minute
}
jobCtx, cancel := context.WithTimeout(ctx, timeout)
defer cancel()
generator := thumbnail.NewGenerator(utils.GetFFmpegPath()) generator := thumbnail.NewGenerator(utils.GetFFmpegPath())
config := thumbnail.Config{ config := thumbnail.Config{
VideoPath: inputPath, VideoPath: inputPath,
@ -582,7 +597,7 @@ func (s *appState) executeThumbJob(ctx context.Context, job *queue.Job, progress
}, },
} }
result, err := generator.Generate(ctx, config) result, err := generator.Generate(jobCtx, config)
if err != nil { if err != nil {
return fmt.Errorf("thumbnail generation failed: %w", err) return fmt.Errorf("thumbnail generation failed: %w", err)
} }
@ -590,7 +605,7 @@ func (s *appState) executeThumbJob(ctx context.Context, job *queue.Job, progress
logging.Debug(logging.CatSystem, "generated %d thumbnails", len(result.Thumbnails)) logging.Debug(logging.CatSystem, "generated %d thumbnails", len(result.Thumbnails))
if progressCallback != nil { if progressCallback != nil {
progressCallback(1) progressCallback(100)
} }
return nil return nil