allow setting custom output prefixes
authorKostya Shishkov <kostya.shishkov@gmail.com>
Thu, 16 Apr 2020 11:27:22 +0000 (13:27 +0200)
committerKostya Shishkov <kostya.shishkov@gmail.com>
Thu, 16 Apr 2020 11:27:22 +0000 (13:27 +0200)
src/frmwriter.rs
src/main.rs

index f3221d09a2b440b8d8556616b34cd966c9f641a2..5b50b816b20a340bca3f478c9e7f28e24f72c700 100644 (file)
@@ -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();
index bb6a7bc1c6fde740f353f0b5b10ef7fe9b3def87..ff6baac91cea84ed7bf3dc46c6ae0465fc5eaf70 100644 (file)
@@ -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<String> = 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;
                 }