From 4c2eeb96c82250e85d6846d2156a28980d3d4d41 Mon Sep 17 00:00:00 2001 From: Erik Zandvliet Date: Wed, 6 Apr 2016 11:38:49 +0200 Subject: [PATCH] Fix for handling negative h264 offsets in mp4 --- lib/mp4_generic.cpp | 6 ++++-- lib/mp4_generic.h | 2 +- src/input/input_mp4.cpp | 10 +++++----- src/input/input_mp4.h | 6 +++--- src/output/output_progressive_mp4.cpp | 2 +- 5 files changed, 14 insertions(+), 12 deletions(-) diff --git a/lib/mp4_generic.cpp b/lib/mp4_generic.cpp index 1ccceb5e..c0cdcc79 100644 --- a/lib/mp4_generic.cpp +++ b/lib/mp4_generic.cpp @@ -2575,7 +2575,8 @@ namespace MP4 { setEntryCount(no + 1); } setInt32(newCTTSEntry.sampleCount, 8 + no * 8); - setInt32(newCTTSEntry.sampleOffset, 8 + (no * 8) + 4); + setInt32(*(reinterpret_cast(&newCTTSEntry.sampleOffset)), 8 + (no * 8) + 4); + } CTTSEntry CTTS::getCTTSEntry(uint32_t no) { @@ -2585,7 +2586,8 @@ namespace MP4 { return inval; } retval.sampleCount = getInt32(8 + (no * 8)); - retval.sampleOffset = getInt32(8 + (no * 8) + 4); + uint32_t tmp = getInt32(8 + (no * 8) + 4); + retval.sampleOffset = *(reinterpret_cast(&tmp)); return retval; } diff --git a/lib/mp4_generic.h b/lib/mp4_generic.h index 093e62e4..d2dc7b04 100644 --- a/lib/mp4_generic.h +++ b/lib/mp4_generic.h @@ -538,7 +538,7 @@ namespace MP4 { struct CTTSEntry { uint32_t sampleCount; - uint32_t sampleOffset; + int32_t sampleOffset; }; class CTTS: public fullBox { diff --git a/src/input/input_mp4.cpp b/src/input/input_mp4.cpp index 77baa0db..9416b8da 100644 --- a/src/input/input_mp4.cpp +++ b/src/input/input_mp4.cpp @@ -100,7 +100,7 @@ namespace Mist { }//rof trak } - void mp4TrackHeader::getPart(long unsigned int index, long long unsigned int & offset,unsigned int& size, long long unsigned int & timestamp, long long unsigned int & timeOffset){ + void mp4TrackHeader::getPart(long unsigned int index, long long unsigned int & offset,unsigned int& size, long long unsigned int & timestamp, int32_t & timeOffset){ if (index < sampleIndex){ @@ -171,7 +171,7 @@ namespace Mist { while (offsetIndex < cttsBox.getEntryCount()){ tmpCTTS = cttsBox.getCTTSEntry(offsetIndex); if ((index - offsetPos) < tmpCTTS.sampleCount){ - timeOffset = (tmpCTTS.sampleOffset*1000)/timeScale; + timeOffset = (tmpCTTS.sampleOffset*1000)/(int32_t)timeScale; break; } offsetPos += tmpCTTS.sampleCount; @@ -518,7 +518,7 @@ namespace Mist { cttsIndex++; cttsEntryRead = 0; } - BsetPart.timeOffset = (cttsEntry.sampleOffset * 1000)/timeScale; + BsetPart.timeOffset = (cttsEntry.sampleOffset * 1000)/(int32_t)timeScale; }else{ BsetPart.timeOffset = 0; } @@ -529,9 +529,9 @@ namespace Mist { /// \todo Fix this. This makes no sense whatsoever. This isn't frame per kilosecond, but milli-STCO-entries per second. // (A single STCO entry may be more than 1 part, and 1 part may be a partial frame or multiple frames) if (stcoIs64){ - myMeta.tracks[trackNo].fpks = (((double)(((MP4::CO64*)&stcoBox)->getEntryCount()*1000))/((totaldur*1000)/timeScale))*1000; + myMeta.tracks[trackNo].fpks = (((double)(((MP4::CO64*)&stcoBox)->getEntryCount()*1000))/((totaldur*1000)))*1000; }else{ - myMeta.tracks[trackNo].fpks = (((double)(stcoBox.getEntryCount()*1000))/((totaldur*1000)/timeScale))*1000; + myMeta.tracks[trackNo].fpks = (((double)(stcoBox.getEntryCount()*1000))/((totaldur*1000)))*1000; } } }//fi stbl diff --git a/src/input/input_mp4.h b/src/input/input_mp4.h index 2a3ac9e8..6a8a3385 100644 --- a/src/input/input_mp4.h +++ b/src/input/input_mp4.h @@ -23,7 +23,7 @@ namespace Mist { return false; } long long unsigned int time; - long long unsigned int offset; + int32_t offset; unsigned int trackID; long long unsigned int bpos; unsigned int size; @@ -52,7 +52,7 @@ namespace Mist { long long unsigned int bpos; long long unsigned int size; long long unsigned int stcoNr; - long unsigned int timeOffset; + int32_t timeOffset; bool keyframe; }; @@ -67,7 +67,7 @@ namespace Mist { MP4::CTTS cttsBox; MP4::STSC stscBox; long unsigned int timeScale; - void getPart(long unsigned int index, long long unsigned int & offset,unsigned int& size, long long unsigned int & timestamp, long long unsigned int & timeOffset); + void getPart(long unsigned int index, long long unsigned int & offset,unsigned int& size, long long unsigned int & timestamp, int32_t & timeOffset); long unsigned int size(); private: bool initialised; diff --git a/src/output/output_progressive_mp4.cpp b/src/output/output_progressive_mp4.cpp index 6313bc13..9b226ccc 100644 --- a/src/output/output_progressive_mp4.cpp +++ b/src/output/output_progressive_mp4.cpp @@ -7,7 +7,7 @@ namespace Mist { OutProgressiveMP4::OutProgressiveMP4(Socket::Connection & conn) : HTTPOutput(conn) { - completeKeysOnly = true; + completeKeysOnly = false; } OutProgressiveMP4::~OutProgressiveMP4() {}