quality pass 2: cached encoders, cancel in gif retry, overlay CSS split
- debug logging in picker changed to tracing::debug - show_overlay uses visible_window_bounds helper - encode_gif retry loop checks cancel flag between attempts - list_encoders cached via OnceLock (ffmpeg -encoders runs once) - remove unnecessary GifBudgetMode clone (is Copy) - config test uses unique temp dir per process - click highlights use 2px border instead of solid fill - audio capture_loop polls at 5ms instead of 1ms - overlay window loads minimal overlay.css instead of full app.css - remove non-spec 960x540 preset - Settings dirty detection uses field-by-field comparison - Overlay startDragging catches errors - pauseRec only emits recording-state on success - Picker listener cleanup guards against unmount race - add sync notes for previewDims and sr-only trim inputs
This commit is contained in:
@@ -275,7 +275,7 @@ fn capture_loop(
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
thread::sleep(std::time::Duration::from_millis(1));
|
thread::sleep(std::time::Duration::from_millis(5));
|
||||||
}
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -207,7 +207,7 @@ mod tests {
|
|||||||
theme: Theme::Light,
|
theme: Theme::Light,
|
||||||
};
|
};
|
||||||
|
|
||||||
let dir = std::env::temp_dir().join("bytesize-test-config");
|
let dir = std::env::temp_dir().join(format!("bytesize-test-{}", std::process::id()));
|
||||||
let _ = std::fs::remove_dir_all(&dir);
|
let _ = std::fs::remove_dir_all(&dir);
|
||||||
std::fs::create_dir_all(&dir).unwrap();
|
std::fs::create_dir_all(&dir).unwrap();
|
||||||
let path = dir.join("config.toml");
|
let path = dir.join("config.toml");
|
||||||
|
|||||||
+16
-4
@@ -85,7 +85,7 @@ fn click_filters(req: &TranscodeRequest) -> Option<String> {
|
|||||||
crate::clicks::MouseButton::Middle => "green@0.6",
|
crate::clicks::MouseButton::Middle => "green@0.6",
|
||||||
};
|
};
|
||||||
parts.push(format!(
|
parts.push(format!(
|
||||||
"drawbox=x={x}:y={y}:w={size}:h={size}:color={color}:t=fill:enable='between(t,{t1:.3},{t2:.3})'"
|
"drawbox=x={x}:y={y}:w={size}:h={size}:color={color}:t=2:enable='between(t,{t1:.3},{t2:.3})'"
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
if parts.is_empty() {
|
if parts.is_empty() {
|
||||||
@@ -159,7 +159,14 @@ pub fn transcode(ffmpeg: &Path, req: &TranscodeRequest) -> Result<()> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn list_encoders(ffmpeg: &Path) -> Result<HashSet<String>> {
|
use std::sync::OnceLock;
|
||||||
|
|
||||||
|
static ENCODER_CACHE: OnceLock<HashSet<String>> = OnceLock::new();
|
||||||
|
|
||||||
|
fn list_encoders(ffmpeg: &Path) -> Result<&'static HashSet<String>> {
|
||||||
|
if let Some(cached) = ENCODER_CACHE.get() {
|
||||||
|
return Ok(cached);
|
||||||
|
}
|
||||||
let out = Command::new(ffmpeg)
|
let out = Command::new(ffmpeg)
|
||||||
.args(["-hide_banner", "-encoders"])
|
.args(["-hide_banner", "-encoders"])
|
||||||
.output()
|
.output()
|
||||||
@@ -180,7 +187,8 @@ fn list_encoders(ffmpeg: &Path) -> Result<HashSet<String>> {
|
|||||||
}
|
}
|
||||||
set.insert(name.to_string());
|
set.insert(name.to_string());
|
||||||
}
|
}
|
||||||
Ok(set)
|
let _ = ENCODER_CACHE.set(set);
|
||||||
|
Ok(ENCODER_CACHE.get().unwrap())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn pick_video_codec<'a>(
|
fn pick_video_codec<'a>(
|
||||||
@@ -353,13 +361,16 @@ fn encode_gif(ffmpeg: &Path, req: &TranscodeRequest) -> Result<()> {
|
|||||||
target_bytes: req.target_bytes,
|
target_bytes: req.target_bytes,
|
||||||
fps: req.fps,
|
fps: req.fps,
|
||||||
duration_secs: req.duration_secs,
|
duration_secs: req.duration_secs,
|
||||||
gif_budget_mode: req.gif_budget_mode.clone(),
|
gif_budget_mode: req.gif_budget_mode,
|
||||||
};
|
};
|
||||||
let (mut scale_width, mut effective_fps) = gif_params(&budget_input, req.clip_width, req.clip_height);
|
let (mut scale_width, mut effective_fps) = gif_params(&budget_input, req.clip_width, req.clip_height);
|
||||||
let target = req.target_bytes;
|
let target = req.target_bytes;
|
||||||
let max_retries = 6;
|
let max_retries = 6;
|
||||||
|
|
||||||
for attempt in 0..max_retries {
|
for attempt in 0..max_retries {
|
||||||
|
if req.cancel.as_ref().map_or(false, |c| c.load(Ordering::Relaxed)) {
|
||||||
|
bail!("export cancelled");
|
||||||
|
}
|
||||||
// Last resort: use minimal settings to hit the target
|
// Last resort: use minimal settings to hit the target
|
||||||
if attempt == 5 {
|
if attempt == 5 {
|
||||||
scale_width = (scale_width / 2).max(60);
|
scale_width = (scale_width / 2).max(60);
|
||||||
@@ -911,6 +922,7 @@ fn parse_frame_from_stderr(line: &str) -> Option<f64> {
|
|||||||
mod tests {
|
mod tests {
|
||||||
use super::*;
|
use super::*;
|
||||||
|
|
||||||
|
// Paths are empty - these tests only exercise bitrate math, not ffmpeg.
|
||||||
fn dummy_request() -> TranscodeRequest {
|
fn dummy_request() -> TranscodeRequest {
|
||||||
TranscodeRequest {
|
TranscodeRequest {
|
||||||
input: PathBuf::new(),
|
input: PathBuf::new(),
|
||||||
|
|||||||
+11
-18
@@ -386,7 +386,7 @@ fn start_capture(
|
|||||||
|
|
||||||
let session = capture::start(
|
let session = capture::start(
|
||||||
output,
|
output,
|
||||||
ffmpeg.clone(),
|
ffmpeg,
|
||||||
cfg.capture.capture_cursor,
|
cfg.capture.capture_cursor,
|
||||||
cfg.capture.capture_audio,
|
cfg.capture.capture_audio,
|
||||||
crop,
|
crop,
|
||||||
@@ -848,30 +848,23 @@ fn show_overlay(app: AppHandle) -> Result<(), String> {
|
|||||||
let _ = mark_overlay_excluded_from_capture(&win);
|
let _ = mark_overlay_excluded_from_capture(&win);
|
||||||
|
|
||||||
// If the overlay is off-screen (monitor disconnected), center on primary
|
// If the overlay is off-screen (monitor disconnected), center on primary
|
||||||
use windows::Win32::Foundation::{HWND, POINT, RECT};
|
use windows::Win32::Foundation::{HWND, POINT};
|
||||||
use windows::Win32::Graphics::Gdi::{
|
use windows::Win32::Graphics::Gdi::{
|
||||||
GetMonitorInfoW, MonitorFromPoint, MONITOR_DEFAULTTOPRIMARY, MONITOR_DEFAULTTONULL, MONITORINFO,
|
GetMonitorInfoW, MonitorFromPoint, MONITOR_DEFAULTTOPRIMARY, MONITOR_DEFAULTTONULL, MONITORINFO,
|
||||||
};
|
};
|
||||||
use windows::Win32::UI::WindowsAndMessaging::{GetWindowRect, SetWindowPos, HWND_TOP, SWP_NOACTIVATE, SWP_NOSIZE, SWP_NOZORDER};
|
use windows::Win32::UI::WindowsAndMessaging::{SetWindowPos, HWND_TOP, SWP_NOACTIVATE, SWP_NOSIZE, SWP_NOZORDER};
|
||||||
if let Ok(raw) = win.hwnd() {
|
if let Ok(raw) = win.hwnd() {
|
||||||
let hwnd = HWND(raw.0 as *mut _);
|
if let Some((vl, vt, vr, vb)) = visible_window_bounds(raw.0 as isize) {
|
||||||
let mut rect = RECT::default();
|
let center = POINT { x: (vl + vr) / 2, y: (vt + vb) / 2 };
|
||||||
if unsafe { GetWindowRect(hwnd, &mut rect) }.is_ok() {
|
|
||||||
let center = POINT {
|
|
||||||
x: (rect.left + rect.right) / 2,
|
|
||||||
y: (rect.top + rect.bottom) / 2,
|
|
||||||
};
|
|
||||||
let hmon = unsafe { MonitorFromPoint(center, MONITOR_DEFAULTTONULL) };
|
let hmon = unsafe { MonitorFromPoint(center, MONITOR_DEFAULTTONULL) };
|
||||||
if hmon.0.is_null() {
|
if hmon.0.is_null() {
|
||||||
|
let hwnd = HWND(raw.0 as *mut _);
|
||||||
let primary = unsafe { MonitorFromPoint(POINT { x: 0, y: 0 }, MONITOR_DEFAULTTOPRIMARY) };
|
let primary = unsafe { MonitorFromPoint(POINT { x: 0, y: 0 }, MONITOR_DEFAULTTOPRIMARY) };
|
||||||
let mut mi = MONITORINFO {
|
let mut mi = MONITORINFO { cbSize: std::mem::size_of::<MONITORINFO>() as u32, ..Default::default() };
|
||||||
cbSize: std::mem::size_of::<MONITORINFO>() as u32,
|
|
||||||
..Default::default()
|
|
||||||
};
|
|
||||||
if unsafe { GetMonitorInfoW(primary, &mut mi) }.as_bool() {
|
if unsafe { GetMonitorInfoW(primary, &mut mi) }.as_bool() {
|
||||||
let work = mi.rcWork;
|
let work = mi.rcWork;
|
||||||
let w = rect.right - rect.left;
|
let w = vr - vl;
|
||||||
let h = rect.bottom - rect.top;
|
let h = vb - vt;
|
||||||
let cx = (work.left + work.right) / 2 - w / 2;
|
let cx = (work.left + work.right) / 2 - w / 2;
|
||||||
let cy = (work.top + work.bottom) / 2 - h / 2;
|
let cy = (work.top + work.bottom) / 2 - h / 2;
|
||||||
let _ = unsafe { SetWindowPos(hwnd, Some(HWND_TOP), cx, cy, 0, 0, SWP_NOACTIVATE | SWP_NOZORDER | SWP_NOSIZE) };
|
let _ = unsafe { SetWindowPos(hwnd, Some(HWND_TOP), cx, cy, 0, 0, SWP_NOACTIVATE | SWP_NOZORDER | SWP_NOSIZE) };
|
||||||
@@ -992,7 +985,7 @@ fn open_window_picker(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
tracing::info!(
|
tracing::debug!(
|
||||||
"open_window_picker: monitor={}x{} exclude={:?}",
|
"open_window_picker: monitor={}x{} exclude={:?}",
|
||||||
mw,
|
mw,
|
||||||
mh,
|
mh,
|
||||||
@@ -1028,7 +1021,7 @@ fn open_window_picker(
|
|||||||
std::mem::size_of::<RECT>() as u32,
|
std::mem::size_of::<RECT>() as u32,
|
||||||
)
|
)
|
||||||
};
|
};
|
||||||
tracing::info!(
|
tracing::debug!(
|
||||||
"picker window: GetWindowRect=({},{},{},{}) DwmBounds=({},{},{},{})",
|
"picker window: GetWindowRect=({},{},{},{}) DwmBounds=({},{},{},{})",
|
||||||
gr.left, gr.top, gr.right, gr.bottom,
|
gr.left, gr.top, gr.right, gr.bottom,
|
||||||
dr.left, dr.top, dr.right, dr.bottom
|
dr.left, dr.top, dr.right, dr.bottom
|
||||||
|
|||||||
+3
-2
@@ -59,13 +59,13 @@
|
|||||||
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"],
|
||||||
]
|
]
|
||||||
|
|
||||||
// Derived
|
// Derived
|
||||||
let trimmedDuration = $derived(Math.max(0.1, trimEnd - trimStart))
|
let trimmedDuration = $derived(Math.max(0.1, trimEnd - trimStart))
|
||||||
|
// NOTE: This logic mirrors gif_params() in encode.rs. Keep in sync.
|
||||||
let previewDims = $derived.by(() => {
|
let previewDims = $derived.by(() => {
|
||||||
if (!clip) return ""
|
if (!clip) return ""
|
||||||
if (format === "gif") {
|
if (format === "gif") {
|
||||||
@@ -196,10 +196,10 @@
|
|||||||
await api.pauseCapture()
|
await api.pauseCapture()
|
||||||
clearTick()
|
clearTick()
|
||||||
phase = "paused"
|
phase = "paused"
|
||||||
|
void emit("recording-state", { phase: "paused", fps })
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
errMsg = String(e)
|
errMsg = String(e)
|
||||||
}
|
}
|
||||||
void emit("recording-state", { phase: "paused", fps })
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async function resumeRec() {
|
async function resumeRec() {
|
||||||
@@ -624,6 +624,7 @@
|
|||||||
}}
|
}}
|
||||||
></div>
|
></div>
|
||||||
</div>
|
</div>
|
||||||
|
<!-- Screen reader alternative: these range inputs mirror the drag handle positions. -->
|
||||||
<input type="range" min="0" max={clip.duration_secs} step="0.05" value={trimStart}
|
<input type="range" min="0" max={clip.duration_secs} step="0.05" value={trimStart}
|
||||||
oninput={(e) => { const v = parseFloat((e.currentTarget as HTMLInputElement).value); trimStart = Math.min(v, trimEnd - 0.1) }}
|
oninput={(e) => { const v = parseFloat((e.currentTarget as HTMLInputElement).value); trimStart = Math.min(v, trimEnd - 0.1) }}
|
||||||
class="sr-only" aria-label="trim start seconds" />
|
class="sr-only" aria-label="trim start seconds" />
|
||||||
|
|||||||
@@ -90,7 +90,7 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
function drag(e: MouseEvent) {
|
function drag(e: MouseEvent) {
|
||||||
if (e.button === 0) void win.startDragging()
|
if (e.button === 0) win.startDragging().catch(() => {})
|
||||||
}
|
}
|
||||||
|
|
||||||
async function openPicker() {
|
async function openPicker() {
|
||||||
|
|||||||
@@ -7,6 +7,7 @@
|
|||||||
|
|
||||||
let hover: Rect | null = $state(null)
|
let hover: Rect | null = $state(null)
|
||||||
let originX = 0, originY = 0, scale = 1
|
let originX = 0, originY = 0, scale = 1
|
||||||
|
let mounted = true
|
||||||
|
|
||||||
onMount(() => {
|
onMount(() => {
|
||||||
const win = getCurrentWebviewWindow()
|
const win = getCurrentWebviewWindow()
|
||||||
@@ -20,11 +21,14 @@
|
|||||||
|
|
||||||
void (async () => {
|
void (async () => {
|
||||||
await refresh()
|
await refresh()
|
||||||
unlisten.push(await win.onMoved(refresh))
|
win.onMoved(refresh).then(fn => { if (mounted) unlisten.push(fn) })
|
||||||
unlisten.push(await listen<Rect>("picker-hover", (e) => { hover = e.payload }))
|
listen<Rect>("picker-hover", (e) => { hover = e.payload }).then(fn => { if (mounted) unlisten.push(fn) })
|
||||||
})()
|
})()
|
||||||
|
|
||||||
return () => unlisten.forEach(fn => fn())
|
return () => {
|
||||||
|
mounted = false
|
||||||
|
unlisten.forEach(fn => fn())
|
||||||
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
let rectStyle = $derived.by(() => {
|
let rectStyle = $derived.by(() => {
|
||||||
|
|||||||
+19
-4
@@ -11,9 +11,24 @@
|
|||||||
let hotkeyWarnings: string[] = $state([])
|
let hotkeyWarnings: string[] = $state([])
|
||||||
let showAdvanced: boolean = $state(false)
|
let showAdvanced: boolean = $state(false)
|
||||||
let activeTab: string = $state("capture")
|
let activeTab: string = $state("capture")
|
||||||
let initialCfg: string = $state("")
|
let initialCfg: Config | null = $state(null)
|
||||||
|
|
||||||
let dirty = $derived(cfg ? JSON.stringify(cfg) !== initialCfg : false)
|
let dirty = $derived.by(() => {
|
||||||
|
if (!cfg || !initialCfg) return false
|
||||||
|
return cfg.theme !== initialCfg.theme
|
||||||
|
|| 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.export.default_format !== initialCfg.export.default_format
|
||||||
|
|| cfg.export.gif_dither !== initialCfg.export.gif_dither
|
||||||
|
|| cfg.export.webm_codec !== initialCfg.export.webm_codec
|
||||||
|
|| cfg.export.mp4_codec !== initialCfg.export.mp4_codec
|
||||||
|
|| cfg.hotkeys.start !== initialCfg.hotkeys.start
|
||||||
|
|| cfg.hotkeys.stop !== initialCfg.hotkeys.stop
|
||||||
|
|| cfg.hotkeys.pause !== initialCfg.hotkeys.pause
|
||||||
|
|| cfg.updates.check_on_launch !== initialCfg.updates.check_on_launch
|
||||||
|
|| cfg.output_dir !== initialCfg.output_dir
|
||||||
|
})
|
||||||
|
|
||||||
const TABS = [
|
const TABS = [
|
||||||
{ id: "capture", label: "Capture" },
|
{ id: "capture", label: "Capture" },
|
||||||
@@ -23,7 +38,7 @@
|
|||||||
{ id: "system", label: "System" },
|
{ id: "system", label: "System" },
|
||||||
]
|
]
|
||||||
|
|
||||||
onMount(async () => { cfg = await api.getConfig(); initialCfg = JSON.stringify(cfg) })
|
onMount(async () => { cfg = await api.getConfig(); initialCfg = structuredClone(cfg) })
|
||||||
|
|
||||||
async function save() {
|
async function save() {
|
||||||
if (!cfg) return
|
if (!cfg) return
|
||||||
@@ -47,7 +62,7 @@
|
|||||||
if (failed.length > 0) {
|
if (failed.length > 0) {
|
||||||
hotkeyWarnings = [`${failed.join(", ")} - hotkey may be in use by another app`]
|
hotkeyWarnings = [`${failed.join(", ")} - hotkey may be in use by another app`]
|
||||||
} else {
|
} else {
|
||||||
initialCfg = JSON.stringify(cfg)
|
initialCfg = structuredClone(cfg)
|
||||||
onClose()
|
onClose()
|
||||||
}
|
}
|
||||||
} finally { saving = false }
|
} finally { saving = false }
|
||||||
|
|||||||
@@ -0,0 +1,5 @@
|
|||||||
|
@import url('https://fonts.bunny.net/css2?family=JetBrains+Mono:wght@400;500&display=swap');
|
||||||
|
:root {
|
||||||
|
--mono: 'JetBrains Mono', ui-monospace, monospace;
|
||||||
|
--r-sm: 3px;
|
||||||
|
}
|
||||||
+1
-1
@@ -1,5 +1,5 @@
|
|||||||
import { mount } from "svelte"
|
import { mount } from "svelte"
|
||||||
import "./app.css"
|
import "./overlay.css"
|
||||||
import Overlay from "./lib/Overlay.svelte"
|
import Overlay from "./lib/Overlay.svelte"
|
||||||
|
|
||||||
const app = mount(Overlay, {
|
const app = mount(Overlay, {
|
||||||
|
|||||||
Reference in New Issue
Block a user