]> git.nihav.org Git - nihav-player.git/commitdiff
videoplayer: add quiet mode
authorKostya Shishkov <kostya.shiskov@gmail.com>
Sun, 31 Aug 2025 19:04:29 +0000 (21:04 +0200)
committerKostya Shishkov <kostya.shiskov@gmail.com>
Sun, 31 Aug 2025 19:04:29 +0000 (21:04 +0200)
videoplayer/src/main.rs

index 16597bdf6c88b7eee4ccfa8333c36a61f69d59a2..47ca34ebbdd5f1a646a56547f9514c1f560042bf 100644 (file)
@@ -357,6 +357,7 @@ struct Player {
 
     tkeep:          TimeKeep,
 
+    quiet:          bool,
     debug:          bool,
     osd:            OSD,
     show_osd:       Option<bool>,
@@ -398,6 +399,7 @@ impl Player {
 
             tkeep:          TimeKeep::new(),
 
+            quiet:          false,
             debug:          false,
             osd:            OSD::new(),
             show_osd:       None,
@@ -506,7 +508,9 @@ impl Player {
         for event in event_pump.poll_iter() {
             if let Event::Quit {..} = event {
                 self.end = true;
-                println!();
+                if !self.quiet {
+                    println!();
+                }
                 return Ok(true);
             }
             if let Event::Window {win_event: WindowEvent::Exposed, ..} = event {
@@ -528,12 +532,16 @@ impl Player {
                 match keycode {
                     Keycode::Escape => {
                         self.end = true;
-                        println!();
+                        if !self.quiet {
+                            println!();
+                        }
                         return Ok(true);
                     },
                     Keycode::Q if keymod.contains(Mod::RSHIFTMOD) || keymod.contains(Mod::LSHIFTMOD) => {
                         self.end = true;
-                        println!();
+                        if !self.quiet {
+                            println!();
+                        }
                         return Ok(true);
                     },
                     Keycode::Return | Keycode::KpEnter => return Ok(true),
@@ -591,7 +599,7 @@ impl Player {
                     },
                     _ => {},
                 };
-                if !self.paused {
+                if !self.paused && !self.quiet {
                     print!("{:60}\r", ' ');
                     std::io::stdout().flush().unwrap();
                 }
@@ -623,7 +631,9 @@ impl Player {
         }
         let (dmx_name, _score) = res.unwrap();
         debug_log!(self; {format!(" found demuxer {} with score {:?}", dmx_name, _score)});
-        println!("trying demuxer {} on {}", dmx_name, name);
+        if !self.quiet {
+            println!("trying demuxer {} on {}", dmx_name, name);
+        }
 
         let mut dmx_reg = RegisteredDemuxers::new();
         nihav_register_all_demuxers(&mut dmx_reg);
@@ -665,7 +675,7 @@ impl Player {
         let mut audio_dec: Option<DecoderStuff> = None;
 
         let duration = dmx.get_duration();
-        if duration != 0 {
+        if duration != 0 && !self.quiet {
             println!(" total duration {}", format_time(duration));
         }
         self.has_video = false;
@@ -680,7 +690,9 @@ impl Player {
             let info = s.get_info();
             let decfunc = dec_reg.find_decoder(info.get_name());
             let decfunc_mt = mtdec_reg.find_decoder(info.get_name());
-            println!("stream {} - {} {}", i, s, info.get_name());
+            if !self.quiet {
+                println!("stream {} - {} {}", i, s, info.get_name());
+            }
             debug_log!(self; {format!(" stream {} - {} {}", i, s, info.get_name())});
             let str_id = s.get_id();
             if info.is_video() {
@@ -695,7 +707,9 @@ impl Player {
                             height = props.get_height();
                         }
                         if dec.init(info.clone()).is_err() {
-                            println!("failed to initialise hwaccel video decoder");
+                            if !self.quiet {
+                                println!("failed to initialise hwaccel video decoder");
+                            }
                         } else {
                             video_dec = Some(DecoderStuff{ dsupp, dec: DecoderType::VideoHW(dec) });
                             self.video_str = str_id;
@@ -703,7 +717,9 @@ impl Player {
                             tb_num = tbn;
                             tb_den = tbd;
                             self.has_video = true;
-                            println!(" using hardware-accelerated decoding");
+                            if !self.quiet {
+                                println!(" using hardware-accelerated decoding");
+                            }
                             continue;
                         }
                     }
@@ -723,7 +739,7 @@ impl Player {
                             tb_den = tbd;
                             self.has_video = true;
                             continue;
-                        } else {
+                        } else if !self.quiet {
                             println!("failed to create multi-threaded decoder, falling back");
                         }
                     }
@@ -872,7 +888,9 @@ impl Player {
         'main: loop {
             let ret = self.handle_events(&mut event_pump, &mut canvas, &mut dmx, &mut disp_q);
             if matches!(ret, Ok(true) | Err(_)) {
-                println!();
+                if !self.quiet {
+                    println!();
+                }
                 break 'main;
             }
             if !self.paused {
@@ -935,10 +953,12 @@ impl Player {
                 if last_disp.elapsed().as_millis() >= 10 {
                     let c_time = self.tkeep.get_cur_time();
 
-                    if !self.debug {
-                        print!(" {}  {}% \r", format_time(c_time), self.acontrol.get_volume());
-                    } else {
-                        print!(" {}  {}  {}% {:3} {:6}\r", format_time(c_time), if self.vcontrol.is_yuv() { 'Y' } else { 'R' }, self.acontrol.get_volume(), (disp_q.end + disp_q.len - disp_q.start) % disp_q.len, self.acontrol.get_fill());
+                    if !self.quiet {
+                        if !self.debug {
+                            print!(" {}  {}% \r", format_time(c_time), self.acontrol.get_volume());
+                        } else {
+                            print!(" {}  {}  {}% {:3} {:6}\r", format_time(c_time), if self.vcontrol.is_yuv() { 'Y' } else { 'R' }, self.acontrol.get_volume(), (disp_q.end + disp_q.len - disp_q.start) % disp_q.len, self.acontrol.get_fill());
+                        }
                     }
                     std::io::stdout().flush().unwrap();
                     last_disp = Instant::now();
@@ -958,7 +978,9 @@ impl Player {
                 thread::sleep(Duration::from_millis(20));
             }
         }
-        println!();
+        if !self.quiet {
+            println!();
+        }
         std::mem::swap(&mut self.vcontrol, &mut new_vcontrol);
         new_vcontrol.finish();
         std::mem::swap(&mut self.acontrol, &mut new_acontrol);
@@ -1044,6 +1066,9 @@ fn main() {
                     }
                 }
             },
+            "-quiet" => {
+                player.quiet = true;
+            },
             "-osd" => {
                 player.show_osd = Some(true);
             },