From 0baea4d730c731d63c7ec3f0aed4c42cd40c514f Mon Sep 17 00:00:00 2001 From: Kostya Shishkov Date: Mon, 22 Dec 2025 16:53:26 +0100 Subject: [PATCH] videoplayer: allow selecting audio and video stream to play --- videoplayer/src/main.rs | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/videoplayer/src/main.rs b/videoplayer/src/main.rs index 12438b4..5321a50 100644 --- a/videoplayer/src/main.rs +++ b/videoplayer/src/main.rs @@ -375,7 +375,9 @@ struct Player { has_video: bool, has_audio: bool, video_str: u32, + force_vstr: Option, audio_str: u32, + force_astr: Option, 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::() { + 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::() { + player.force_astr = Some(str_id); + } else { + println!("invalid stream number"); + } + } + }, _ => { window = player.play(window, arg, seek_time); if player.end { break; } -- 2.39.5