]> git.nihav.org Git - nihav-encoder.git/commitdiff
add an option to set the same timebase for as the first video stream
authorKostya Shishkov <kostya.shishkov@gmail.com>
Fri, 6 Oct 2023 16:47:40 +0000 (18:47 +0200)
committerKostya Shishkov <kostya.shishkov@gmail.com>
Fri, 6 Oct 2023 16:47:40 +0000 (18:47 +0200)
src/main.rs

index 81993116df0b57c915dd5629443e7c2e98ad24be..9811584831950986053fb70e4d2de842133739c2 100644 (file)
@@ -189,6 +189,7 @@ struct Transcoder {
 
     calc_len:       bool,
     nframes:        Vec<usize>,
+    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);
         }