]> git.nihav.org Git - nihav.git/commitdiff
mpegts/h264: slightly improve splitting raw stream into NALs
authorKostya Shishkov <kostya.shishkov@gmail.com>
Wed, 2 Dec 2026 17:14:05 +0000 (18:14 +0100)
committerKostya Shishkov <kostya.shishkov@gmail.com>
Wed, 2 Dec 2026 17:14:05 +0000 (18:14 +0100)
nihav-mpeg/src/demuxers/ts/h264.rs

index a6b4b867d7e28fa15dfdf55fc29d4141c7533248..8b53be9e777b21b59bcffd25b6ed95d637fd087d 100644 (file)
@@ -267,6 +267,7 @@ impl StreamPacketiser for RawH264Chunker {
 
         let mut nal_buf = Vec::with_capacity(65536);
         let mut is_eof = false;
+        let mut got_frame = !buf.is_empty();
         while !is_eof {
             match read_nal(&mut self.buf, &mut nal_buf, flush) {
                 Ok(()) => {},
@@ -291,9 +292,11 @@ impl StreamPacketiser for RawH264Chunker {
                             break;
                         } else {
                             put_nal(&mut buf, &nal_buf);
+                            got_frame = true;
                         }
                     },
-                    9 if !buf.is_empty() => { break; },
+                    9 if got_frame || !buf.is_empty() => { break; },
+                    9 => {},
                     _ => {
                         //println!("non-slice NAL {} @ {:X}", nal_type, self.src.tell());
                         put_nal(&mut buf, &nal_buf);
@@ -304,7 +307,7 @@ impl StreamPacketiser for RawH264Chunker {
             }
         }
 
-        if is_eof && buf.is_empty() {
+        if is_eof && !got_frame {
             return Ok(None);
         }