X-Git-Url: https://git.nihav.org/?p=nihav-tool.git;a=blobdiff_plain;f=src%2Fmain.rs;h=b57e3611953ab6ad83b093f779416ebec465b320;hp=c1f44281ed156e8155a19d1085c85ac594d10652;hb=417ba15eea92979575a8452f6b34162330b56e1f;hpb=cd9ece3c2316fe74631e33347328dfe3d8d21a65 diff --git a/src/main.rs b/src/main.rs index c1f4428..b57e361 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; @@ -104,20 +122,27 @@ println!("trying demuxer {} on {}", dmx_name, name); let mut dmx = create_demuxer(dmx_fact, &mut br).unwrap(); let mut decs: Vec>> = Vec::new(); + let mut sids: Vec = Vec::new(); let mut writers: Vec = Vec::new(); for i in 0..dmx.get_num_streams() { let s = dmx.get_stream(i).unwrap(); let info = s.get_info(); let decfunc = find_decoder(info.get_name()); println!("stream {} - {} {}", i, s, info.get_name()); + let str_id = s.get_id(); let mut has_out = false; + sids.push(str_id); 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 +150,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)); @@ -151,18 +180,20 @@ panic!("decoder {} not found", info.get_name()); if e == DemuxerError::EOF { break; } } let pkt = pktres.unwrap(); - let streamno = pkt.get_stream().get_id() as usize; - if let Some(ref mut dec) = decs[streamno] { + let streamno = pkt.get_stream().get_id(); + let sr = sids.iter().position(|x| *x == streamno); + let idx = sr.unwrap(); + if let Some(ref mut dec) = decs[idx] { let frm = dec.decode(&pkt).unwrap(); if !noout { - match writers[streamno] { + match writers[idx] { Outputter::Video(ref mut wr) => { wr.output_frame(&pkt, frm); }, Outputter::Audio(ref mut wr) => { wr.output_frame(&pkt, frm); }, _ => {}, }; } } - if pkt.get_pts() != None && pkt.get_pts() >= lastpts { break; } + if pkt.get_pts() != None && lastpts.is_some() && pkt.get_pts() >= lastpts { break; } } //panic!("end"); }