From e7995911084f438192038dd86da0d040b315afa1 Mon Sep 17 00:00:00 2001 From: Kostya Shishkov Date: Tue, 9 Jun 2026 18:57:22 +0200 Subject: [PATCH] allow custom stream tags --- src/transcoder.rs | 54 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) diff --git a/src/transcoder.rs b/src/transcoder.rs index 01b9399..d087a27 100644 --- a/src/transcoder.rs +++ b/src/transcoder.rs @@ -538,6 +538,53 @@ impl OutputQueue { } } +fn format_stream_tag(streamno: u32, arg: &str) -> Result { + let mut dst = format!("stream{streamno}tag"); + + let src = arg.as_bytes(); + let mut idx = 0; + while idx < src.len() { + match src[idx] { + b'\\' => { + idx += 1; + + if idx >= src.len() { + return Err(()); + } + match src[idx] { + b'0' => { + dst += "00"; + idx += 1; + }, + b'x' => { + idx += 1; + if idx + 1 >= src.len() { + return Err(()); + } + let c0 = src[idx]; + let c1 = src[idx + 1]; + idx += 2; + if c0.is_ascii_hexdigit() && c1.is_ascii_hexdigit() { + dst.push(c0.to_ascii_uppercase() as char); + dst.push(c1.to_ascii_uppercase() as char); + } else { + return Err(()); + } + }, + _ => return Err(()), + } + }, + b' '..=0x7E => { + dst += format!("{:02X}", src[idx]).as_str(); + idx += 1; + }, + _ => return Err(()), + } + } + + Ok(dst) +} + #[derive(Default)] pub struct QuirkSupport { pub calc_len: bool, @@ -844,6 +891,13 @@ impl Transcoder { println!("invalid volume"); } }, + "stream_tag" => { + if let Ok(tag) = format_stream_tag(streamno, oval[1]) { + self.mux_opts.push(OptionArgs{ name: "stream_tag".to_string(), value: Some(tag) }); + } else { + println!("invalid stream tag"); + } + }, _ => { ostr.enc_opts.push(OptionArgs{ name: oval[0].to_string(), value: Some(oval[1].to_string()) }); }, -- 2.39.5