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:
+61
-11
@@ -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;
|
||||
|
||||
+83
-2
@@ -1,6 +1,6 @@
|
||||
<script lang="ts">
|
||||
import { onMount } from "svelte"
|
||||
import { api, type Config, type CodecAvailability } from "./api"
|
||||
import { api, type Config, type CodecAvailability, type DiagnosticsInfo } from "./api"
|
||||
import HotkeyInput from "./HotkeyInput.svelte"
|
||||
import { open } from "@tauri-apps/plugin-dialog"
|
||||
|
||||
@@ -20,6 +20,7 @@
|
||||
|| cfg.capture.default_fps !== initialCfg.capture.default_fps
|
||||
|| cfg.capture.capture_cursor !== initialCfg.capture.capture_cursor
|
||||
|| cfg.capture.capture_audio !== initialCfg.capture.capture_audio
|
||||
|| cfg.capture.capture_quality !== initialCfg.capture.capture_quality
|
||||
|| cfg.export.default_format !== initialCfg.export.default_format
|
||||
|| cfg.export.gif_dither !== initialCfg.export.gif_dither
|
||||
|| cfg.export.webm_codec !== initialCfg.export.webm_codec
|
||||
@@ -31,12 +32,15 @@
|
||||
|| cfg.output_dir !== initialCfg.output_dir
|
||||
})
|
||||
|
||||
let diagnostics: DiagnosticsInfo | null = $state(null)
|
||||
|
||||
const TABS = [
|
||||
{ id: "capture", label: "Capture" },
|
||||
{ id: "export", label: "Export" },
|
||||
{ id: "hotkeys", label: "Hotkeys" },
|
||||
{ id: "output", label: "Output" },
|
||||
{ id: "system", label: "System" },
|
||||
{ id: "diagnostics", label: "Diagnostics" },
|
||||
]
|
||||
|
||||
onMount(async () => {
|
||||
@@ -49,6 +53,15 @@
|
||||
if (cfg) document.documentElement.setAttribute("data-theme", cfg.theme)
|
||||
})
|
||||
|
||||
$effect(() => {
|
||||
if (activeTab !== "diagnostics") return
|
||||
api.diagnosticsInfo().then(d => { diagnostics = d }).catch(() => { diagnostics = null })
|
||||
})
|
||||
|
||||
async function refreshDiagnostics() {
|
||||
try { diagnostics = await api.diagnosticsInfo() } catch { diagnostics = null }
|
||||
}
|
||||
|
||||
async function save() {
|
||||
if (!cfg) return
|
||||
|
||||
@@ -124,6 +137,13 @@
|
||||
{#each [15,24,30,60] as f}<option value={f}>{f} fps</option>{/each}
|
||||
</select>
|
||||
</label>
|
||||
<label class="field">
|
||||
<span class="field-label">Capture quality</span>
|
||||
<select bind:value={cfg.capture.capture_quality}>
|
||||
<option value="auto">Auto (cap 1920px, lower CPU)</option>
|
||||
<option value="full">Full (native res up to 3840px)</option>
|
||||
</select>
|
||||
</label>
|
||||
<label class="field-check">
|
||||
<input type="checkbox" bind:checked={cfg.capture.capture_cursor} />
|
||||
<span>Capture cursor</span>
|
||||
@@ -247,6 +267,36 @@
|
||||
</label>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{:else if activeTab === "diagnostics"}
|
||||
<div class="tab-panel">
|
||||
<div class="panel-head">
|
||||
<h2>Diagnostics</h2>
|
||||
<p class="panel-desc">Versions and recent log output</p>
|
||||
</div>
|
||||
<div class="field-list">
|
||||
<div class="diag-row">
|
||||
<span class="field-label">ByteSize</span>
|
||||
<span class="diag-val mono">{diagnostics ? `v${diagnostics.app_version}` : "..."}</span>
|
||||
</div>
|
||||
<div class="diag-row">
|
||||
<span class="field-label">ffmpeg</span>
|
||||
<span class="diag-val mono">{diagnostics ? diagnostics.ffmpeg_version : "..."}</span>
|
||||
</div>
|
||||
<div class="diag-row">
|
||||
<span class="field-label">Log folder</span>
|
||||
<span class="diag-val mono">{diagnostics ? diagnostics.log_dir : "..."}</span>
|
||||
<button class="btn-ghost compact" onclick={() => api.openLogDir()} disabled={!diagnostics}>Open</button>
|
||||
</div>
|
||||
<div class="diag-tail-wrap">
|
||||
<div class="diag-tail-head">
|
||||
<span class="field-label">Recent log</span>
|
||||
<button class="link" onclick={refreshDiagnostics}>Refresh</button>
|
||||
</div>
|
||||
<pre class="diag-tail">{diagnostics ? diagnostics.log_tail || "(empty)" : "loading..."}</pre>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{/if}
|
||||
|
||||
{#if hotkeyWarnings.length > 0}
|
||||
@@ -257,7 +307,7 @@
|
||||
<button class="btn-ghost" onclick={onClose}>Cancel</button>
|
||||
</div>
|
||||
</div>
|
||||
{:else}
|
||||
{:else if activeTab !== "diagnostics"}
|
||||
<div class="panel-foot">
|
||||
<button class="btn-primary" onclick={save} disabled={saving}>
|
||||
{saving ? "Saving" : "Save changes"}
|
||||
@@ -265,6 +315,10 @@
|
||||
{#if dirty}<span class="unsaved-dot" title="unsaved changes"></span>{/if}
|
||||
<button class="btn-ghost" onclick={onClose}>Cancel</button>
|
||||
</div>
|
||||
{:else}
|
||||
<div class="panel-foot">
|
||||
<button class="btn-ghost" onclick={onClose}>Close</button>
|
||||
</div>
|
||||
{/if}
|
||||
</div>
|
||||
</div>
|
||||
@@ -528,4 +582,31 @@
|
||||
margin-left: 8px;
|
||||
vertical-align: middle;
|
||||
}
|
||||
|
||||
/* ---- Diagnostics ---- */
|
||||
.diag-row {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 10px;
|
||||
}
|
||||
.diag-row .field-label { flex-shrink: 0; width: 90px; }
|
||||
.diag-val { font-size: 12px; color: var(--text-2); flex: 1; min-width: 0; word-break: break-all; }
|
||||
.btn-ghost.compact { padding: 5px 12px; font-size: 12px; }
|
||||
.diag-tail-wrap { display: flex; flex-direction: column; gap: 6px; margin-top: 4px; }
|
||||
.diag-tail-head { display: flex; align-items: center; justify-content: space-between; }
|
||||
.diag-tail {
|
||||
margin: 0;
|
||||
padding: 10px;
|
||||
background: var(--bg-3);
|
||||
border: 1px solid var(--border);
|
||||
border-radius: var(--r-sm);
|
||||
font-family: var(--mono);
|
||||
font-size: 10px;
|
||||
line-height: 1.5;
|
||||
color: var(--text-3);
|
||||
max-height: 220px;
|
||||
overflow: auto;
|
||||
white-space: pre-wrap;
|
||||
word-break: break-all;
|
||||
}
|
||||
</style>
|
||||
|
||||
@@ -6,12 +6,12 @@
|
||||
clip,
|
||||
trimStart = $bindable(),
|
||||
trimEnd = $bindable(),
|
||||
onAfterChange,
|
||||
onAfterChange = () => {},
|
||||
}: {
|
||||
clip: { temp_path: string; duration_secs: number; width: number; height: number }
|
||||
trimStart: number
|
||||
trimEnd: number
|
||||
onAfterChange: () => void
|
||||
onAfterChange?: () => void
|
||||
} = $props()
|
||||
|
||||
let trackEl: HTMLDivElement | null = $state(null)
|
||||
|
||||
@@ -23,10 +23,13 @@ export type ExportConfig = {
|
||||
mp4_codec: Mp4Codec
|
||||
}
|
||||
|
||||
export type CaptureQuality = "auto" | "full"
|
||||
|
||||
export type CaptureConfig = {
|
||||
default_fps: number
|
||||
capture_cursor: boolean
|
||||
capture_audio: boolean
|
||||
capture_quality: CaptureQuality
|
||||
}
|
||||
|
||||
export type HotkeyConfig = {
|
||||
@@ -124,6 +127,8 @@ export type ExportRequest = {
|
||||
export type ExportResult = {
|
||||
output_path: string
|
||||
size_bytes: number
|
||||
target_bytes: number
|
||||
met_target: boolean
|
||||
}
|
||||
|
||||
export type HotkeyRegistrationResult = {
|
||||
@@ -167,6 +172,13 @@ export type CodecAvailability = {
|
||||
av1: boolean
|
||||
}
|
||||
|
||||
export type DiagnosticsInfo = {
|
||||
app_version: string
|
||||
ffmpeg_version: string
|
||||
log_dir: string
|
||||
log_tail: string
|
||||
}
|
||||
|
||||
export type AudioFailed = string
|
||||
|
||||
export const api = {
|
||||
@@ -245,6 +257,8 @@ export const api = {
|
||||
listen<string>("audio-failed", (e) => handler(e.payload)),
|
||||
cancelExport: () => invoke<void>("cancel_export"),
|
||||
codecAvailability: () => invoke<CodecAvailability>("codec_availability"),
|
||||
diagnosticsInfo: () => invoke<DiagnosticsInfo>("diagnostics_info"),
|
||||
openLogDir: () => invoke<void>("open_log_dir"),
|
||||
}
|
||||
|
||||
export function formatBytes(n: number): string {
|
||||
|
||||
Reference in New Issue
Block a user