From 44e7021ec11647f175719b4d9d5c782aa37df116 Mon Sep 17 00:00:00 2001 From: William Yang Date: Sun, 18 Aug 2024 07:36:43 +1000 Subject: [PATCH] Update transcode progress if duration is greater --- src/worker_transcode.rs | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/src/worker_transcode.rs b/src/worker_transcode.rs index 9274971..acfaf9e 100644 --- a/src/worker_transcode.rs +++ b/src/worker_transcode.rs @@ -76,11 +76,19 @@ fn update_field(dst: &mut Option, src: Option) { impl TranscodeState { pub fn update_from_progress(&mut self, progress: ffmpeg::TranscodeProgress) { self.end_time_unix = get_unix_time(); - // NOTE: we get multiple progress stats including from thumbnail which makes no sense - // since we bind thumbnail to source 1, we can ignore this - if progress.frame != Some(0) { + // NOTE: On linux the frame number is sometimes 1 for the audio stream so this check doesn't make sense + // Instead we only update the progress if the transcode duration is greater than the old duration + // if progress.frame != Some(0) { + // return; + // } + let Some(new_duration) = progress.total_time_transcoded.map(|t| t.to_milliseconds()) else { return; - } + }; + if let Some(old_duration) = self.transcode_duration_milliseconds { + if old_duration > new_duration { + return; + } + }; update_field(&mut self.transcode_size_bytes, progress.size_bytes); update_field(&mut self.transcode_duration_milliseconds , progress.total_time_transcoded.map(|t| t.to_milliseconds())); update_field(&mut self.transcode_speed_bits, progress.speed_bits);