From: Kostya Shishkov Date: Thu, 16 Apr 2020 11:27:22 +0000 (+0200) Subject: allow setting custom output prefixes X-Git-Url: https://git.nihav.org/?a=commitdiff_plain;h=7437145d254f1852f5b594e56e20124761bb5b02;p=nihav-tool.git allow setting custom output prefixes --- diff --git a/src/frmwriter.rs b/src/frmwriter.rs index f3221d0..5b50b81 100644 --- a/src/frmwriter.rs +++ b/src/frmwriter.rs @@ -6,7 +6,7 @@ use std::fs::File; pub fn write_pgmyuv(pfx: &str, strno: usize, num: u64, frm: NAFrameRef) { if let NABufferType::None = frm.get_buffer() { return; } - let name = format!("{}out{:02}_{:08}.pgm", pfx, strno, num); + let name = format!("{}{:02}_{:08}.pgm", pfx, strno, num); let mut ofile = File::create(name).unwrap(); let buf = frm.get_buffer().get_vbuf().unwrap(); let is_flipped = buf.get_info().is_flipped(); @@ -96,7 +96,7 @@ pub fn write_pgmyuv(pfx: &str, strno: usize, num: u64, frm: NAFrameRef) { } pub fn write_palppm(pfx: &str, strno: usize, num: u64, frm: NAFrameRef) { - let name = format!("{}out{:02}_{:08}.ppm", pfx, strno, num); + let name = format!("{}{:02}_{:08}.ppm", pfx, strno, num); let mut ofile = File::create(name).unwrap(); let buf = frm.get_buffer().get_vbuf().unwrap(); let (w, h) = buf.get_dimensions(0); @@ -131,7 +131,7 @@ pub fn write_palppm(pfx: &str, strno: usize, num: u64, frm: NAFrameRef) { } pub fn write_ppm(pfx: &str, strno: usize, num: u64, frm: NAFrameRef) { - let name = format!("{}out{:02}_{:08}.ppm", pfx, strno, num); + let name = format!("{}{:02}_{:08}.ppm", pfx, strno, num); let mut ofile = File::create(name).unwrap(); let info = frm.get_buffer().get_video_info().unwrap(); let flipped = info.is_flipped(); diff --git a/src/main.rs b/src/main.rs index bb6a7bc..ff6baac 100644 --- a/src/main.rs +++ b/src/main.rs @@ -27,7 +27,7 @@ enum NumberMode { } struct FrameOutput { - prefix: &'static str, + prefix: String, streamno: usize, frameno: u64, nmode: NumberMode, @@ -43,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"); } @@ -92,6 +92,8 @@ fn main() { 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; while (cur_arg < args.len()) && args[cur_arg].starts_with('-') { match args[cur_arg].as_str() { @@ -115,6 +117,22 @@ fn main() { } 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()); + }, _ => { println!("unknown option {}", args[cur_arg]); return; }, } cur_arg += 1; @@ -176,7 +194,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 { @@ -193,7 +211,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; }