From 4d521522fc653ba5886513ac96f18d0fa07f2fd4 Mon Sep 17 00:00:00 2001 From: lashman Date: Sat, 30 May 2026 01:33:50 +0300 Subject: [PATCH] fix frame counting: use ffmpeg -f null instead of missing ffprobe --- src-tauri/src/capture.rs | 32 ++++++++++++++------------------ 1 file changed, 14 insertions(+), 18 deletions(-) diff --git a/src-tauri/src/capture.rs b/src-tauri/src/capture.rs index 0d2dbe0..5613cb3 100644 --- a/src-tauri/src/capture.rs +++ b/src-tauri/src/capture.rs @@ -321,35 +321,32 @@ pub fn fix_intermediate_fps( ) -> Result<()> { use std::process::Command; - // Count frames in the intermediate file + // Count frames by running ffmpeg with null output let probe = Command::new(ffmpeg) - .args(["-hide_banner", "-i", &input.to_string_lossy()]) + .args(["-hide_banner", "-loglevel", "error", + "-i", &input.to_string_lossy(), + "-map", "0:v:0", "-c", "copy", "-f", "null", "-"]) .output() - .context("probing frame count")?; + .context("counting frames with ffmpeg")?; let stderr = String::from_utf8_lossy(&probe.stderr); - // Look for "frame= NNN" or "NNN frames" in stderr + // stderr contains: "frame= NNN fps=..." let frame_count: u32 = stderr .lines() - .find_map(|line| { - if line.contains("frames") { - line.split_whitespace() - .find(|w| w.parse::().is_ok()) - .and_then(|w| w.parse().ok()) - } else if line.contains("frame=") { - line.split("frame=") - .nth(1)? - .split_whitespace() - .next()? - .parse() - .ok() + .filter_map(|line| { + let line = line.trim(); + if line.starts_with("frame=") { + let after = line.strip_prefix("frame=")?.trim_start(); + let num_str: String = after.chars().take_while(|c| c.is_ascii_digit()).collect(); + num_str.parse().ok() } else { None } }) + .last() .unwrap_or(0); if frame_count == 0 || elapsed_secs <= 0.0 { - // Can't determine fps, just copy as-is + tracing::warn!("capture fix: could not count frames, keeping original"); let _ = std::fs::rename(input, output); return Ok(()); } @@ -374,7 +371,6 @@ pub fn fix_intermediate_fps( if status.success() { let _ = std::fs::remove_file(input); } else { - // Fallback: just rename let _ = std::fs::rename(input, output); } Ok(())