From 1129821fc6aa411a6e5ed4150411e983b5aac538 Mon Sep 17 00:00:00 2001 From: jcdr428 Date: Tue, 21 Jun 2022 21:45:40 +0100 Subject: [PATCH] Fix mp4 tx3g subtitles In case a chunk includes an empty length sample, seek the next sample. --- tsMuxer/movDemuxer.cpp | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/tsMuxer/movDemuxer.cpp b/tsMuxer/movDemuxer.cpp index 4f14256..ec7ffb3 100644 --- a/tsMuxer/movDemuxer.cpp +++ b/tsMuxer/movDemuxer.cpp @@ -434,12 +434,15 @@ class MovParsedSRTTrackData : public ParsedTrackPrivData uint8_t* dst = pkt->data; memcpy(dst, prefix.c_str(), prefix.length()); dst += prefix.length(); + uint32_t unitSize = 0; - uint32_t unitSize = (buff[0] << 8) | buff[1]; - buff += 2; - subtitleText = std::string((char*)buff, unitSize); - buff += unitSize; - + while (unitSize == 0) + { + unitSize = (buff[0] << 8) | buff[1]; + buff += 2; + subtitleText = std::string((char*)buff, unitSize); + buff += unitSize; + } while (buff < end) { uint64_t modifierLen = (buff[0] << 24) | (buff[1] << 16) | (buff[2] << 8) | buff[3]; @@ -524,13 +527,16 @@ class MovParsedSRTTrackData : public ParsedTrackPrivData prefix += floatToTime(endTime / 1e3, ','); prefix += '\n'; int textLen = 0; + uint32_t unitSize = 0; try { - uint32_t unitSize = (buff[0] << 8) | buff[1]; - textLen += unitSize; - buff += 2 + unitSize; - + while (unitSize == 0) + { + unitSize = (buff[0] << 8) | buff[1]; + textLen = unitSize; + buff += 2 + unitSize; + } while (buff < end) { uint64_t modifierLen = (buff[0] << 24) | (buff[1] << 16) | (buff[2] << 8) | buff[3];