From 3eb244c4617c6f06948e7d493861f9a0455efd60 Mon Sep 17 00:00:00 2001 From: zaki Date: Thu, 10 Aug 2023 15:30:11 +0530 Subject: [PATCH] Mp4Writer playback issue for high resolution videos --- base/src/Mp4WriterSink.cpp | 18 ++++++++++-------- base/test/mp4writersink_tests.cpp | 2 +- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/base/src/Mp4WriterSink.cpp b/base/src/Mp4WriterSink.cpp index 23abe46fc..f265029ec 100644 --- a/base/src/Mp4WriterSink.cpp +++ b/base/src/Mp4WriterSink.cpp @@ -371,7 +371,6 @@ bool DetailJpeg::write(frame_container& frames) uint8_t* DetailH264::AppendSizeInNaluSeprator(short naluType, frame_sp inH264ImageFrame, size_t& frameSize) { char NaluSeprator[3] = { 00 ,00, 00 }; - char nalusepratorIframe[2] = { 00, 00 }; auto nalu = reinterpret_cast(NaluSeprator); uint spsPpsSize = spsBuffer.size() + ppsBuffer.size() + 8; if (naluType == H264Utils::H264_NAL_TYPE_SEQ_PARAM) @@ -399,13 +398,14 @@ uint8_t* DetailH264::AppendSizeInNaluSeprator(short naluType, frame_sp inH264Ima newBuffer += 1; memcpy(newBuffer, ppsBuffer.data(), ppsBuffer.size()); newBuffer += ppsBuffer.size(); - memcpy(newBuffer, nalusepratorIframe, 2); - newBuffer += 2; - //add the size of I frame to the 3rd and 4th byte of I frame's nalu seprator (00 00 frameSize frameSize 66) - newBuffer[0] = (frameSize - spsPpsSize - 4 >> 8) & 0xFF; - newBuffer[1] = frameSize - spsPpsSize - 4 & 0xFF; - newBuffer += 2; + //add the size of I frame to the I frame's nalu seprator + newBuffer[0] = (frameSize - spsPpsSize - 4 >> 24) & 0xFF; + newBuffer[1] = (frameSize - spsPpsSize - 4 >> 16) & 0xFF; + newBuffer[2] = (frameSize - spsPpsSize - 4 >> 8) & 0xFF; + newBuffer[3] = frameSize - spsPpsSize - 4 & 0xFF; + newBuffer += 4; + uint8_t* tempBuffer = reinterpret_cast(inH264ImageFrame->data()); if (naluType == H264Utils::H264_NAL_TYPE_SEQ_PARAM) { @@ -454,7 +454,9 @@ bool DetailH264::write(frame_container& frames) } uint8_t* frameData = reinterpret_cast(inH264ImageFrame->data()); - // assign size of the frame to the last two bytes of the NALU seperator for playability in default players + // assign size of the frame to the NALU seperator for playability in default players + frameData[0] = (inH264ImageFrame->size() - 4 >> 24) & 0xFF; + frameData[1] = (inH264ImageFrame->size() - 4 >> 16) & 0xFF; frameData[2] = (inH264ImageFrame->size() - 4 >> 8) & 0xFF; frameData[3] = inH264ImageFrame->size() - 4 & 0xFF; diff --git a/base/test/mp4writersink_tests.cpp b/base/test/mp4writersink_tests.cpp index 9594841eb..fb1377b52 100644 --- a/base/test/mp4writersink_tests.cpp +++ b/base/test/mp4writersink_tests.cpp @@ -38,7 +38,7 @@ void writeH264(bool readLoop, int sleepSeconds, std::string outFolderPath, int c auto h264ImageMetadata = framemetadata_sp(new H264Metadata(width, height)); fileReader->addOutputPin(h264ImageMetadata); - auto mp4WriterSinkProps = Mp4WriterSinkProps(chunkTime, 10, 100, outFolderPath); + auto mp4WriterSinkProps = Mp4WriterSinkProps(chunkTime, 10, 24, outFolderPath); mp4WriterSinkProps.logHealth = true; mp4WriterSinkProps.logHealthFrequency = 100; auto mp4WriterSink = boost::shared_ptr(new Mp4WriterSink(mp4WriterSinkProps));