keep capturing at the panel rate and name the fps setting after what it does

This commit is contained in:
2026-09-21 06:49:37 +03:00
parent aef64fa4e3
commit a953875405
6 changed files with 14 additions and 68 deletions
+8 -48
View File
@@ -794,20 +794,6 @@ fn is_hdr_output(device_name: &str) -> Option<bool> {
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
/// primary monitor on failure.
fn monitor_at_point(x: i32, y: i32) -> Result<Monitor> {
@@ -837,7 +823,6 @@ pub(crate) fn start(
ffmpeg_path: PathBuf,
capture_cursor: bool,
crop: Option<CaptureRect>,
fps: u32,
quality: CaptureQuality,
) -> Result<CaptureSession> {
// 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));
// 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 pipe_fps = pipe_framerate(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
};
let pipe_fps = refresh_hz;
// 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
@@ -909,7 +893,7 @@ pub(crate) fn start(
cursor_setting,
DrawBorderSettings::Default,
SecondaryWindowSettings::Default,
update_interval,
MinimumUpdateIntervalSettings::Default,
DirtyRegionSettings::Default,
ColorFormat::Rgba16F,
setup,
@@ -1129,28 +1113,4 @@ mod tests {
assert_close(actual_fps, 60.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
View File
@@ -329,7 +329,6 @@ async fn download_ffmpeg(app: AppHandle, state: State<'_, AppState>) -> Result<(
#[derive(Debug, Deserialize)]
pub struct StartCaptureRequest {
pub crop: Option<CaptureRect>,
pub fps: Option<u32>,
}
fn segment_path(app_dir: &Path, idx: usize) -> PathBuf {
@@ -569,10 +568,6 @@ fn start_capture(
clear_temp_segments(&state.app_dir, true);
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 ffmpeg = bootstrap::ffmpeg_path(&state.app_dir);
@@ -587,7 +582,6 @@ fn start_capture(
ffmpeg,
cfg.capture.capture_cursor,
crop,
fps,
cfg.capture.capture_quality,
)
.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)
};
let (fps, quality) = {
let c = lock(&state.config);
(c.capture.default_fps, c.capture.capture_quality)
};
let quality = lock(&state.config).capture.capture_quality;
let output = segment_path(&state.app_dir, next_idx);
let ffmpeg = bootstrap::ffmpeg_path(&state.app_dir);
if !ffmpeg.is_file() {
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:#}"))?;
let audio_path = audio_segment_path(&state.app_dir, next_idx);