Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mp4 Writer video playback compatibility fix for high resolution videos #287

Merged
merged 2 commits into from
Aug 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 10 additions & 8 deletions base/src/Mp4WriterSink.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<uint8_t*>(NaluSeprator);
uint spsPpsSize = spsBuffer.size() + ppsBuffer.size() + 8;
if (naluType == H264Utils::H264_NAL_TYPE_SEQ_PARAM)
Expand Down Expand Up @@ -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<uint8_t*>(inH264ImageFrame->data());
if (naluType == H264Utils::H264_NAL_TYPE_SEQ_PARAM)
{
Expand Down Expand Up @@ -454,7 +454,9 @@ bool DetailH264::write(frame_container& frames)
}

uint8_t* frameData = reinterpret_cast<uint8_t*>(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;

Expand Down
2 changes: 1 addition & 1 deletion base/test/mp4writersink_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<Module>(new Mp4WriterSink(mp4WriterSinkProps));
Expand Down
Loading