close frame unchecks use capture frame, gif only scales down never up, gif preview updates when settings change

This commit is contained in:
2026-05-29 19:33:40 +03:00
parent cf49e22d61
commit 9e52750a71
3 changed files with 31 additions and 42 deletions
+16 -35
View File
@@ -359,8 +359,8 @@ fn encode_gif(ffmpeg: &Path, req: &TranscodeRequest) -> Result<()> {
let ratio = target as f64 / actual as f64; let ratio = target as f64 / actual as f64;
// Accept if within 15% of target // Accept if at or under target (even if significantly under - don't upscale)
if ratio >= 0.85 && ratio <= 1.15 { if ratio >= 1.0 {
tracing::info!( tracing::info!(
"gif encode done on attempt {}: {} bytes (target {})", "gif encode done on attempt {}: {} bytes (target {})",
attempt + 1, actual, target attempt + 1, actual, target
@@ -368,52 +368,33 @@ fn encode_gif(ffmpeg: &Path, req: &TranscodeRequest) -> Result<()> {
return Ok(()); return Ok(());
} }
// Adjust based on budget priority: // Only adjust DOWN when file is too big
// - Resolution: priority is resolution, so keep it and try to increase it. If file is too // Accept within 15% over target
// small, increase resolution. If too big, decrease fps. if ratio >= 0.85 {
// - Framerate: priority is fps, keep it. If too small, increase fps. If too big, decrease resolution. tracing::info!(
// - Balanced: adjust both. "gif encode done on attempt {}: {} bytes (target {} - close enough)",
attempt + 1, actual, target
);
return Ok(());
}
// File is too big - scale down based on budget priority
match req.gif_budget_mode { match req.gif_budget_mode {
GifBudgetMode::Resolution => { GifBudgetMode::Resolution => {
if ratio > 1.0 { // Reduce fps (resolution is priority, keep it)
// File too small - can grow resolution to fill budget
let factor = ratio.sqrt(); // sqrt because both dims scale
scale_width = ((scale_width as f64 * factor).round() as u32 / 2).max(60).min(1280) * 2;
} else {
// File too big - reduce fps (can't reduce resolution, it's the priority)
effective_fps = ((effective_fps as f64 * ratio).round() as u32).max(1); effective_fps = ((effective_fps as f64 * ratio).round() as u32).max(1);
} }
}
GifBudgetMode::Framerate => { GifBudgetMode::Framerate => {
if ratio > 1.0 { // Reduce resolution (fps is priority, keep it)
// File too small - increase fps to fill budget
let new_fps = ((effective_fps as f64 * ratio).round() as u32).min(req.fps);
if new_fps <= effective_fps {
// FPS maxed out, can grow resolution as fallback
scale_width = ((scale_width as f64 * ratio.sqrt()).round() as u32 / 2).max(60).min(1280) * 2; scale_width = ((scale_width as f64 * ratio.sqrt()).round() as u32 / 2).max(60).min(1280) * 2;
} }
effective_fps = new_fps;
} else {
// File too big - reduce resolution
scale_width = ((scale_width as f64 * ratio.sqrt()).round() as u32 / 2).max(60).min(1280) * 2;
}
}
GifBudgetMode::Balanced => { GifBudgetMode::Balanced => {
// Adjust both - use sqrt for resolution (both dims), linear for fps // Reduce both
if ratio > 1.0 {
// Too small: grow resolution aggressively, fps modestly
let res_factor = ratio.sqrt();
let fps_factor = 1.0 + (ratio - 1.0) * 0.3;
scale_width = ((scale_width as f64 * res_factor).round() as u32 / 2).max(60).min(1280) * 2;
effective_fps = ((effective_fps as f64 * fps_factor).round() as u32).max(1).min(req.fps);
} else {
// Too big: shrink both
let factor = ratio.sqrt(); let factor = ratio.sqrt();
scale_width = ((scale_width as f64 * factor).round() as u32 / 2).max(60).min(1280) * 2; scale_width = ((scale_width as f64 * factor).round() as u32 / 2).max(60).min(1280) * 2;
effective_fps = ((effective_fps as f64 * factor).round() as u32).max(1); effective_fps = ((effective_fps as f64 * factor).round() as u32).max(1);
} }
} }
}
tracing::info!( tracing::info!(
"gif retry {}: was {} bytes (target {}), adjusting to {}x @ {}fps", "gif retry {}: was {} bytes (target {}), adjusting to {}x @ {}fps",
+8 -1
View File
@@ -2,7 +2,7 @@
import { onMount } from "svelte" import { onMount } from "svelte"
import { api, convertFileSrc, formatBytes, type Config, type Format, type GifBudgetMode, type GifDither, type RecordedClip, type ExportResult, type CaptureRect } from "./api" import { api, convertFileSrc, formatBytes, type Config, type Format, type GifBudgetMode, type GifDither, type RecordedClip, type ExportResult, type CaptureRect } from "./api"
import { save } from "@tauri-apps/plugin-dialog" import { save } from "@tauri-apps/plugin-dialog"
import { emit } from "@tauri-apps/api/event" import { emit, listen } from "@tauri-apps/api/event"
type Phase = "idle" | "recording" | "paused" | "editing" | "exporting" | "done" type Phase = "idle" | "recording" | "paused" | "editing" | "exporting" | "done"
@@ -111,8 +111,12 @@
let unlistenHotkey: (() => void) | null = null let unlistenHotkey: (() => void) | null = null
let unlistenProgress: (() => void) | null = null let unlistenProgress: (() => void) | null = null
let unlistenAudio: (() => void) | null = null let unlistenAudio: (() => void) | null = null
let unlistenOverlayClosed: (() => void) | null = null
void (async () => { void (async () => {
unlistenOverlayClosed = await listen("overlay-closed", () => {
useFrame = false
})
config = await api.getConfig() config = await api.getConfig()
format = config.export.default_format format = config.export.default_format
fps = config.capture.default_fps fps = config.capture.default_fps
@@ -139,6 +143,7 @@
unlistenHotkey?.() unlistenHotkey?.()
unlistenProgress?.() unlistenProgress?.()
unlistenAudio?.() unlistenAudio?.()
unlistenOverlayClosed?.()
} }
}) })
@@ -362,6 +367,8 @@
$effect(() => { $effect(() => {
if (phase === "editing" && format) { if (phase === "editing" && format) {
// Read these so the effect re-runs when they change
const _deps = format === "gif" ? `${gifBudgetMode}-${gifDither}-${gifColors}-${fps}-${targetMB}` : `${fps}-${targetMB}`
const timer = window.setTimeout(() => { void refreshPreview() }, 300) const timer = window.setTimeout(() => { void refreshPreview() }, 300)
return () => { clearTimeout(timer) } return () => { clearTimeout(timer) }
} }
+2 -1
View File
@@ -1,7 +1,7 @@
<script lang="ts"> <script lang="ts">
import { onMount } from "svelte" import { onMount } from "svelte"
import { getCurrentWebviewWindow } from "@tauri-apps/api/webviewWindow" import { getCurrentWebviewWindow } from "@tauri-apps/api/webviewWindow"
import { listen } from "@tauri-apps/api/event" import { listen, emit } from "@tauri-apps/api/event"
import { invoke } from "@tauri-apps/api/core" import { invoke } from "@tauri-apps/api/core"
const win = getCurrentWebviewWindow() const win = getCurrentWebviewWindow()
@@ -99,6 +99,7 @@
async function closeOverlay() { async function closeOverlay() {
try { await invoke("hide_overlay") } catch {} try { await invoke("hide_overlay") } catch {}
try { await emit("overlay-closed", {}) } catch {}
} }
</script> </script>