harden gif pipeline, capture, and audio resilience

fix gif calibration (sample deleted before measurement), swap the
budget-mode application so resolution shrinks width not fps, correct the
color factor comment. accumulate gif encode progress across retry
attempts instead of resetting, surface an over-budget result on the done
screen. stream the audio head padding instead of loading it into memory,
detect mid-record audio device loss and offer the existing retry flow,
invalidate the cached encoder list when the ffmpeg binary changes.
add a capture quality setting so 4k screens can record at native res,
try a stream copy before re-encoding when fixing capture timestamps,
park the overlay poll thread when idle, sweep stale config backups, add
a diagnostics tab, and consolidate the preview render debounce.
This commit is contained in:
2026-06-17 23:57:28 +03:00
parent f732cdda4d
commit c3f132507a
9 changed files with 624 additions and 83 deletions
+61 -11
View File
@@ -392,7 +392,15 @@
else if (format !== "gif") thumbnails = []
})
// Single owner of preview rendering. Touches every input that affects the
// preview so one debounced render fires per change-burst - previously the
// debounced effect here and TrimPanel's synchronous onAfterChange could
// both trigger a render for the same change.
$effect(() => {
void phase; void format; void fps; void targetMB
void gifBudgetMode; void gifDither; void gifColors
void trimStart; void trimEnd
void cropEnabled; void cropX; void cropY; void cropW; void cropH
if (phase === "editing" && format) {
const timer = window.setTimeout(() => { void refreshPreview() }, 300)
return () => { clearTimeout(timer) }
@@ -423,6 +431,20 @@
phase === "done" ? "DONE" : ""
)
// Overall encode percent across all passes/attempts. The encoder reports
// per-pass percent (0-100 within one pass); with GIF retrying up to ~12
// times the headline number otherwise jumps back to single digits each
// attempt. Spread each pass's percent across its share of the whole.
let encodeOverall = $derived.by(() => {
if (!encodeProgress) return 0
const { pass, total, pct } = encodeProgress
if (total <= 0) return pct
return ((pass - 1) / total) * 100 + (pct / total)
})
// GIF retry loop calls each pass an "attempt"; two-pass video keeps "pass".
let encodeUnit = $derived(format === "gif" ? "attempt" : "pass")
let phaseColor: string = $derived.by(() => {
const p: string = phase
return p === "recording" ? "var(--recording)" :
@@ -584,12 +606,12 @@
{previewCacheBust}
/>
<!-- Trim timeline -->
<!-- Trim timeline. Preview re-render is driven by the debounced
$effect that watches trimStart/trimEnd, so no onAfterChange. -->
<TrimPanel
{clip}
bind:trimStart
bind:trimEnd
onAfterChange={refreshPreview}
/>
<!-- GIF frames -->
@@ -635,10 +657,10 @@
<div class="exporting">
{#if encodeProgress}
<div class="enc-meta">
<span>Pass {encodeProgress.pass}/{encodeProgress.total}</span>
<span class="mono">{encodeProgress.pct.toFixed(0)}%</span>
<span class="text-cap">{encodeUnit} {encodeProgress.pass}/{encodeProgress.total}</span>
<span class="mono">{encodeOverall.toFixed(0)}%</span>
</div>
<div class="enc-track">
<div class="enc-track" class:multi={encodeProgress.total > 3}>
{#each Array(encodeProgress.total) as _, i}
<div class="enc-segment">
<div
@@ -652,20 +674,33 @@
<div class="enc-meta"><span>Preparing</span></div>
<div class="enc-track"><div class="enc-segment"><div class="enc-fill" style="width:0%"></div></div></div>
{/if}
<p class="enc-hint">ffmpeg is encoding your clip</p>
<p class="enc-hint">ffmpeg is encoding your clip{format === "gif" ? " (retrying to hit target size)" : ""}</p>
<button class="btn-ghost" onclick={cancelExport}>Cancel</button>
</div>
<!-- DONE -->
{:else if phase === "done" && exportResult}
<div class="done">
<div class="done-mark">
<svg width="28" height="28" viewBox="0 0 28 28" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
<circle cx="14" cy="14" r="11"/><polyline points="9,14 13,18 19,11"/>
</svg>
<div class="done-mark" class:warn={!exportResult.met_target}>
{#if exportResult.met_target}
<svg width="28" height="28" viewBox="0 0 28 28" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
<circle cx="14" cy="14" r="11"/><polyline points="9,14 13,18 19,11"/>
</svg>
{:else}
<svg width="28" height="28" viewBox="0 0 28 28" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
<circle cx="14" cy="14" r="11"/><line x1="14" y1="8" x2="14" y2="15"/><circle cx="14" cy="19" r="0.5" fill="currentColor"/>
</svg>
{/if}
</div>
<h2 class="done-title">Exported</h2>
<h2 class="done-title">
{exportResult.met_target ? "Exported" : "Exported (over budget)"}
</h2>
<p class="done-size mono">{formatBytes(exportResult.size_bytes)}</p>
{#if !exportResult.met_target}
<p class="done-caveat">
target {formatBytes(exportResult.target_bytes)} - could not shrink further without wrecking quality
</p>
{/if}
<p class="done-path mono">{exportResult.output_path}</p>
<div class="done-actions">
<button class="btn-primary" onclick={startOver}>Record another</button>
@@ -1117,6 +1152,9 @@
display: flex;
gap: 2px;
}
/* GIF retry renders many thin segments; tighten the gap so they don't read as
a dotted line at 10+ attempts. */
.enc-track.multi { gap: 1px; }
.enc-segment { flex: 1; background: var(--bg-3); overflow: hidden; }
.enc-fill {
height: 100%;
@@ -1124,6 +1162,7 @@
border-radius: 2px;
transition: width 0.4s ease;
}
.text-cap { text-transform: capitalize; }
.enc-hint {
margin: 0;
font-size: 11px;
@@ -1143,6 +1182,17 @@
.done-mark {
color: var(--accent);
}
.done-mark.warn {
color: var(--warn);
}
.done-caveat {
margin: 0;
font-size: 11px;
color: var(--warn);
text-align: center;
max-width: 320px;
line-height: 1.5;
}
.done-title {
margin: 0;
font-size: 18px;