From e47b21140303d901f723d4638b08cdefa06a19d4 Mon Sep 17 00:00:00 2001 From: Kostya Shishkov Date: Fri, 6 Oct 2023 18:47:40 +0200 Subject: [PATCH] add an option to set the same timebase for as the first video stream --- src/main.rs | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/src/main.rs b/src/main.rs index 8199311..9811584 100644 --- a/src/main.rs +++ b/src/main.rs @@ -189,6 +189,7 @@ struct Transcoder { calc_len: bool, nframes: Vec, + global_tb: (u32, u32), } macro_rules! parse_and_apply_options { @@ -588,6 +589,10 @@ impl Transcoder { _ => {}, }; } + if self.global_tb != (0, 0) { + oopts.enc_params.tb_num = self.global_tb.0; + oopts.enc_params.tb_den = self.global_tb.1; + } if oopts.enc_params.tb_num == 0 { oopts.enc_params.tb_num = istr.tb_num; oopts.enc_params.tb_den = istr.tb_den; @@ -674,8 +679,13 @@ println!("encoder {} is not supported by output (expected {})", istr.id, istr.ge } let mut encoder = (enc_create.unwrap())(); oopts.enc_params.format = istr.get_info().get_properties(); - oopts.enc_params.tb_num = istr.tb_num; - oopts.enc_params.tb_den = istr.tb_den; + if self.global_tb != (0, 0) { + oopts.enc_params.tb_num = self.global_tb.0; + oopts.enc_params.tb_den = self.global_tb.1; + } else { + oopts.enc_params.tb_num = istr.tb_num; + oopts.enc_params.tb_den = istr.tb_den; + } let ret_eparams = encoder.negotiate_format(&oopts.enc_params); if ret_eparams.is_err() { println!("cannot negotiate encoding parameters"); @@ -1022,6 +1032,7 @@ fn main() { let full_reg = FullRegister::new(); let mut transcoder = Transcoder::new(); + let mut use_video_tb = false; let mut arg_idx = 1; let mut printed_info = false; @@ -1173,6 +1184,9 @@ fn main() { "--calc-len" => { transcoder.calc_len = true; }, + "--use-video-tb" => { + use_video_tb = true; + }, "--verbose" | "-v" => transcoder.verbose = 1, "-vv" => transcoder.verbose = 2, "-v-" => transcoder.verbose = 0, @@ -1258,6 +1272,9 @@ fn main() { let max_id = sm.iter().fold(0u32, |id, strm| id.max(strm.id)); for stream in sm.iter() { let mut newstream = (*stream).clone(); + if use_video_tb && transcoder.global_tb == (0, 0) && newstream.get_media_type() == StreamType::Video { + transcoder.global_tb = newstream.get_timebase(); + } newstream.id += start; ism.add_stream(newstream); } -- 2.39.5