introduce various output frame numbering modes and some messages
authorKostya Shishkov <kostya.shishkov@gmail.com>
Tue, 11 Sep 2018 13:11:50 +0000 (15:11 +0200)
committerKostya Shishkov <kostya.shishkov@gmail.com>
Tue, 11 Sep 2018 13:11:50 +0000 (15:11 +0200)
src/main.rs

index 87c718c..b5653f4 100644 (file)
@@ -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));