fps selector on idle screen, lower gif fps minimum, 16:9 preset, aspect ratio lock on frame resize, gif budget mode (resolution/framerate/balanced priority), fix asset protocol scope

This commit is contained in:
2026-05-27 19:35:40 +03:00
parent e4141f8be8
commit 2b3f7e433c
7 changed files with 220 additions and 41 deletions
+9
View File
@@ -63,6 +63,15 @@ pub enum Format {
Mp4, Mp4,
} }
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize, Default)]
#[serde(rename_all = "lowercase")]
pub enum GifBudgetMode {
#[default]
Balanced,
Resolution,
Framerate,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize, Default)] #[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize, Default)]
#[serde(rename_all = "snake_case")] #[serde(rename_all = "snake_case")]
pub enum GifDither { pub enum GifDither {
+47 -11
View File
@@ -8,7 +8,7 @@ use std::thread;
use anyhow::{anyhow, bail, Context, Result}; use anyhow::{anyhow, bail, Context, Result};
use crate::clicks::Click; use crate::clicks::Click;
use crate::config::{Format, GifDither, Mp4Codec, WebmCodec}; use crate::config::{Format, GifBudgetMode, GifDither, Mp4Codec, WebmCodec};
use crate::CaptureRect; use crate::CaptureRect;
// Used both for bitrate budget calculation and final mux. Must be consistent. // Used both for bitrate budget calculation and final mux. Must be consistent.
@@ -39,6 +39,7 @@ pub struct TranscodeRequest {
pub mp4_codec: Mp4Codec, pub mp4_codec: Mp4Codec,
pub scratch_dir: PathBuf, pub scratch_dir: PathBuf,
pub crop: Option<CaptureRect>, pub crop: Option<CaptureRect>,
pub gif_budget_mode: GifBudgetMode,
pub deleted_frame_indices: Vec<u32>, pub deleted_frame_indices: Vec<u32>,
pub trim_start_secs: Option<f64>, pub trim_start_secs: Option<f64>,
pub trim_end_secs: Option<f64>, pub trim_end_secs: Option<f64>,
@@ -341,7 +342,7 @@ fn cleanup_pass_logs(stem: &Path) {
fn encode_gif(ffmpeg: &Path, req: &TranscodeRequest) -> Result<()> { fn encode_gif(ffmpeg: &Path, req: &TranscodeRequest) -> Result<()> {
let palette_path = req.scratch_dir.join("palette.png"); let palette_path = req.scratch_dir.join("palette.png");
let scale_width = estimate_gif_scale_width(req, req.clip_width, req.clip_height); let (scale_width, effective_fps) = gif_params(req, req.clip_width, req.clip_height);
let crop_prefix = crop_filter(req.crop) let crop_prefix = crop_filter(req.crop)
.map(|c| format!("{c},")) .map(|c| format!("{c},"))
.unwrap_or_default(); .unwrap_or_default();
@@ -356,7 +357,7 @@ fn encode_gif(ffmpeg: &Path, req: &TranscodeRequest) -> Result<()> {
cprefix = crop_prefix, cprefix = crop_prefix,
kprefix = click_prefix, kprefix = click_prefix,
sprefix = select_prefix, sprefix = select_prefix,
fps = req.fps, fps = effective_fps,
w = scale_width, w = scale_width,
); );
@@ -380,7 +381,7 @@ fn encode_gif(ffmpeg: &Path, req: &TranscodeRequest) -> Result<()> {
cprefix = crop_prefix, cprefix = crop_prefix,
kprefix = click_prefix, kprefix = click_prefix,
sprefix = select_prefix, sprefix = select_prefix,
fps = req.fps, fps = effective_fps,
w = scale_width, w = scale_width,
d = dither, d = dither,
); );
@@ -404,7 +405,7 @@ fn encode_gif(ffmpeg: &Path, req: &TranscodeRequest) -> Result<()> {
1, 1,
1, 1,
req.duration_secs, req.duration_secs,
req.fps, effective_fps,
req.progress_tx.as_ref(), req.progress_tx.as_ref(),
)?; )?;
@@ -412,14 +413,48 @@ fn encode_gif(ffmpeg: &Path, req: &TranscodeRequest) -> Result<()> {
Ok(()) Ok(())
} }
fn estimate_gif_scale_width(req: &TranscodeRequest, clip_width: u32, clip_height: u32) -> u32 { pub fn gif_params(req: &TranscodeRequest, clip_width: u32, clip_height: u32) -> (u32, u32) {
let bytes_per_pixel_per_frame = 0.5_f64;
let frames = (req.fps as f64 * req.duration_secs).max(1.0);
let budget = req.target_bytes as f64 / (frames * bytes_per_pixel_per_frame);
let aspect = if clip_height > 0 { clip_width as f64 / clip_height as f64 } else { 16.0 / 9.0 }; 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;
let target_bytes = req.target_bytes as f64;
let requested_fps = req.fps as f64;
let duration = req.duration_secs;
match req.gif_budget_mode {
GifBudgetMode::Resolution => {
let max_w = (clip_width.min(1280) as f64).clamp(120.0, 1280.0);
let w = (max_w / 2.0).round() as u32 * 2;
let h = (w as f64 / aspect).round() as u32;
let pixels_per_frame = w as f64 * h as f64;
let bytes_per_frame = pixels_per_frame * bytes_per_pixel_per_frame;
let max_frames = (target_bytes / bytes_per_frame).floor().max(1.0);
let min_fps = (max_frames / duration).max(1.0).round() as u32;
let fps = (req.fps).min(min_fps).max(1);
(w, fps)
}
GifBudgetMode::Framerate => {
let frames = (requested_fps * duration).max(1.0);
let budget = target_bytes / (frames * bytes_per_pixel_per_frame);
let w = (budget * aspect).sqrt(); let w = (budget * aspect).sqrt();
let w = w.clamp(120.0, 1280.0).round() as u32; let w = (w.clamp(120.0, 1280.0).round() as u32 / 2) * 2;
(w / 2) * 2 (w, req.fps)
}
GifBudgetMode::Balanced => {
let frames_at_full = (requested_fps * duration).max(1.0);
let budget_at_full = target_bytes / (frames_at_full * bytes_per_pixel_per_frame);
let w_at_full = (budget_at_full * aspect).sqrt().clamp(120.0, 1280.0);
let scale = if w_at_full < clip_width as f64 {
(w_at_full / clip_width as f64).sqrt()
} else {
1.0
};
let w = ((clip_width as f64 * scale).round() as u32 / 2).max(60) * 2;
let fps = ((requested_fps * scale).round() as u32).max(1).min(req.fps);
(w, fps)
}
}
} }
pub fn render_preview( pub fn render_preview(
@@ -713,6 +748,7 @@ mod tests {
mp4_codec: Mp4Codec::H264, mp4_codec: Mp4Codec::H264,
scratch_dir: PathBuf::new(), scratch_dir: PathBuf::new(),
crop: None, crop: None,
gif_budget_mode: GifBudgetMode::Balanced,
deleted_frame_indices: vec![], deleted_frame_indices: vec![],
trim_start_secs: None, trim_start_secs: None,
trim_end_secs: None, trim_end_secs: None,
+33 -13
View File
@@ -19,7 +19,7 @@ use tauri_plugin_global_shortcut::{GlobalShortcutExt, Shortcut, ShortcutState};
use std::str::FromStr; use std::str::FromStr;
use crate::bootstrap::FfmpegStatus; use crate::bootstrap::FfmpegStatus;
use crate::config::{Config, Format}; use crate::config::{Config, Format, GifBudgetMode, GifDither, Mp4Codec, WebmCodec};
fn lock<T>(m: &std::sync::Mutex<T>) -> std::sync::MutexGuard<'_, T> { fn lock<T>(m: &std::sync::Mutex<T>) -> std::sync::MutexGuard<'_, T> {
m.lock().unwrap_or_else(|e| e.into_inner()) m.lock().unwrap_or_else(|e| e.into_inner())
@@ -264,6 +264,7 @@ async fn download_ffmpeg(app: AppHandle, state: State<'_, AppState>) -> Result<(
#[derive(Debug, Deserialize)] #[derive(Debug, Deserialize)]
pub struct StartCaptureRequest { pub struct StartCaptureRequest {
pub crop: Option<CaptureRect>, pub crop: Option<CaptureRect>,
pub fps: Option<u32>,
} }
fn segment_path(app_dir: &Path, idx: usize) -> PathBuf { fn segment_path(app_dir: &Path, idx: usize) -> PathBuf {
@@ -340,7 +341,8 @@ fn start_capture(
std::fs::create_dir_all(&temp).map_err(|e| format!("creating temp dir: {e}"))?; std::fs::create_dir_all(&temp).map_err(|e| format!("creating temp dir: {e}"))?;
clear_temp_segments(&state.app_dir); clear_temp_segments(&state.app_dir);
let crop = request.and_then(|r| r.crop); let crop = request.as_ref().and_then(|r| r.crop);
let fps = request.as_ref().and_then(|r| r.fps).unwrap_or(cfg.capture.default_fps);
let output = segment_path(&state.app_dir, 1); let output = segment_path(&state.app_dir, 1);
let ffmpeg = bootstrap::ffmpeg_path(&state.app_dir); let ffmpeg = bootstrap::ffmpeg_path(&state.app_dir);
@@ -357,7 +359,7 @@ fn start_capture(
cfg.capture.capture_cursor, cfg.capture.capture_cursor,
cfg.capture.capture_audio, cfg.capture.capture_audio,
crop, crop,
cfg.capture.default_fps, fps,
) )
.map_err(|e| format!("{e:#}"))?; .map_err(|e| format!("{e:#}"))?;
@@ -640,6 +642,8 @@ pub struct ExportRequest {
pub output_path: Option<String>, pub output_path: Option<String>,
#[serde(default)] #[serde(default)]
pub crop: Option<CaptureRect>, pub crop: Option<CaptureRect>,
#[serde(default)]
pub gif_budget_mode: GifBudgetMode,
} }
#[tauri::command] #[tauri::command]
@@ -660,6 +664,8 @@ pub struct PreviewRequest {
pub format: Format, pub format: Format,
pub fps: u32, pub fps: u32,
pub target_bytes: u64, pub target_bytes: u64,
#[serde(default)]
pub gif_budget_mode: GifBudgetMode,
} }
#[tauri::command] #[tauri::command]
@@ -676,18 +682,31 @@ fn render_preview(
} }
let target_width: u32 = if request.format == Format::Gif { let target_width: u32 = if request.format == Format::Gif {
// For GIF, derive a width that fits the target byte budget. let req = encode::TranscodeRequest {
let frames = (request.fps as f64 * clip.duration_secs).max(1.0); input: clip.temp_path.clone(),
let budget = (request.target_bytes as f64) / (frames * 0.5); output: PathBuf::new(),
let aspect = if clip.height == 0 { format: request.format,
16.0 / 9.0 target_bytes: request.target_bytes,
} else { duration_secs: clip.duration_secs,
clip.width as f64 / clip.height as f64 fps: request.fps,
keep_audio: false,
gif_dither: GifDither::FloydSteinberg,
webm_codec: WebmCodec::Vp9,
mp4_codec: Mp4Codec::H264,
scratch_dir: PathBuf::new(),
crop: None,
gif_budget_mode: request.gif_budget_mode,
deleted_frame_indices: vec![],
trim_start_secs: None,
trim_end_secs: None,
clicks: vec![],
clip_width: clip.width,
clip_height: clip.height,
progress_tx: None,
}; };
let w = (budget * aspect).sqrt(); let (w, _) = encode::gif_params(&req, clip.width, clip.height);
(w.clamp(120.0, clip.width as f64) as u32 / 2) * 2 w
} else { } else {
// For video formats, scale to a reasonable preview size.
clip.width.min(1280).max(160) clip.width.min(1280).max(160)
}; };
@@ -1272,6 +1291,7 @@ fn export(app: AppHandle, state: State<'_, AppState>, request: ExportRequest) ->
mp4_codec: cfg.export.mp4_codec, mp4_codec: cfg.export.mp4_codec,
scratch_dir: temp_dir(&state.app_dir), scratch_dir: temp_dir(&state.app_dir),
crop: request.crop, crop: request.crop,
gif_budget_mode: request.gif_budget_mode,
deleted_frame_indices: request.deleted_frame_indices, deleted_frame_indices: request.deleted_frame_indices,
trim_start_secs: trim_start, trim_start_secs: trim_start,
trim_end_secs: trim_end, trim_end_secs: trim_end,
+1 -1
View File
@@ -56,7 +56,7 @@
"csp": null, "csp": null,
"assetProtocol": { "assetProtocol": {
"enable": true, "enable": true,
"scope": ["$APPDIR/**", "$TEMP/**"] "scope": ["$APPDIR/**/*", "$RESOURCE/**/*"]
} }
} }
}, },
+92 -7
View File
@@ -1,6 +1,6 @@
<script lang="ts"> <script lang="ts">
import { onMount } from "svelte" import { onMount } from "svelte"
import { api, convertFileSrc, formatBytes, type Config, type Format, type RecordedClip, type ExportResult, type CaptureRect } from "./api" import { api, convertFileSrc, formatBytes, type Config, type Format, type GifBudgetMode, 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 } from "@tauri-apps/api/event"
@@ -24,6 +24,8 @@
let outputPath: string = $state("") let outputPath: string = $state("")
let pathOverridden: boolean = $state(false) let pathOverridden: boolean = $state(false)
let gifBudgetMode: GifBudgetMode = $state("balanced")
// Post-record crop // Post-record crop
let cropEnabled: boolean = $state(false) let cropEnabled: boolean = $state(false)
let cropX: number = $state(0) let cropX: number = $state(0)
@@ -50,10 +52,12 @@
let previewTimer: number | null = null let previewTimer: number | null = null
let thumbCache: Map<string, string[]> = $state(new Map()) let thumbCache: Map<string, string[]> = $state(new Map())
let showDiscardConfirm: boolean = $state(false) let showDiscardConfirm: boolean = $state(false)
let aspectLock: number | null = $state(null)
const PRESETS: [number, number, string][] = [ const PRESETS: [number, number, string][] = [
[1280, 720, "720p"], [1280, 720, "720p"],
[1920, 1080, "1080p"], [1920, 1080, "1080p"],
[960, 540, "16:9"],
[800, 800, "1:1"], [800, 800, "1:1"],
[540, 960, "9:16"], [540, 960, "9:16"],
] ]
@@ -64,13 +68,38 @@
if (!clip) return "" if (!clip) return ""
if (format === "gif") { if (format === "gif") {
const bpf = 0.5 const bpf = 0.5
const frames = Math.max(1, fps * trimmedDuration) const requestedFps = fps
const budget = (targetMB * 1_048_576) / (frames * bpf)
const aspect = clip.height === 0 ? 16 / 9 : clip.width / clip.height const aspect = clip.height === 0 ? 16 / 9 : clip.width / clip.height
if (gifBudgetMode === "resolution") {
const maxW = Math.min(clip.width, 1280)
const w = Math.max(120, maxW)
const h = Math.round(w / aspect)
const pixelsPerFrame = w * h
const bytesPerFrame = pixelsPerFrame * bpf
const maxFrames = Math.max(1, Math.floor((targetMB * 1_048_576) / bytesPerFrame))
const minFps = Math.max(1, Math.round(maxFrames / trimmedDuration))
const effectiveFps = Math.max(1, Math.min(requestedFps, minFps))
const w2 = w & ~1
const h2 = Math.round(w2 / aspect) & ~1
return `${w2}x${h2} @ ${effectiveFps}fps`
} else if (gifBudgetMode === "framerate") {
const frames = Math.max(1, requestedFps * trimmedDuration)
const budget = (targetMB * 1_048_576) / (frames * bpf)
const w = Math.sqrt(budget * aspect) const w = Math.sqrt(budget * aspect)
const w2 = Math.min(clip.width, Math.max(120, Math.round(w))) & ~1 const w2 = Math.min(clip.width, Math.max(120, Math.round(w))) & ~1
const h2 = Math.round(w2 / aspect) & ~1 const h2 = Math.round(w2 / aspect) & ~1
return `${w2}x${h2}` return `${w2}x${h2}`
} else {
const framesAtFull = Math.max(1, requestedFps * trimmedDuration)
const budgetAtFull = (targetMB * 1_048_576) / (framesAtFull * bpf)
const wAtFull = Math.sqrt(budgetAtFull * aspect)
const scale = wAtFull < clip.width ? Math.sqrt(wAtFull / clip.width) : 1
const w2 = Math.max(60, Math.round(clip.width * scale)) & ~1
const h2 = Math.round(w2 / aspect) & ~1
const effectiveFps = Math.max(1, Math.min(requestedFps, Math.round(requestedFps * scale)))
return `${w2}x${h2} @ ${effectiveFps}fps`
}
} }
return `${clip.width}x${clip.height}` return `${clip.width}x${clip.height}`
}) })
@@ -125,7 +154,7 @@
try { crop = await api.getOverlayRect() } catch (e) { errMsg = String(e); return } try { crop = await api.getOverlayRect() } catch (e) { errMsg = String(e); return }
} }
try { try {
await api.startCapture({ crop }) await api.startCapture({ crop, fps })
phase = "recording" phase = "recording"
tick() tick()
void emit("recording-state", { phase: "recording", fps }) void emit("recording-state", { phase: "recording", fps })
@@ -176,7 +205,7 @@
if (!clip) return if (!clip) return
previewLoading = true previewLoading = true
try { try {
previewPath = await api.renderPreview(format, fps, Math.round(targetMB * 1_048_576)) previewPath = await api.renderPreview(format, fps, Math.round(targetMB * 1_048_576), format === "gif" ? gifBudgetMode : undefined)
previewCacheBust = Date.now() previewCacheBust = Date.now()
} catch { previewPath = null } } catch { previewPath = null }
finally { previewLoading = false } finally { previewLoading = false }
@@ -219,6 +248,7 @@
trim_start_secs: tsStart, trim_end_secs: tsEnd, trim_start_secs: tsStart, trim_end_secs: tsEnd,
output_path: outputPath.trim() || null, output_path: outputPath.trim() || null,
crop, crop,
gif_budget_mode: format === "gif" ? gifBudgetMode : undefined,
}) })
exportResult = result; phase = "done" exportResult = result; phase = "done"
} catch (e) { errMsg = String(e); phase = "editing" } } catch (e) { errMsg = String(e); phase = "editing" }
@@ -403,10 +433,27 @@
{#if useFrame} {#if useFrame}
<div class="preset-row"> <div class="preset-row">
{#each PRESETS as [w, h, label]} {#each PRESETS as [w, h, label]}
<button class="chip" onclick={() => api.setOverlaySize(w, h)}>{label}</button> <button class="chip" onclick={() => {
api.setOverlaySize(w, h)
aspectLock = w / h
emit("overlay-aspect-lock", { ratio: aspectLock })
}}>{label}</button>
{/each} {/each}
{#if aspectLock !== null}
<button class="chip unlock" onclick={() => {
aspectLock = null
emit("overlay-aspect-lock", { ratio: null })
}}>Unlock</button>
{/if}
</div> </div>
{/if} {/if}
<div class="idle-fps">
<span class="switch-label">Capture FPS</span>
<select bind:value={fps}>
{#each [1, 2, 5, 10, 15, 24, 30, 60] as f}<option value={f}>{f}</option>{/each}
</select>
</div>
</div> </div>
</div> </div>
@@ -587,12 +634,32 @@
<p class="estimate">{previewDims} &middot; {fps}fps &middot; {trimmedDuration.toFixed(1)}s</p> <p class="estimate">{previewDims} &middot; {fps}fps &middot; {trimmedDuration.toFixed(1)}s</p>
</div> </div>
{#if format === "gif"}
<div class="control-group">
<span class="section-title">Budget priority</span>
<div class="fmt-bar">
{#each (["resolution", "framerate", "balanced"] as const) as m}
<button
class="fmt-chip"
class:active={gifBudgetMode === m}
onclick={() => { gifBudgetMode = m }}
>{m === "resolution" ? "Resolution" : m === "framerate" ? "Framerate" : "Balanced"}</button>
{/each}
</div>
<p class="estimate">
{gifBudgetMode === "resolution" ? "Keeps resolution high, may reduce FPS" :
gifBudgetMode === "framerate" ? "Keeps FPS high, may reduce resolution" :
"Balances resolution and FPS"}
</p>
</div>
{/if}
<!-- FPS + Audio --> <!-- FPS + Audio -->
<div class="control-row"> <div class="control-row">
<label class="control"> <label class="control">
<span class="control-label">FPS</span> <span class="control-label">FPS</span>
<select bind:value={fps} onchange={refreshPreview}> <select bind:value={fps} onchange={refreshPreview}>
{#each [15,24,30,60] as f}<option value={f}>{f}</option>{/each} {#each [1, 2, 5, 10, 15, 24, 30, 60] as f}<option value={f}>{f}</option>{/each}
</select> </select>
</label> </label>
{#if format !== "gif"} {#if format !== "gif"}
@@ -866,6 +933,16 @@
} }
.switch.on .switch-knob { transform: translateX(16px); background: var(--accent-text); } .switch.on .switch-knob { transform: translateX(16px); background: var(--accent-text); }
.idle-fps {
display: flex;
justify-content: space-between;
align-items: center;
padding: 10px 14px;
background: var(--bg-2);
border: 1px solid var(--border);
border-radius: var(--r-sm);
}
.preset-row { .preset-row {
display: flex; display: flex;
gap: 6px; gap: 6px;
@@ -884,6 +961,14 @@
transition: border-color 80ms, color 80ms; transition: border-color 80ms, color 80ms;
} }
.chip:hover { border-color: var(--accent); color: var(--accent); } .chip:hover { border-color: var(--accent); color: var(--accent); }
.chip.unlock {
border-color: var(--warn);
color: var(--warn);
}
.chip.unlock:hover {
background: var(--warn);
color: var(--bg);
}
/* ---- Recording ---- */ /* ---- Recording ---- */
.recording { .recording {
+28 -2
View File
@@ -13,6 +13,8 @@
let fps: number = $state(30) let fps: number = $state(30)
let elapsed: number = $state(0) let elapsed: number = $state(0)
let timer: number | null = null let timer: number | null = null
let lockedRatio: number | null = null
let resizeDebounce: number | null = null
onMount(() => { onMount(() => {
const updateSize = async () => { const updateSize = async () => {
@@ -24,7 +26,27 @@
updateSize() updateSize()
let cleanup: (() => void)[] = [] let cleanup: (() => void)[] = []
win.onResized(updateSize).then(fn => cleanup.push(fn)) win.onResized(async () => {
await updateSize()
if (lockedRatio === null) return
if (resizeDebounce !== null) clearTimeout(resizeDebounce)
resizeDebounce = window.setTimeout(async () => {
const ratio = lockedRatio!
const targetH = Math.round(width / ratio)
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 {}
}
}, 150)
}).then(fn => cleanup.push(fn))
listen<{ ratio: number | null }>("overlay-aspect-lock", (e) => {
lockedRatio = e.payload.ratio
}).then(fn => cleanup.push(fn))
listen<{ phase: "idle"|"recording"|"paused"; fps: number }>( listen<{ phase: "idle"|"recording"|"paused"; fps: number }>(
"recording-state", (e) => { "recording-state", (e) => {
@@ -49,7 +71,11 @@
try { await invoke("close_window_picker") } catch {} try { await invoke("close_window_picker") } catch {}
}).then(fn => cleanup.push(fn)) }).then(fn => cleanup.push(fn))
return () => { stopTimer(); cleanup.forEach(fn => fn()) } return () => {
stopTimer()
if (resizeDebounce !== null) clearTimeout(resizeDebounce)
cleanup.forEach(fn => fn())
}
}) })
function startTimer() { function startTimer() {
+5 -2
View File
@@ -12,6 +12,7 @@ export type AppStatus = {
export type Format = "gif" | "webm" | "mp4" export type Format = "gif" | "webm" | "mp4"
export type GifDither = "floyd_steinberg" | "bayer" | "none" export type GifDither = "floyd_steinberg" | "bayer" | "none"
export type GifBudgetMode = "resolution" | "framerate" | "balanced"
export type WebmCodec = "vp9" | "av1" export type WebmCodec = "vp9" | "av1"
export type Mp4Codec = "h264" | "h265" export type Mp4Codec = "h264" | "h265"
@@ -101,6 +102,7 @@ export type RecordedClip = {
export type StartCaptureRequest = { export type StartCaptureRequest = {
crop: CaptureRect | null crop: CaptureRect | null
fps: number
} }
export type ExportRequest = { export type ExportRequest = {
@@ -113,6 +115,7 @@ export type ExportRequest = {
trim_end_secs?: number | null trim_end_secs?: number | null
output_path?: string | null output_path?: string | null
crop?: CaptureRect | null crop?: CaptureRect | null
gif_budget_mode?: GifBudgetMode
} }
export type ExportResult = { export type ExportResult = {
@@ -162,8 +165,8 @@ export const api = {
getOverlayRect: () => invoke<CaptureRect>("get_overlay_rect"), getOverlayRect: () => invoke<CaptureRect>("get_overlay_rect"),
extractThumbnails: (fps: number) => extractThumbnails: (fps: number) =>
invoke<string[]>("extract_thumbnails", { fps }), invoke<string[]>("extract_thumbnails", { fps }),
renderPreview: (format: Format, fps: number, target_bytes: number) => renderPreview: (format: Format, fps: number, target_bytes: number, gif_budget_mode?: GifBudgetMode) =>
invoke<string>("render_preview", { request: { format, fps, target_bytes } }), invoke<string>("render_preview", { request: { format, fps, target_bytes, gif_budget_mode } }),
defaultOutputPath: (format: Format) => defaultOutputPath: (format: Format) =>
invoke<string>("default_output_path", { format }), invoke<string>("default_output_path", { format }),
openUrl: (url: string) => invoke<void>("open_url", { url }), openUrl: (url: string) => invoke<void>("open_url", { url }),