fix frame counting: use ffmpeg -f null instead of missing ffprobe

This commit is contained in:
2026-05-30 01:33:50 +03:00
parent 8b91028a42
commit 4d521522fc
+14 -18
View File
@@ -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::<u32>().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(())