keep temp clean and previews alive across a capture

This commit is contained in:
2026-09-21 01:04:22 +03:00
parent 03b2fec744
commit 1ace31fc6e
3 changed files with 75 additions and 11 deletions
+9 -2
View File
@@ -874,8 +874,15 @@ pub(crate) fn render_gif_preview(
let sample_start = (midpoint_secs - 1.0).max(0.0);
let sample_dur = duration_secs.min(2.0);
let palette_key = palette_cache_key(gif_colors, target_width, sample_start, sample_dur);
let palette_path = out_path.parent().unwrap_or(input.parent().unwrap())
.join(format!("preview-palette-{palette_key}.png"));
// The preview and its input both live in the scratch dir, so the preview's
// parent is the normal case. Fall back to the input's parent rather than
// panicking on a bare filename.
let palette_dir = out_path
.parent()
.filter(|p| !p.as_os_str().is_empty())
.or_else(|| input.parent().filter(|p| !p.as_os_str().is_empty()))
.context("preview palette has no parent directory")?;
let palette_path = palette_dir.join(format!("preview-palette-{palette_key}.png"));
let need_regen = !palette_path.is_file();
if need_regen {