]> git.vomp.tv Git - vompclient.git/commitdiff
Fix ITV2 frame counting bug
authorChris Tallon <chris@vomp.tv>
Thu, 12 Jun 2025 15:55:00 +0000 (15:55 +0000)
committerChris Tallon <chris@vomp.tv>
Thu, 12 Jun 2025 15:55:00 +0000 (15:55 +0000)
src/demuxer.cc

index 2e7e7938f4e6e48c9a01c41771e98929566e6b2f..14301313b6ef468beb88f23a8d99daa4b250cbf1 100644 (file)
@@ -451,7 +451,26 @@ u4 PESPacket::countPictureHeaders(bool h264, struct PictCountInfo& pinfo) const
          {
           pos++;
                  pattern = (pattern << 8) | data[pos];
-          if (pattern==DEMUXER_PIC_HEAD) count++;
+          if (pattern==DEMUXER_PIC_HEAD)
+          {
+            count++;
+          }
+          // Now also search for EXT_START_CODE headers and if it's a Picture Coding Extension,
+          // and the picture structure is set to interlaced - bottom field (2), reverse the frame count by 1
+          else if (pattern == 0x000001b5) // EXT_START_CODE
+          {
+            u1 extbyte1 = data[pos+1];
+
+            if ((extbyte1 & 0xF0) == 0x80) // First 4 bits are 0001
+            {
+              u1 extbyte3 = data[pos+3];
+              u1 picstruct =  extbyte3 & 0x3;
+              if (picstruct == 2)
+              {
+                count--;
+              }
+            }
+          }
          }
          return count;
   }