let the capture rate be capped on purpose, off by default
This commit is contained in:
@@ -794,6 +794,27 @@ fn is_hdr_output(device_name: &str) -> Option<bool> {
|
|||||||
None
|
None
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Resolve what the raw pipe declares, and whether WGC has to be throttled to
|
||||||
|
/// get there. Returns `(fps, throttled)`.
|
||||||
|
///
|
||||||
|
/// With no limit the pipe declares the panel's refresh rate, which is what WGC
|
||||||
|
/// delivers on its own - and the declared rate has to match what actually
|
||||||
|
/// arrives, or `fix_intermediate_fps` rescales every timestamp by the difference
|
||||||
|
/// and changes the clip's speed rather than its smoothness.
|
||||||
|
///
|
||||||
|
/// A limit above the refresh rate needs no throttle, and one below it caps at
|
||||||
|
/// the panel either way. The `max(1)` keeps `clamp` from panicking if a panel
|
||||||
|
/// ever reports 0 Hz, which `monitor_refresh_rate` already guards against.
|
||||||
|
fn pipe_rate(refresh_hz: u32, limit: Option<u32>) -> (u32, bool) {
|
||||||
|
match limit {
|
||||||
|
Some(requested) => {
|
||||||
|
let fps = requested.clamp(1, refresh_hz.max(1));
|
||||||
|
(fps, fps < refresh_hz)
|
||||||
|
}
|
||||||
|
None => (refresh_hz, false),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// 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> {
|
||||||
@@ -823,6 +844,7 @@ pub(crate) fn start(
|
|||||||
ffmpeg_path: PathBuf,
|
ffmpeg_path: PathBuf,
|
||||||
capture_cursor: bool,
|
capture_cursor: bool,
|
||||||
crop: Option<CaptureRect>,
|
crop: Option<CaptureRect>,
|
||||||
|
rate_limit: Option<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.
|
||||||
@@ -852,14 +874,18 @@ 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
|
// Off by default, so the pipe declares the panel's refresh rate and WGC
|
||||||
// rate - not the frame rate in the settings. Those timestamps land close to
|
// delivers it untouched. Only an explicit cap throttles, and then the
|
||||||
// real time already, so `fix_intermediate_fps` only has drift to correct.
|
// declared rate follows the throttle down.
|
||||||
// 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 = refresh_hz;
|
let (pipe_fps, throttled) = pipe_rate(refresh_hz, rate_limit);
|
||||||
|
let update_interval = if throttled {
|
||||||
|
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
|
||||||
@@ -893,7 +919,7 @@ pub(crate) fn start(
|
|||||||
cursor_setting,
|
cursor_setting,
|
||||||
DrawBorderSettings::Default,
|
DrawBorderSettings::Default,
|
||||||
SecondaryWindowSettings::Default,
|
SecondaryWindowSettings::Default,
|
||||||
MinimumUpdateIntervalSettings::Default,
|
update_interval,
|
||||||
DirtyRegionSettings::Default,
|
DirtyRegionSettings::Default,
|
||||||
ColorFormat::Rgba16F,
|
ColorFormat::Rgba16F,
|
||||||
setup,
|
setup,
|
||||||
@@ -1113,4 +1139,26 @@ 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);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// No cap is the default and must leave the rate exactly where WGC puts it.
|
||||||
|
#[test]
|
||||||
|
fn pipe_rate_follows_the_panel_without_a_cap() {
|
||||||
|
assert_eq!(pipe_rate(120, None), (120, false));
|
||||||
|
assert_eq!(pipe_rate(60, None), (60, false));
|
||||||
|
}
|
||||||
|
|
||||||
|
/// An explicit cap below the refresh rate throttles, and the declared rate
|
||||||
|
/// follows it down so the two cannot disagree.
|
||||||
|
#[test]
|
||||||
|
fn pipe_rate_throttles_to_an_explicit_cap() {
|
||||||
|
assert_eq!(pipe_rate(120, Some(30)), (30, true));
|
||||||
|
assert_eq!(pipe_rate(120, Some(60)), (60, true));
|
||||||
|
}
|
||||||
|
|
||||||
|
/// A cap at or above the panel has nothing to hold back.
|
||||||
|
#[test]
|
||||||
|
fn pipe_rate_needs_no_throttle_at_or_above_the_panel() {
|
||||||
|
assert_eq!(pipe_rate(120, Some(120)), (120, false));
|
||||||
|
assert_eq!(pipe_rate(60, Some(240)), (60, false));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -61,6 +61,11 @@ pub struct CaptureConfig {
|
|||||||
pub capture_cursor: bool,
|
pub capture_cursor: bool,
|
||||||
pub capture_audio: bool,
|
pub capture_audio: bool,
|
||||||
pub capture_quality: CaptureQuality,
|
pub capture_quality: CaptureQuality,
|
||||||
|
/// Opt in to recording at `default_fps` instead of the panel's refresh rate.
|
||||||
|
/// Off by default, and a config written before this field existed gets false
|
||||||
|
/// through the container `serde(default)` - so nobody's capture changes until
|
||||||
|
/// they turn it on.
|
||||||
|
pub limit_capture_fps: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone, Default, Serialize, Deserialize)]
|
#[derive(Debug, Clone, Default, Serialize, Deserialize)]
|
||||||
@@ -151,6 +156,7 @@ impl Default for CaptureConfig {
|
|||||||
capture_cursor: true,
|
capture_cursor: true,
|
||||||
capture_audio: false,
|
capture_audio: false,
|
||||||
capture_quality: CaptureQuality::Auto,
|
capture_quality: CaptureQuality::Auto,
|
||||||
|
limit_capture_fps: false,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -278,6 +284,7 @@ mod tests {
|
|||||||
capture_cursor: false,
|
capture_cursor: false,
|
||||||
capture_audio: true,
|
capture_audio: true,
|
||||||
capture_quality: CaptureQuality::Full,
|
capture_quality: CaptureQuality::Full,
|
||||||
|
limit_capture_fps: true,
|
||||||
},
|
},
|
||||||
hotkeys: HotkeyConfig {
|
hotkeys: HotkeyConfig {
|
||||||
start: Some("F9".to_string()),
|
start: Some("F9".to_string()),
|
||||||
@@ -299,6 +306,7 @@ mod tests {
|
|||||||
let loaded = Config::load_or_create(&path).unwrap();
|
let loaded = Config::load_or_create(&path).unwrap();
|
||||||
assert_eq!(loaded.export.default_format, Format::Webm);
|
assert_eq!(loaded.export.default_format, Format::Webm);
|
||||||
assert_eq!(loaded.capture.default_fps, 60);
|
assert_eq!(loaded.capture.default_fps, 60);
|
||||||
|
assert!(loaded.capture.limit_capture_fps);
|
||||||
assert_eq!(loaded.hotkeys.start, Some("F9".to_string()));
|
assert_eq!(loaded.hotkeys.start, Some("F9".to_string()));
|
||||||
assert_eq!(loaded.output_dir, Some(PathBuf::from("./custom")));
|
assert_eq!(loaded.output_dir, Some(PathBuf::from("./custom")));
|
||||||
assert_eq!(loaded.theme, Theme::Light);
|
assert_eq!(loaded.theme, Theme::Light);
|
||||||
|
|||||||
@@ -582,6 +582,7 @@ fn start_capture(
|
|||||||
ffmpeg,
|
ffmpeg,
|
||||||
cfg.capture.capture_cursor,
|
cfg.capture.capture_cursor,
|
||||||
crop,
|
crop,
|
||||||
|
cfg.capture.limit_capture_fps.then_some(cfg.capture.default_fps),
|
||||||
cfg.capture.capture_quality,
|
cfg.capture.capture_quality,
|
||||||
)
|
)
|
||||||
.map_err(|e| format!("{e:#}"))?;
|
.map_err(|e| format!("{e:#}"))?;
|
||||||
@@ -684,13 +685,19 @@ 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 quality = lock(&state.config).capture.capture_quality;
|
let (rate_limit, quality) = {
|
||||||
|
let c = lock(&state.config);
|
||||||
|
(
|
||||||
|
c.capture.limit_capture_fps.then_some(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, quality)
|
let session = capture::start(output, ffmpeg, capture_cursor, crop, rate_limit, 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);
|
||||||
|
|||||||
+13
-2
@@ -21,6 +21,7 @@
|
|||||||
|| cfg.capture.capture_cursor !== initialCfg.capture.capture_cursor
|
|| cfg.capture.capture_cursor !== initialCfg.capture.capture_cursor
|
||||||
|| cfg.capture.capture_audio !== initialCfg.capture.capture_audio
|
|| cfg.capture.capture_audio !== initialCfg.capture.capture_audio
|
||||||
|| cfg.capture.capture_quality !== initialCfg.capture.capture_quality
|
|| cfg.capture.capture_quality !== initialCfg.capture.capture_quality
|
||||||
|
|| cfg.capture.limit_capture_fps !== initialCfg.capture.limit_capture_fps
|
||||||
|| cfg.export.default_format !== initialCfg.export.default_format
|
|| cfg.export.default_format !== initialCfg.export.default_format
|
||||||
|| cfg.export.gif_dither !== initialCfg.export.gif_dither
|
|| cfg.export.gif_dither !== initialCfg.export.gif_dither
|
||||||
|| cfg.export.webm_codec !== initialCfg.export.webm_codec
|
|| cfg.export.webm_codec !== initialCfg.export.webm_codec
|
||||||
@@ -148,6 +149,16 @@
|
|||||||
{#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>
|
||||||
</label>
|
</label>
|
||||||
|
<label class="field-check">
|
||||||
|
<input type="checkbox" bind:checked={cfg.capture.limit_capture_fps} />
|
||||||
|
<span>Cap capture at this rate</span>
|
||||||
|
</label>
|
||||||
|
{#if cfg.capture.limit_capture_fps}
|
||||||
|
<p class="field-note">
|
||||||
|
Recording stops at {cfg.capture.default_fps} fps instead of the display's refresh
|
||||||
|
rate. Smaller temp files and less CPU, but nothing above that rate is captured.
|
||||||
|
</p>
|
||||||
|
{/if}
|
||||||
<label class="field">
|
<label class="field">
|
||||||
<span class="field-label">Capture quality</span>
|
<span class="field-label">Capture quality</span>
|
||||||
<select bind:value={cfg.capture.capture_quality}>
|
<select bind:value={cfg.capture.capture_quality}>
|
||||||
@@ -213,7 +224,7 @@
|
|||||||
</select>
|
</select>
|
||||||
</label>
|
</label>
|
||||||
{#if codecs && (!codecs.av1 || !codecs.h265)}
|
{#if codecs && (!codecs.av1 || !codecs.h265)}
|
||||||
<p class="codec-note">Some codecs are unavailable in your ffmpeg build and disabled above.</p>
|
<p class="field-note">Some codecs are unavailable in your ffmpeg build and disabled above.</p>
|
||||||
{/if}
|
{/if}
|
||||||
{/if}
|
{/if}
|
||||||
</div>
|
</div>
|
||||||
@@ -515,7 +526,7 @@
|
|||||||
.advanced-toggle svg { transition: transform 150ms; }
|
.advanced-toggle svg { transition: transform 150ms; }
|
||||||
.advanced-toggle svg.rotated { transform: rotate(180deg); }
|
.advanced-toggle svg.rotated { transform: rotate(180deg); }
|
||||||
|
|
||||||
.codec-note {
|
.field-note {
|
||||||
margin: 0;
|
margin: 0;
|
||||||
font-size: 11px;
|
font-size: 11px;
|
||||||
color: var(--warn);
|
color: var(--warn);
|
||||||
|
|||||||
@@ -30,6 +30,7 @@ export type CaptureConfig = {
|
|||||||
capture_cursor: boolean
|
capture_cursor: boolean
|
||||||
capture_audio: boolean
|
capture_audio: boolean
|
||||||
capture_quality: CaptureQuality
|
capture_quality: CaptureQuality
|
||||||
|
limit_capture_fps: boolean
|
||||||
}
|
}
|
||||||
|
|
||||||
export type HotkeyConfig = {
|
export type HotkeyConfig = {
|
||||||
|
|||||||
Reference in New Issue
Block a user