Repository: nathanbabcock/ffmpeg-sidecar (language: rust)

Issue:
Broken with ffmpeg 7.0
I have been successfully using this crate for a few months on a personal project, but when I tried to update to `ffmpeg` to the new 7.0 release today, I ran into some issues.

In particular, it seems `FfmpegEvent::Progress` no longer parses correctly, causing that event to never be processed.


Discussion / hints:
Ooh, thanks for flagging this. I know 7.0 introduced multithreading in the FFmpeg CLI. I wonder if that will require any changes to this library, or if it's something smaller like a different format for progress messages.

I'll look into this — PRs welcome in the meantime.
Good news. It's an incredibly minor formatting change in the `Lsize` field of the progress message.

Before (6.0 and earlier):
```
[info] frame= 1996 fps=1984 q=-1.0 Lsize=     372kB time=00:01:19.72 bitrate=  38.2kbits/s speed=79.2x\n
```

After (7.0 onwards):

```
[info] frame=    5 fps=0.0 q=-1.0 Lsize=      10KiB time=00:00:03.00 bitrate=  27.2kbits/s speed= 283x\n
```

**TL;DR:** `kB` changed to `KiB` 😅

Fix patch:
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<FfmpegProgress> {
     .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::<u32>()
     .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);
+  }
 }


Test patch: