From e99e0b24d5be981ddc9e9601629d5919f7845ca7 Mon Sep 17 00:00:00 2001 From: Nathan Date: Fri, 12 Apr 2024 13:54:34 -0500 Subject: [PATCH] Fix for FFmpeg v7: "KiB" filesize units in progress updates (#33) * fix: parse KiB progress units in FFmpeg v7 * docs: explain context for progress parsing change in unit test doc comments --- src/log_parser.rs | 25 ++++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/src/log_parser.rs b/src/log_parser.rs index 6698636..1da1d54 100644 --- a/src/log_parser.rs +++ b/src/log_parser.rs @@ -417,9 +417,12 @@ pub fn try_parse_progress(mut string: &str) -> Option { .split("size=") // captures "Lsize=" AND "size=" .nth(1)? .split_whitespace() - .next()? - .trim() - .strip_suffix("kB")? + .next() + .map(|s| s.trim()) + .and_then(|s| { + s.strip_suffix("KiB") // FFmpeg v7.0 and later + .or_else(|| s.strip_suffix("kB")) // FFmpeg v6.0 and prior + })? .parse::() .ok()?; let time = string @@ -561,4 +564,20 @@ mod tests { } assert!(num_events > 1); } + + /// Test case for https://github.com/nathanbabcock/ffmpeg-sidecar/issues/31 + /// Covers regression in progress parsing introduced in FFmpeg 7.0 + /// The string format for `Lsize` units went from `kB` to `KiB` + #[test] + fn test_parse_progress_v7() { + let line = "[info] frame= 5 fps=0.0 q=-1.0 Lsize= 10KiB time=00:00:03.00 bitrate= 27.2kbits/s speed= 283x\n"; + let progress = try_parse_progress(line).unwrap(); + assert!(progress.frame == 5); + assert!(progress.fps == 0.0); + assert!(progress.q == -1.0); + assert!(progress.size_kb == 10); + assert!(progress.time == "00:00:03.00"); + assert!(progress.bitrate_kbps == 27.2); + assert!(progress.speed == 283.0); + } }