]> git.nihav.org Git - nihav.git/commitdiff
mov: add another mode for inventing keyframes
authorKostya Shishkov <kostya.shishkov@gmail.com>
Sat, 4 Apr 2026 17:01:26 +0000 (19:01 +0200)
committerKostya Shishkov <kostya.shishkov@gmail.com>
Sat, 4 Apr 2026 17:01:26 +0000 (19:01 +0200)
This time treat multi-sample chunks as the ones with keyframe first
and inter frames next.

nihav-commonfmt/src/demuxers/mov/pktread.rs

index 5beb196f817600a2dd476ec6ae2933bc9517fa06..943c558d0f37f307fe73f4c47af7dbc937ac6e7c 100644 (file)
@@ -178,7 +178,7 @@ impl QTPacketDemuxer {
     }
     pub fn invent_keyframes(&mut self, intraonly: bool) {
         self.keyframes.reserve(self.time_to_sample.len());
-        if !self.time_to_sample.is_empty() {
+        if self.time_to_sample.len() > 2 {
             let mut abs_csamp = 1u64;
             for &(count, _scount) in self.time_to_sample.iter() {
                 let count = u64::from(count);
@@ -189,6 +189,27 @@ impl QTPacketDemuxer {
             for samp in 0..self.chunk_sizes.len() {
                 self.keyframes.push((samp + 1) as u32);
             }
+        } else {
+            let max_nsamps = self.sample_map.iter().fold(0u32, |mns, &(_sno, ns)| mns.max(ns));
+            if max_nsamps >= 3 {
+                let nchunks = self.chunk_offsets.len() as u32;
+                let mut sample_no = 1;
+                let mut cur_chunk = 1;
+                let mut cur_ns = 0;
+                for &(chunk_no, nsamples) in self.sample_map.iter() {
+                    while cur_chunk < chunk_no {
+                        self.keyframes.push(sample_no);
+                        sample_no += cur_ns;
+                        cur_chunk += 1;
+                    }
+                    cur_ns = nsamples;
+                }
+                while cur_chunk < nchunks {
+                    self.keyframes.push(sample_no);
+                    sample_no += cur_ns;
+                    cur_chunk += 1;
+                }
+            }
         }
     }
     fn calculate_chunk_size(&self, nsamp: usize) -> usize {