From 27b080238526aa77099314808daeb838a350335a Mon Sep 17 00:00:00 2001 From: Chris Tallon Date: Thu, 12 Jun 2025 15:55:00 +0000 Subject: [PATCH] Fix ITV2 frame counting bug --- src/demuxer.cc | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/src/demuxer.cc b/src/demuxer.cc index 2e7e793..1430131 100644 --- a/src/demuxer.cc +++ b/src/demuxer.cc @@ -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; } -- 2.39.5