Generate failing make previews
Have you enabled troubleshooting mode?
- I confirm that the troubleshooting mode is enabled.
Describe the bug
Describe the bug Preview video generation fails for 100% of scenes in a library when using the default "Generate → Previews" task with no explicit per-task preview options — every scene fails instantly and identically, while sprite/cover/phash generation succeeds normally for the same scenes.
The fallback attempt (audio-less retry) fails identically. This reproduces on every scene tested — different codecs, containers, durations, and file sizes — ruling out a per-file issue.
Confirmed workaround (this is the key diagnostic finding)
Calling the metadataGenerate GraphQL mutation directly, with previewOptions.previewSegments / previewOptions.previewSegmentDuration explicitly set to the same values already configured globally, succeeds:
mutation {
metadataGenerate(input: {
previews: true,
previewOptions: { previewSegments: 12, previewSegmentDuration: 0.75 },
sceneIDs: ["<id>"]
})
}This generated a valid, playable preview on a scene that reliably failed via the normal UI-triggered default-options generate task. The only difference between the failing case and the working case is that the segment count/duration were passed explicitly in the mutation rather than left to resolve from saved config defaults. This isolates the bug specifically to how the default (no-override) code path resolves Segments/SegmentDuration from config, not to ffmpeg, the source files, disk, permissions, or concurrency (see "Ruled out," below).
Root cause (from source inspection)
In pkg/scene/generate/preview.go, previewVideo()'s per-segment loop is bounded by options.Segments:
for i := 0; i < options.Segments; i++ {
...
if err := g.previewVideoChunk(...); err != nil {
return err
}
}
concatFilePath, err := g.generateConcatFile(tmpFiles)If options.Segments resolves to 0 at generation time, this loop never executes, tmpFiles stays empty, and generateConcatFile() writes a concat .txt file with zero file '...' entries — a valid-but-empty file. ffmpeg's concat demuxer then correctly rejects it with "Invalid data found when processing input" / exit 183, matching the observed error exactly. I confirmed this directly: the concat .txt file was 0 bytes at creation time (caught with inotifywait mid-run during a failing default-options run).
I also manually reproduced a single segment-cut ffmpeg command outside of Stash (matching Stash's own invocation, using Stash's bundled ffmpeg binary) — it succeeded immediately, proving ffmpeg, the encoder, and the source files are all fine. The defect is entirely upstream of ffmpeg, in the Go code that's supposed to populate the segment count before the concat step ever runs.
In internal/manager/task_generate.go, getGeneratePreviewOptions() is intended to source Segments/SegmentDuration from config.GetPreviewSegments() / config.GetPreviewSegmentDuration() whenever a task provides no per-task override (the default "Generate → Previews" case, and the case that fails). Since passing the same values explicitly through the mutation's previewOptions fixes the issue immediately, the bug is isolated to that config-fallback path specifically — either in GetPreviewSegments()/GetPreviewSegmentDuration() themselves, or in how getGeneratePreviewOptions() consumes them. This may be related to the recent config backend migration from viper to koanf, though I haven't been able to confirm the exact faulty line without access to build/run a local instance with debug instrumentation.
Ruled out during investigation
- Disk space / permissions on the generated/tmp directory
- ffmpeg binary integrity and version (bundled static ffmpeg 6.1; manual single-segment reproduction succeeds)
- Source file corruption (confirmed clean via
ffprobe, correct duration, on multiple affected scenes) - Generate concurrency / race conditions (reproduced identically with
parallel_tasksforced to 1) - Network/CIFS mount issues (separate, unrelated corruption found in a small number of library files during scanning, but does not explain preview failures on confirmed-healthy files)
- Global "Preview generation options" misconfiguration (Number of segments / Segment duration confirmed correctly set and displayed in Settings UI)
Environment
- Stash version: v0.31.1 (build 2026-04-13)
- ffmpeg: bundled static binary, ffmpeg version 6.1-static
- OS: Ubuntu (baremetal), Linux
- Library on a network (CIFS) mount
- Reproduced with default global generate settings (Segments: 12, Segment duration: 0.75)
- Reproduced with generate concurrency (parallel tasks) forced to 1
- Reproduced on multiple unrelated scenes/files, all clean per
ffprobe
This was vibe-debugged with Sonnet 5 with several beers over multiple hours. Since it is a question no plugins have been installed
Steps to reproduce
- Confirm Settings → System → Preview generation options: Number of segments = 12, Segment duration = 0.75 (confirmed correctly saved and displayed in the UI)
- Settings → Tasks → Generate → enable Previews only
- Run Generate, scoped to one or more scenes, using the default task (no explicit per-task preview option overrides)
- Every scene's preview generation fails with the error above
Expected behaviour
Preview generation using the default global settings (no per-task override) should split the source video into the configured number of segments, encode each with ffmpeg, then concatenate them into the final preview clip — exactly as it does when the same values are passed explicitly.
Screenshots or additional context
This affects all default-path preview generation on this instance. The explicit-options GraphQL mutation is a reliable workaround for anyone hitting this in the meantime — worth mentioning in case others find this issue via search.
Stash version
v0.31.1 (build 2026-04-13)
Device details
- OS: Ubuntu (baremetal), Linux
Relevant log output
Warning [generator] Segment duration (0.000000) too short. Using 0.750000 instead.
Info [generator] generating video preview for <file>
Error command stderr: [in#0 @ 0x...] Error opening input: Invalid data found when processing input
Error opening input file <path>/generated/tmp/<random>.txt.
Error opening input files: Invalid data found when processing input
Error error generating preview: error running ffmpeg command <-v error -f concat -i <path>/generated/tmp/<random>.txt -y -c:v copy -c:a copy <path>/generated/tmp/<random>.mp4>: exit status 183
Warning [generator] failed generating scene preview, trying fallbackSource: stashapp/stash