Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 26 additions & 15 deletions src/log_parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -511,6 +511,7 @@ fn try_parse_video_stream(mut comma_iter: CommaIter) -> Option<StreamTypeSpecifi
}

/// Parse a progress update line from ffmpeg.
/// For audio-only progress events, the `frame`, `fps`, and `q` fields will be `0`.
///
Comment thread
nathanbabcock marked this conversation as resolved.
/// ## Example
/// ```rust
Expand All @@ -532,25 +533,22 @@ pub fn try_parse_progress(mut string: &str) -> Option<FfmpegProgress> {

let frame = string
.split("frame=")
.nth(1)?
.split_whitespace()
.next()?
.parse::<u32>()
.ok()?;
.nth(1)
.and_then(|s| s.split_whitespace().next())
.and_then(|s| s.parse::<u32>().ok())
.unwrap_or(0);
let fps = string
.split("fps=")
.nth(1)?
.split_whitespace()
.next()?
.parse::<f32>()
.ok()?;
.nth(1)
.and_then(|s| s.split_whitespace().next())
.and_then(|s| s.parse::<f32>().ok())
.unwrap_or(0.0);
let q = string
.split("q=")
.nth(1)?
.split_whitespace()
.next()?
.parse::<f32>()
.ok()?;
.nth(1)
.and_then(|s| s.split_whitespace().next())
.and_then(|s| s.parse::<f32>().ok())
.unwrap_or(0.0);
let size_kb = string
.split("size=") // captures "Lsize=" AND "size="
.nth(1)?
Expand Down Expand Up @@ -769,4 +767,17 @@ mod tests {

Ok(())
}

#[test]
fn test_audio_progress() {
let line = "[info] size= 66kB time=00:00:02.21 bitrate= 245.0kbits/s speed=1.07x\n";
let progress = try_parse_progress(line).unwrap();
assert!(progress.frame == 0);
assert!(progress.fps == 0.0);
assert!(progress.q == 0.0);
Comment thread
nathanbabcock marked this conversation as resolved.
assert!(progress.size_kb == 66);
Comment thread
nathanbabcock marked this conversation as resolved.
assert!(progress.time == "00:00:02.21");
assert!(progress.bitrate_kbps == 245.0);
assert!(progress.speed == 1.07);
Comment thread
nathanbabcock marked this conversation as resolved.
Comment thread
nathanbabcock marked this conversation as resolved.
Comment thread
nathanbabcock marked this conversation as resolved.
Comment thread
nathanbabcock marked this conversation as resolved.
Comment thread
nathanbabcock marked this conversation as resolved.
}
}
Loading