Skip to content

Commit

Permalink
Fix for FFmpeg v7: "KiB" filesize units in progress updates (#33)
Browse files Browse the repository at this point in the history
* fix: parse KiB progress units in FFmpeg v7

* docs: explain context for progress parsing change in unit test doc comments
  • Loading branch information
nathanbabcock committed Apr 12, 2024
1 parent b0eaae7 commit e99e0b2
Showing 1 changed file with 22 additions and 3 deletions.
25 changes: 22 additions & 3 deletions src/log_parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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);
}
}

0 comments on commit e99e0b2

Please sign in to comment.