X-Git-Url: https://git.nihav.org/?p=nihav-tool.git;a=blobdiff_plain;f=src%2Fmain.rs;h=bb94c1218432969bcebead768e75deb3fbaa6b68;hp=c26e671f628ab0259dc9a8a33c7b0728ffdaa453;hb=e9c93f5f087a52d9f5c14c5f3bb821038f1b211d;hpb=e47ee41144428dafd739f6bb7fd7fc31f1c890d5 diff --git a/src/main.rs b/src/main.rs index c26e671..bb94c12 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,4 +1,5 @@ extern crate nihav_core; +extern crate nihav_registry; extern crate nihav_allstuff; use std::io::SeekFrom; @@ -8,7 +9,7 @@ use nihav_core::io::byteio::{FileReader, ByteReader}; use nihav_core::frame::*; use nihav_core::codecs::*; use nihav_core::demuxers::*; -use nihav_core::detect; +use nihav_registry::detect; use nihav_allstuff::*; use std::env; @@ -26,7 +27,7 @@ enum NumberMode { } struct FrameOutput { - prefix: &'static str, + prefix: String, streamno: usize, frameno: u64, nmode: NumberMode, @@ -42,11 +43,11 @@ impl FrameOutput { }; let vinfo = frm.get_buffer().get_video_info().unwrap(); if vinfo.get_format().is_paletted() { - write_palppm(self.prefix, self.streamno, pts, frm); + write_palppm(&self.prefix, self.streamno, pts, frm); } else if vinfo.get_format().get_model().is_yuv() { - write_pgmyuv(self.prefix, self.streamno, pts, frm); + write_pgmyuv(&self.prefix, self.streamno, pts, frm); } else if vinfo.get_format().get_model().is_rgb() { - write_ppm(self.prefix, self.streamno, pts, frm); + write_ppm(&self.prefix, self.streamno, pts, frm); } else { panic!(" unknown format"); } @@ -90,6 +91,10 @@ fn main() { let mut decode_video = true; let mut decode_audio = true; let mut nmode = NumberMode::FrmPTS; + let mut seek_time = 0u64; + let mut vpfx: Option = None; + let mut apfx: Option<&str> = None; + let mut ignore_errors = false; while (cur_arg < args.len()) && args[cur_arg].starts_with('-') { match args[cur_arg].as_str() { @@ -100,6 +105,36 @@ fn main() { "-nm=count" => { nmode = NumberMode::Counter; }, "-nm=pktpts" => { nmode = NumberMode::PktPTS; }, "-nm=frmpts" => { nmode = NumberMode::FrmPTS; }, + "-seek" => { + cur_arg += 1; + if cur_arg == args.len() { + println!("seek time missing"); + return; + } + let ret = args[cur_arg].parse::(); + if ret.is_err() { + println!("wrong seek time"); + return; + } + seek_time = ret.unwrap(); + }, + "-apfx" => { + cur_arg += 1; + if cur_arg == args.len() { + println!("name missing"); + return; + } + apfx = Some(&args[cur_arg]); + }, + "-vpfx" => { + cur_arg += 1; + if cur_arg == args.len() { + println!("name missing"); + return; + } + vpfx = Some(args[cur_arg].clone()); + }, + "-ignerr" => { ignore_errors = true; }, _ => { println!("unknown option {}", args[cur_arg]); return; }, } cur_arg += 1; @@ -132,6 +167,13 @@ println!("trying demuxer {} on {}", dmx_name, name); br.seek(SeekFrom::Start(0)).unwrap(); let mut dmx = create_demuxer(dmx_fact, &mut br).unwrap(); + if seek_time > 0 { + let ret = dmx.seek(seek_time); + if ret.is_err() { +println!(" seek error {:?}", ret.err().unwrap()); + } + } + let mut decs: Vec, Box)>> = Vec::new(); let mut sids: Vec = Vec::new(); let mut writers: Vec = Vec::new(); @@ -154,7 +196,7 @@ println!("stream {} - {} {}", i, s, info.get_name()); dec.init(&mut dsupp, info).unwrap(); decs.push(Some((dsupp, dec))); if !noout { - writers.push(Outputter::Video(FrameOutput{prefix: "", streamno: i, frameno: 1, nmode})); + writers.push(Outputter::Video(FrameOutput{prefix: if let Some(ref str) = vpfx { str.clone() } else { "out".to_string() }, streamno: i, frameno: 1, nmode})); has_out = true; } } else { @@ -171,7 +213,11 @@ println!("stream {} - {} {}", i, s, info.get_name()); dec.init(&mut dsupp, info).unwrap(); decs.push(Some((dsupp, dec))); if !noout { - let name = format!("out{:02}.wav", i); + let name = if let Some(apfx) = apfx { + format!("{}{:02}.wav", apfx, i) + } else { + format!("out{:02}.wav", i) + }; writers.push(Outputter::Audio(AudioOutput::new(&name))); has_out = true; } @@ -197,16 +243,28 @@ panic!("decoder {} not found", info.get_name()); let sr = sids.iter().position(|x| *x == streamno); let idx = sr.unwrap(); if let Some((ref mut dsupp, ref mut dec)) = decs[idx] { - let frm = dec.decode(dsupp, &pkt).unwrap(); - if !noout { - match writers[idx] { - Outputter::Video(ref mut wr) => { wr.output_frame(&pkt, frm); }, - Outputter::Audio(ref mut wr) => { wr.output_frame(&pkt, frm); }, - _ => {}, - }; - } + match dec.decode(dsupp, &pkt) { + Ok(frm) => { + if !noout { + match writers[idx] { + Outputter::Video(ref mut wr) => { wr.output_frame(&pkt, frm); }, + Outputter::Audio(ref mut wr) => { wr.output_frame(&pkt, frm); }, + _ => {}, + }; + } + }, + Err(DecoderError::MissingReference) if seek_time > 0 => { + println!("ignoring missing ref"); + }, + Err(reason) => { + println!("error decoding frame {:?}", reason); + if !ignore_errors { + break; + } + }, + }; + if pkt.get_pts() != None && lastpts.is_some() && pkt.get_pts() >= lastpts { break; } } - if pkt.get_pts() != None && lastpts.is_some() && pkt.get_pts() >= lastpts { break; } } //panic!("end"); }