From 2d6439449a7f212270bddb308cbed616699a06d4 Mon Sep 17 00:00:00 2001 From: jcdr428 Date: Mon, 25 Sep 2023 17:13:09 +0100 Subject: [PATCH] Fix CLPI for H.264 BFF (Bottom Field First) streams Fixes issue #700. --- tsMuxer/h264StreamReader.cpp | 5 ++++- tsMuxer/h264StreamReader.h | 1 + 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/tsMuxer/h264StreamReader.cpp b/tsMuxer/h264StreamReader.cpp index 505c7a2b..63d0ac1d 100644 --- a/tsMuxer/h264StreamReader.cpp +++ b/tsMuxer/h264StreamReader.cpp @@ -14,6 +14,7 @@ H264StreamReader::H264StreamReader() m_frameNum = 0; m_lastMessageLen = -1; m_forceLsbDiv = 0; + m_fieldFirst = 0; prevPicOrderCntMsb = prevPicOrderCntLsb = 0; m_iFramePtsOffset = 0; m_isFirstFrame = true; @@ -672,6 +673,8 @@ void H264StreamReader::additionalStreamCheck(uint8_t *buff, uint8_t *end) int picOrder = calcPicOrder(slice); if (slice.isIDR()) frameNum = -1; + if (slice.isIFrame()) + m_fieldFirst = slice.bottom_field_flag; checkPyramid(++frameNum, &picOrder, true); } break; @@ -1079,7 +1082,7 @@ int H264StreamReader::processSliceNal(uint8_t *buff) if (slice.first_mb_in_slice != 0) return 0; - if (slice.bottom_field_flag == 1) // insrease PTS/DTS only for whole frame + if (m_fieldFirst != slice.bottom_field_flag) // insrease PTS/DTS only for whole frame return 0; if (detectPrimaryPicType(slice, buff) != 0) diff --git a/tsMuxer/h264StreamReader.h b/tsMuxer/h264StreamReader.h index dc31ab7b..248df682 100644 --- a/tsMuxer/h264StreamReader.h +++ b/tsMuxer/h264StreamReader.h @@ -92,6 +92,7 @@ class H264StreamReader final : public MPEGStreamReader int prevPicOrderCntMsb; int prevPicOrderCntLsb; int m_forceLsbDiv; + int m_fieldFirst; int m_lastMessageLen; bool m_isFirstFrame; SeiMethod m_insertSEIMethod;