From: Kostya Shishkov Date: Mon, 17 Mar 2025 17:55:15 +0000 (+0100) Subject: retrieve last (possibly unsynchronised) packets at the end X-Git-Url: https://git.nihav.org/?a=commitdiff_plain;h=a5c44ebf3e99fc57b56c931bd8b42f63617ed298;p=nihav-encoder.git retrieve last (possibly unsynchronised) packets at the end --- diff --git a/src/main.rs b/src/main.rs index 8c456b3..92ee64c 100644 --- a/src/main.rs +++ b/src/main.rs @@ -110,7 +110,7 @@ macro_rules! parse_id { } } -fn retrieve_packets(transcoder: &mut Transcoder, mux: &mut Muxer, vdata_size: &mut usize, adata_size: &mut usize) -> bool { +fn retrieve_packets(transcoder: &mut Transcoder, mux: &mut Muxer, vdata_size: &mut usize, adata_size: &mut usize, end: bool) -> bool { while let Some(pkt) = transcoder.queue.get_packet() { if transcoder.end != NATimePoint::None && !pkt.ts.less_than(transcoder.end) { return false; @@ -126,6 +126,23 @@ fn retrieve_packets(transcoder: &mut Transcoder, mux: &mut Muxer, vdata_size: &m return false; } } + if end { + while let Some(pkt) = transcoder.queue.get_last_packet() { + if transcoder.end != NATimePoint::None && !pkt.ts.less_than(transcoder.end) { + return false; + } + let pkt_size = pkt.get_buffer().len(); + match pkt.get_stream().get_media_type() { + StreamType::Video => { *vdata_size += pkt_size; }, + StreamType::Audio => { *adata_size += pkt_size; }, + _ => {}, + }; + if mux.mux_frame(pkt).is_err() { + println!("error muxing packet"); + return false; + } + } + } true } @@ -632,7 +649,7 @@ fn main() { }, }; - if !retrieve_packets(&mut transcoder, &mut mux, &mut vdata_size, &mut adata_size) { + if !retrieve_packets(&mut transcoder, &mut mux, &mut vdata_size, &mut adata_size, false) { break; } } @@ -661,7 +678,7 @@ fn main() { }; } - retrieve_packets(&mut transcoder, &mut mux, &mut vdata_size, &mut adata_size); + retrieve_packets(&mut transcoder, &mut mux, &mut vdata_size, &mut adata_size, true); if transcoder.verbose > 0 { println!();