]> git.nihav.org Git - nihav-player.git/commitdiff
videoplayer: allow selecting audio and video stream to play
authorKostya Shishkov <kostya.shishkov@gmail.com>
Mon, 22 Dec 2025 15:53:26 +0000 (16:53 +0100)
committerKostya Shishkov <kostya.shishkov@gmail.com>
Mon, 22 Dec 2025 15:53:26 +0000 (16:53 +0100)
videoplayer/src/main.rs

index 12438b465653bd909cc6d041985117c229349be0..5321a5013131bc5e5487ab8354a3b3b2977b4d6a 100644 (file)
@@ -375,7 +375,9 @@ struct Player {
     has_video:      bool,
     has_audio:      bool,
     video_str:      u32,
+    force_vstr:     Option<u32>,
     audio_str:      u32,
+    force_astr:     Option<u32>,
     sc_size:        ScaleSize,
 
     vthreads:       usize,
@@ -420,7 +422,9 @@ impl Player {
             has_video:      false,
             has_audio:      false,
             video_str:      0,
+            force_vstr:     None,
             audio_str:      0,
+            force_astr:     None,
             sc_size:        ScaleSize::Auto,
 
             vthreads:       3,
@@ -737,6 +741,9 @@ impl Player {
             debug_log!(self; {format!(" stream {} - {} {}", i, s, info.get_name())});
             let str_id = s.get_id();
             if info.is_video() {
+                if self.force_vstr.is_some() && self.force_vstr != Some(str_id) {
+                    continue;
+                }
                 if video_dec.is_none() && self.play_video {
                     #[cfg(feature="hwaccel")]
                     if info.get_name() == "h264" && self.use_hwaccel {
@@ -818,6 +825,9 @@ impl Player {
                     }
                 }
             } else if info.is_audio() {
+                if self.force_astr.is_some() && self.force_astr != Some(str_id) {
+                    continue;
+                }
                 if audio_dec.is_none() && self.play_audio {
                     if let Some(decfunc) = decfunc {
                         let mut dec = (decfunc)();
@@ -1166,6 +1176,28 @@ fn main() {
             "-ignosd" => {
                 player.show_osd = None;
             },
+            "-vstr" => {
+                if let Some(arg) = aiter.next() {
+                    if arg == "auto" || arg == "-1" {
+                        player.force_vstr = None;
+                    } else if let Ok(str_id) = arg.parse::<u32>() {
+                        player.force_vstr = Some(str_id);
+                    } else {
+                        println!("invalid stream number");
+                    }
+                }
+            },
+            "-astr" => {
+                if let Some(arg) = aiter.next() {
+                    if arg == "auto" || arg == "-1" {
+                        player.force_astr = None;
+                    } else if let Ok(str_id) = arg.parse::<u32>() {
+                        player.force_astr = Some(str_id);
+                    } else {
+                        println!("invalid stream number");
+                    }
+                }
+            },
             _ => {
                 window = player.play(window, arg, seek_time);
                 if player.end { break; }