From 3a631c0c24de3c2384217f739c613c02b3cb6147 Mon Sep 17 00:00:00 2001 From: lashman Date: Wed, 27 May 2026 21:12:00 +0300 Subject: [PATCH] fix aspect ratio lock (send event before resize, enforce on lock), fix gif size estimate (0.5 -> 0.2 bytes/pixel for screen content) --- src-tauri/src/encode.rs | 5 ++++- src/lib/Main.svelte | 4 ++-- src/lib/Overlay.svelte | 15 ++++++++++++++- 3 files changed, 20 insertions(+), 4 deletions(-) diff --git a/src-tauri/src/encode.rs b/src-tauri/src/encode.rs index f777eb2..dbf4d60 100644 --- a/src-tauri/src/encode.rs +++ b/src-tauri/src/encode.rs @@ -417,7 +417,10 @@ fn encode_gif(ffmpeg: &Path, req: &TranscodeRequest) -> Result<()> { pub fn gif_params(req: &TranscodeRequest, clip_width: u32, clip_height: u32) -> (u32, u32) { let aspect = if clip_height > 0 { clip_width as f64 / clip_height as f64 } else { 16.0 / 9.0 }; - let bytes_per_pixel_per_frame = 0.5_f64; + // GIF LZW compression on typical screen content averages ~0.2 bytes/pixel. + // The 0.5 constant was causing massive under-estimation (files at half target size). + // This is inherently approximate - complex content compresses worse, flat UI compresses better. + let bytes_per_pixel_per_frame = 0.2_f64; let target_bytes = req.target_bytes as f64; let requested_fps = req.fps as f64; let duration = req.duration_secs; diff --git a/src/lib/Main.svelte b/src/lib/Main.svelte index bf1d197..16559b2 100644 --- a/src/lib/Main.svelte +++ b/src/lib/Main.svelte @@ -69,7 +69,7 @@ let previewDims = $derived.by(() => { if (!clip) return "" if (format === "gif") { - const bpf = 0.5 + const bpf = 0.2 const requestedFps = fps const aspect = clip.height === 0 ? 16 / 9 : clip.width / clip.height @@ -439,9 +439,9 @@
{#each PRESETS as [w, h, label]} {/each} {#if aspectLock !== null} diff --git a/src/lib/Overlay.svelte b/src/lib/Overlay.svelte index ce1dfb0..583ed7a 100644 --- a/src/lib/Overlay.svelte +++ b/src/lib/Overlay.svelte @@ -44,8 +44,21 @@ }, 150) }).then(fn => cleanup.push(fn)) - listen<{ ratio: number | null }>("overlay-aspect-lock", (e) => { + listen<{ ratio: number | null }>("overlay-aspect-lock", async (e) => { lockedRatio = e.payload.ratio + if (lockedRatio !== null) { + // Enforce ratio on current size immediately + await updateSize() + const targetH = Math.round(width / lockedRatio) + const minH = 90 + const clampedH = Math.max(minH, targetH) + if (Math.abs(clampedH - height) > 1) { + try { + await win.setSize({ type: "Logical", width, height: clampedH }) + await updateSize() + } catch {} + } + } }).then(fn => cleanup.push(fn)) listen<{ phase: "idle"|"recording"|"paused"; fps: number }>(