keep capturing at the panel rate and name the fps setting after what it does
This commit is contained in:
@@ -794,20 +794,6 @@ fn is_hdr_output(device_name: &str) -> Option<bool> {
|
|||||||
None
|
None
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Pick the pipe framerate ffmpeg should declare for raw input, and the rate the
|
|
||||||
/// capture API is throttled to.
|
|
||||||
///
|
|
||||||
/// WGC hands over every frame the panel produces, so the user's setting is the
|
|
||||||
/// only thing that can make this differ from the refresh rate - and a setting
|
|
||||||
/// that changes nothing is worse than no setting. Asking for more than the panel
|
|
||||||
/// can deliver is pointless, so the request is capped at the refresh rate. The
|
|
||||||
/// declared rate has to match the throttled one: get that wrong and
|
|
||||||
/// `fix_intermediate_fps` rescales every timestamp by the difference, which
|
|
||||||
/// changes the clip's speed rather than its smoothness.
|
|
||||||
fn pipe_framerate(requested: u32, refresh_hz: u32) -> u32 {
|
|
||||||
requested.clamp(1, refresh_hz.max(1))
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Find the monitor containing the given screen point, falling back to the
|
/// Find the monitor containing the given screen point, falling back to the
|
||||||
/// primary monitor on failure.
|
/// primary monitor on failure.
|
||||||
fn monitor_at_point(x: i32, y: i32) -> Result<Monitor> {
|
fn monitor_at_point(x: i32, y: i32) -> Result<Monitor> {
|
||||||
@@ -837,7 +823,6 @@ pub(crate) fn start(
|
|||||||
ffmpeg_path: PathBuf,
|
ffmpeg_path: PathBuf,
|
||||||
capture_cursor: bool,
|
capture_cursor: bool,
|
||||||
crop: Option<CaptureRect>,
|
crop: Option<CaptureRect>,
|
||||||
fps: u32,
|
|
||||||
quality: CaptureQuality,
|
quality: CaptureQuality,
|
||||||
) -> Result<CaptureSession> {
|
) -> Result<CaptureSession> {
|
||||||
// Use the center of the capture region to determine which monitor to capture.
|
// Use the center of the capture region to determine which monitor to capture.
|
||||||
@@ -867,15 +852,14 @@ pub(crate) fn start(
|
|||||||
|
|
||||||
let frame_counter = Arc::new(std::sync::atomic::AtomicU64::new(0));
|
let frame_counter = Arc::new(std::sync::atomic::AtomicU64::new(0));
|
||||||
|
|
||||||
|
// The pipe declares what WGC actually delivers, which is the panel's refresh
|
||||||
|
// rate - not the frame rate in the settings. Those timestamps land close to
|
||||||
|
// real time already, so `fix_intermediate_fps` only has drift to correct.
|
||||||
|
// Throttling capture to the setting would throw away frames a later export
|
||||||
|
// cannot get back; the setting is a target for the export, the thumbnails and
|
||||||
|
// the GIF estimate instead.
|
||||||
let refresh_hz = monitor_refresh_rate(monitor);
|
let refresh_hz = monitor_refresh_rate(monitor);
|
||||||
let pipe_fps = pipe_framerate(fps, refresh_hz);
|
let pipe_fps = refresh_hz;
|
||||||
let update_interval = if pipe_fps < refresh_hz {
|
|
||||||
MinimumUpdateIntervalSettings::Custom(std::time::Duration::from_secs_f64(
|
|
||||||
1.0 / f64::from(pipe_fps),
|
|
||||||
))
|
|
||||||
} else {
|
|
||||||
MinimumUpdateIntervalSettings::Default
|
|
||||||
};
|
|
||||||
|
|
||||||
// A monitor showing HDR needs the tone curve; an SDR one must not go through
|
// A monitor showing HDR needs the tone curve; an SDR one must not go through
|
||||||
// it, or white comes out at 0.65. Unknown falls back to the HDR path so a
|
// it, or white comes out at 0.65. Unknown falls back to the HDR path so a
|
||||||
@@ -909,7 +893,7 @@ pub(crate) fn start(
|
|||||||
cursor_setting,
|
cursor_setting,
|
||||||
DrawBorderSettings::Default,
|
DrawBorderSettings::Default,
|
||||||
SecondaryWindowSettings::Default,
|
SecondaryWindowSettings::Default,
|
||||||
update_interval,
|
MinimumUpdateIntervalSettings::Default,
|
||||||
DirtyRegionSettings::Default,
|
DirtyRegionSettings::Default,
|
||||||
ColorFormat::Rgba16F,
|
ColorFormat::Rgba16F,
|
||||||
setup,
|
setup,
|
||||||
@@ -1129,28 +1113,4 @@ mod tests {
|
|||||||
assert_close(actual_fps, 60.0);
|
assert_close(actual_fps, 60.0);
|
||||||
assert_close(pts_scale, 2.0);
|
assert_close(pts_scale, 2.0);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// The setting has to reach the pipe, or the recording ignores what the user
|
|
||||||
/// picked and runs at whatever the panel does.
|
|
||||||
#[test]
|
|
||||||
fn pipe_rate_follows_the_setting_below_the_refresh_rate() {
|
|
||||||
assert_eq!(pipe_framerate(30, 60), 30);
|
|
||||||
assert_eq!(pipe_framerate(15, 60), 15);
|
|
||||||
assert_eq!(pipe_framerate(60, 60), 60);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Asking for more frames than the panel produces cannot produce more.
|
|
||||||
#[test]
|
|
||||||
fn pipe_rate_never_exceeds_the_panel() {
|
|
||||||
assert_eq!(pipe_framerate(120, 60), 60);
|
|
||||||
assert_eq!(pipe_framerate(240, 144), 144);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// A panel that reports 0 Hz would otherwise clamp to a max below the min and
|
|
||||||
/// panic; the declared rate must stay positive either way.
|
|
||||||
#[test]
|
|
||||||
fn pipe_rate_stays_positive_without_a_refresh_rate() {
|
|
||||||
assert_eq!(pipe_framerate(30, 0), 1);
|
|
||||||
assert_eq!(pipe_framerate(0, 60), 1);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
+2
-11
@@ -329,7 +329,6 @@ 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 {
|
||||||
@@ -569,10 +568,6 @@ fn start_capture(
|
|||||||
clear_temp_segments(&state.app_dir, true);
|
clear_temp_segments(&state.app_dir, true);
|
||||||
|
|
||||||
let crop = request.as_ref().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);
|
||||||
@@ -587,7 +582,6 @@ fn start_capture(
|
|||||||
ffmpeg,
|
ffmpeg,
|
||||||
cfg.capture.capture_cursor,
|
cfg.capture.capture_cursor,
|
||||||
crop,
|
crop,
|
||||||
fps,
|
|
||||||
cfg.capture.capture_quality,
|
cfg.capture.capture_quality,
|
||||||
)
|
)
|
||||||
.map_err(|e| format!("{e:#}"))?;
|
.map_err(|e| format!("{e:#}"))?;
|
||||||
@@ -690,16 +684,13 @@ fn resume_capture(app: AppHandle, state: State<'_, AppState>) -> Result<(), Stri
|
|||||||
(ss.capture_cursor, ss.audio, ss.crop, ss.segments.len() + 1)
|
(ss.capture_cursor, ss.audio, ss.crop, ss.segments.len() + 1)
|
||||||
};
|
};
|
||||||
|
|
||||||
let (fps, quality) = {
|
let quality = lock(&state.config).capture.capture_quality;
|
||||||
let c = lock(&state.config);
|
|
||||||
(c.capture.default_fps, c.capture.capture_quality)
|
|
||||||
};
|
|
||||||
let output = segment_path(&state.app_dir, next_idx);
|
let output = segment_path(&state.app_dir, next_idx);
|
||||||
let ffmpeg = bootstrap::ffmpeg_path(&state.app_dir);
|
let ffmpeg = bootstrap::ffmpeg_path(&state.app_dir);
|
||||||
if !ffmpeg.is_file() {
|
if !ffmpeg.is_file() {
|
||||||
return Err("ffmpeg.exe not found".to_string());
|
return Err("ffmpeg.exe not found".to_string());
|
||||||
}
|
}
|
||||||
let session = capture::start(output, ffmpeg, capture_cursor, crop, fps, quality)
|
let session = capture::start(output, ffmpeg, capture_cursor, crop, quality)
|
||||||
.map_err(|e| format!("{e:#}"))?;
|
.map_err(|e| format!("{e:#}"))?;
|
||||||
|
|
||||||
let audio_path = audio_segment_path(&state.app_dir, next_idx);
|
let audio_path = audio_segment_path(&state.app_dir, next_idx);
|
||||||
|
|||||||
+2
-2
@@ -212,7 +212,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, fps })
|
await api.startCapture({ crop })
|
||||||
phase = "recording"
|
phase = "recording"
|
||||||
tick()
|
tick()
|
||||||
void emit("recording-state", { phase: "recording", fps })
|
void emit("recording-state", { phase: "recording", fps })
|
||||||
@@ -542,7 +542,7 @@
|
|||||||
{/if}
|
{/if}
|
||||||
|
|
||||||
<div class="idle-fps">
|
<div class="idle-fps">
|
||||||
<span class="switch-label">Capture FPS</span>
|
<span class="switch-label">Export FPS</span>
|
||||||
<select bind:value={fps}>
|
<select bind:value={fps}>
|
||||||
{#each [1, 2, 5, 10, 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>
|
||||||
|
|||||||
@@ -10,7 +10,6 @@
|
|||||||
let width: number = $state(0)
|
let width: number = $state(0)
|
||||||
let height: number = $state(0)
|
let height: number = $state(0)
|
||||||
let phase: "idle" | "recording" | "paused" = $state("idle")
|
let phase: "idle" | "recording" | "paused" = $state("idle")
|
||||||
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 = $state(null)
|
let lockedRatio: number | null = $state(null)
|
||||||
@@ -51,9 +50,8 @@
|
|||||||
}, 200)
|
}, 200)
|
||||||
}).then(fn => cleanup.push(fn))
|
}).then(fn => cleanup.push(fn))
|
||||||
|
|
||||||
listen<{ phase: "idle"|"recording"|"paused"; fps: number }>(
|
listen<{ phase: "idle"|"recording"|"paused" }>(
|
||||||
"recording-state", (e) => {
|
"recording-state", (e) => {
|
||||||
fps = e.payload.fps
|
|
||||||
if (e.payload.phase === "recording") {
|
if (e.payload.phase === "recording") {
|
||||||
if (phase !== "recording") elapsed = 0
|
if (phase !== "recording") elapsed = 0
|
||||||
startTimer()
|
startTimer()
|
||||||
@@ -127,8 +125,6 @@
|
|||||||
{phase === "recording" ? "REC" : "PAUSE"}
|
{phase === "recording" ? "REC" : "PAUSE"}
|
||||||
<span class="sep">/</span>
|
<span class="sep">/</span>
|
||||||
{elapsed.toFixed(1)}s
|
{elapsed.toFixed(1)}s
|
||||||
<span class="sep">/</span>
|
|
||||||
{fps}fps
|
|
||||||
</span>
|
</span>
|
||||||
{/if}
|
{/if}
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -143,7 +143,7 @@
|
|||||||
</div>
|
</div>
|
||||||
<div class="field-list">
|
<div class="field-list">
|
||||||
<label class="field">
|
<label class="field">
|
||||||
<span class="field-label">Default FPS</span>
|
<span class="field-label">Export FPS</span>
|
||||||
<select bind:value={cfg.capture.default_fps}>
|
<select bind:value={cfg.capture.default_fps}>
|
||||||
{#each [15,24,30,60] as f}<option value={f}>{f} fps</option>{/each}
|
{#each [15,24,30,60] as f}<option value={f}>{f} fps</option>{/each}
|
||||||
</select>
|
</select>
|
||||||
|
|||||||
@@ -106,7 +106,6 @@ export type RecordedClip = {
|
|||||||
|
|
||||||
export type StartCaptureRequest = {
|
export type StartCaptureRequest = {
|
||||||
crop: CaptureRect | null
|
crop: CaptureRect | null
|
||||||
fps: number
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export type ExportRequest = {
|
export type ExportRequest = {
|
||||||
|
|||||||
Reference in New Issue
Block a user