From 43da6b86872827fda1c6f2a573099409f7125e52 Mon Sep 17 00:00:00 2001 From: Tatsuyuki Ishi Date: Sun, 22 Aug 2021 13:35:54 +0900 Subject: [PATCH] ffmpeg: fix frame count parsing (#339) The old code used to search for the first match that looked like a frame count. When ffmpeg emits a warning, it would also emit the frame count at the point of warning, therefore the previous implementation gave wrong frame count when it happened. Fix this by modifying the code to take the last match. Also replace the index of cap by an explicit one since this is the index of capture group (which is constant given the regex), not matches. --- av1an-core/src/ffmpeg.rs | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/av1an-core/src/ffmpeg.rs b/av1an-core/src/ffmpeg.rs index b3709a0..5674fa1 100644 --- a/av1an-core/src/ffmpeg.rs +++ b/av1an-core/src/ffmpeg.rs @@ -32,9 +32,8 @@ pub fn get_frame_count(source: impl AsRef) -> usize { let re = Regex::new(r".*frame=\s*([0-9]+)\s").unwrap(); let output = String::from_utf8(out.stderr).unwrap(); - let cap = re.captures(&output).unwrap(); - - cap[cap.len() - 1].parse::().unwrap() + let cap = re.captures_iter(&output).last().unwrap(); + cap[1].parse::().unwrap() } /// Returns vec of all keyframes