From 44939c842b9aa76838dae8064d1b13bb47960efb Mon Sep 17 00:00:00 2001 From: Kostya Shishkov Date: Tue, 11 Sep 2018 15:11:50 +0200 Subject: [PATCH] introduce various output frame numbering modes and some messages --- src/main.rs | 30 ++++++++++++++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) diff --git a/src/main.rs b/src/main.rs index 87c718c..b5653f4 100644 --- a/src/main.rs +++ b/src/main.rs @@ -16,16 +16,29 @@ use frmwriter::*; mod wavwriter; use wavwriter::WavWriter; +#[derive(Clone,Copy,PartialEq)] +enum NumberMode { + Counter, + PktPTS, + FrmPTS, +} + struct FrameOutput { prefix: &'static str, streamno: usize, + frameno: u64, + nmode: NumberMode, } impl FrameOutput { fn output_frame(&mut self, pkt: &NAPacket, frmref: NAFrameRef) { let frm = frmref.borrow(); if frm.get_frame_type() != FrameType::Skip { - let pts = if let Some(pt) = frm.get_pts() { pt } else { pkt.get_pts().unwrap() }; + let pts = match self.nmode { + NumberMode::Counter => { self.frameno }, + NumberMode::PktPTS => { pkt.get_pts().unwrap() }, + NumberMode::FrmPTS => { if let Some(pt) = frm.get_pts() { pt } else { pkt.get_pts().unwrap() } }, + }; let frmbuf = frm.get_buffer().get_vbuf().unwrap(); if frmbuf.get_info().get_format().is_paletted() { write_palppm(self.prefix, self.streamno, pts, frm); @@ -33,6 +46,7 @@ impl FrameOutput { write_pgmyuv(self.prefix, self.streamno, pts, frm); } } + self.frameno += 1; } } @@ -70,6 +84,7 @@ fn main() { let mut noout = false; let mut decode_video = true; let mut decode_audio = true; + let mut nmode = NumberMode::FrmPTS; while (cur_arg < args.len()) && (args[cur_arg].chars().next().unwrap() == '-') { match args[cur_arg].as_str() { @@ -77,6 +92,9 @@ fn main() { "-noout" => { noout = true; }, "-an" => { decode_audio = false; }, "-vn" => { decode_video = false; }, + "-nm=count" => { nmode = NumberMode::Counter; }, + "-nm=pktpts" => { nmode = NumberMode::PktPTS; }, + "-nm=frmpts" => { nmode = NumberMode::FrmPTS; }, _ => { println!("unknown option {}", args[cur_arg]); return; }, } cur_arg += 1; @@ -113,11 +131,15 @@ println!("stream {} - {} {}", i, s, info.get_name()); let mut has_out = false; if info.is_video() { if decode_video { + if decfunc.is_none() { + println!("no video decoder found!"); + return; + } let mut dec = (decfunc.unwrap())(); dec.init(info).unwrap(); decs.push(Some(dec)); if !noout { - writers.push(Outputter::Video(FrameOutput{prefix: "", streamno: i})); + writers.push(Outputter::Video(FrameOutput{prefix: "", streamno: i, frameno: 1, nmode: nmode})); has_out = true; } } else { @@ -125,6 +147,10 @@ println!("stream {} - {} {}", i, s, info.get_name()); } } else if info.is_audio() { if decode_audio { + if decfunc.is_none() { + println!("no audio decoder found!"); + return; + } let mut dec = (decfunc.unwrap())(); dec.init(info).unwrap(); decs.push(Some(dec)); -- 2.39.5