fix capture speeding up: remove framerate declaration and fps filter

The capture was declaring -framerate 120 (monitor refresh rate) but the
Windows capture API doesn't deliver frames at that rate. This caused ffmpeg
to compress the timeline - 10 seconds of recording became 4 seconds of video.

Fix: remove both -framerate and fps filter from capture. All frames are
captured as they arrive. The export pipeline's fps filter handles rate
conversion correctly.
This commit is contained in:
2026-05-30 01:05:29 +03:00
parent c970caeebd
commit 67c2a84178
+5 -5
View File
@@ -26,6 +26,7 @@ pub struct CaptureSetup {
pub ffmpeg_path: PathBuf, pub ffmpeg_path: PathBuf,
pub width: u32, pub width: u32,
pub height: u32, pub height: u32,
#[allow(dead_code)]
pub fps: u32, pub fps: u32,
pub crop: Option<CaptureRect>, pub crop: Option<CaptureRect>,
} }
@@ -57,8 +58,8 @@ impl GraphicsCaptureApiHandler for CaptureHandler {
setup.width setup.width
}; };
// Reduce frame rate before scaling to avoid processing unnecessary frames // Capture all frames at the rate they arrive. No fps filter in capture -
filter_parts.push(format!("fps={}", setup.fps)); // the export pipeline handles frame rate conversion.
if working_width > MAX_ENCODE_WIDTH { if working_width > MAX_ENCODE_WIDTH {
filter_parts.push(format!("scale={}:-2", MAX_ENCODE_WIDTH)); filter_parts.push(format!("scale={}:-2", MAX_ENCODE_WIDTH));
@@ -70,8 +71,7 @@ impl GraphicsCaptureApiHandler for CaptureHandler {
// The capture API delivers frames at the monitor's refresh rate, not the // The capture API delivers frames at the monitor's refresh rate, not the
// user's chosen FPS. We must tell ffmpeg the actual rate so timestamps are // user's chosen FPS. We must tell ffmpeg the actual rate so timestamps are
// correct. The fps filter in the export pipeline handles the conversion. // correct. The fps filter in the export pipeline handles the conversion.
let capture_fps = detect_monitor_refresh_rate().max(setup.fps); tracing::info!("capture: no declared framerate, size={}x{}", setup.width, setup.height);
tracing::info!("capture: ffmpeg framerate={}, size={}x{}", capture_fps, setup.width, setup.height);
let mut cmd = Command::new(&setup.ffmpeg_path); let mut cmd = Command::new(&setup.ffmpeg_path);
cmd.arg("-y") cmd.arg("-y")
@@ -80,7 +80,6 @@ impl GraphicsCaptureApiHandler for CaptureHandler {
.args(["-f", "rawvideo"]) .args(["-f", "rawvideo"])
.args(["-pixel_format", "bgra"]) .args(["-pixel_format", "bgra"])
.args(["-video_size", &format!("{}x{}", setup.width, setup.height)]) .args(["-video_size", &format!("{}x{}", setup.width, setup.height)])
.args(["-framerate", &capture_fps.to_string()])
.args(["-i", "-"]) .args(["-i", "-"])
.args(["-vf", &filter]) .args(["-vf", &filter])
.args(["-c:v", "libx264"]) .args(["-c:v", "libx264"])
@@ -176,6 +175,7 @@ pub fn primary_monitor_dims() -> Result<(u32, u32)> {
Ok((w & !1, h & !1)) Ok((w & !1, h & !1))
} }
#[allow(dead_code)]
/// Detect the primary monitor's refresh rate in Hz. /// Detect the primary monitor's refresh rate in Hz.
/// Falls back to 60 if detection fails. /// Falls back to 60 if detection fails.
fn detect_monitor_refresh_rate() -> u32 { fn detect_monitor_refresh_rate() -> u32 {