fix frame counting: use ffmpeg -f null instead of missing ffprobe
This commit is contained in:
+14
-18
@@ -321,35 +321,32 @@ pub fn fix_intermediate_fps(
|
|||||||
) -> Result<()> {
|
) -> Result<()> {
|
||||||
use std::process::Command;
|
use std::process::Command;
|
||||||
|
|
||||||
// Count frames in the intermediate file
|
// Count frames by running ffmpeg with null output
|
||||||
let probe = Command::new(ffmpeg)
|
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()
|
.output()
|
||||||
.context("probing frame count")?;
|
.context("counting frames with ffmpeg")?;
|
||||||
let stderr = String::from_utf8_lossy(&probe.stderr);
|
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
|
let frame_count: u32 = stderr
|
||||||
.lines()
|
.lines()
|
||||||
.find_map(|line| {
|
.filter_map(|line| {
|
||||||
if line.contains("frames") {
|
let line = line.trim();
|
||||||
line.split_whitespace()
|
if line.starts_with("frame=") {
|
||||||
.find(|w| w.parse::<u32>().is_ok())
|
let after = line.strip_prefix("frame=")?.trim_start();
|
||||||
.and_then(|w| w.parse().ok())
|
let num_str: String = after.chars().take_while(|c| c.is_ascii_digit()).collect();
|
||||||
} else if line.contains("frame=") {
|
num_str.parse().ok()
|
||||||
line.split("frame=")
|
|
||||||
.nth(1)?
|
|
||||||
.split_whitespace()
|
|
||||||
.next()?
|
|
||||||
.parse()
|
|
||||||
.ok()
|
|
||||||
} else {
|
} else {
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
.last()
|
||||||
.unwrap_or(0);
|
.unwrap_or(0);
|
||||||
|
|
||||||
if frame_count == 0 || elapsed_secs <= 0.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);
|
let _ = std::fs::rename(input, output);
|
||||||
return Ok(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
@@ -374,7 +371,6 @@ pub fn fix_intermediate_fps(
|
|||||||
if status.success() {
|
if status.success() {
|
||||||
let _ = std::fs::remove_file(input);
|
let _ = std::fs::remove_file(input);
|
||||||
} else {
|
} else {
|
||||||
// Fallback: just rename
|
|
||||||
let _ = std::fs::rename(input, output);
|
let _ = std::fs::rename(input, output);
|
||||||
}
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
|
|||||||
Reference in New Issue
Block a user