From 106591b47eca18d554534012e60dc4c292fa6150 Mon Sep 17 00:00:00 2001 From: Kostya Shishkov Date: Mon, 17 Mar 2025 18:51:20 +0100 Subject: [PATCH] attempt to sync packets when possible --- src/transcoder.rs | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/src/transcoder.rs b/src/transcoder.rs index aef0004..f6fb29f 100644 --- a/src/transcoder.rs +++ b/src/transcoder.rs @@ -264,7 +264,10 @@ impl OutputQueue { } pub fn get_packet(&mut self) -> Option { if self.sync { - for queue in self.packets.iter() { + let mut all_with_time = true; + let mut min_ts = None; + let mut min_sn = 0; + for (streamno, queue) in self.packets.iter().enumerate() { if queue.is_empty() { if !self.had_warning && self.packets.len() > 1 { for q in self.packets.iter() { @@ -278,9 +281,22 @@ impl OutputQueue { } return None; } + if let Some(pts) = queue[0].ts.pts { + let stream = queue[0].get_stream(); + let millis = NATimeInfo::ts_to_time(pts, 1000, stream.tb_num, stream.tb_den); + if min_ts.is_none() || min_ts > Some(millis) { + min_ts = Some(millis); + min_sn = streamno; + } + } else { + all_with_time = false; + } + } + if all_with_time && min_ts.is_some() { + self.packets[min_sn].pop_front() + } else { + self.get_last_packet() } -// todo return packet with minimum timestamp - self.get_last_packet() } else { self.get_last_packet() } -- 2.39.5