Added MP4 subtitle input durations

This commit is contained in:
Thulinma 2017-11-17 15:48:07 +01:00
parent 307d14f901
commit 891696df83
2 changed files with 27 additions and 9 deletions

View file

@ -60,7 +60,7 @@ namespace Mist{
hasCTTS = cttsBox.isType("ctts"); hasCTTS = cttsBox.isType("ctts");
} }
void mp4TrackHeader::getPart(uint64_t index, uint64_t & offset, uint32_t & size, uint64_t & timestamp, int32_t & timeOffset){ void mp4TrackHeader::getPart(uint64_t index, uint64_t & offset, uint32_t & size, uint64_t & timestamp, int32_t & timeOffset, uint64_t & duration){
if (index < sampleIndex){ if (index < sampleIndex){
sampleIndex = 0; sampleIndex = 0;
stscStart = 0; stscStart = 0;
@ -114,6 +114,24 @@ namespace Mist{
++deltaIndex; ++deltaIndex;
} }
timestamp = ((deltaTotal + ((index-deltaPos) * tmpSTTS.sampleDelta))*1000) / timeScale; timestamp = ((deltaTotal + ((index-deltaPos) * tmpSTTS.sampleDelta))*1000) / timeScale;
duration = 0;
{
uint64_t tmpIndex = deltaIndex;
uint64_t tmpPos = deltaPos;
uint64_t tmpTotal = deltaTotal;
while (tmpIndex < sttsCount){
tmpSTTS = sttsBox.getSTTSEntry(tmpIndex);
if ((index+1 - tmpPos) < tmpSTTS.sampleCount){
duration = (((tmpTotal + ((index+1-tmpPos) * tmpSTTS.sampleDelta))*1000) / timeScale) - timestamp;
break;
}
tmpTotal += tmpSTTS.sampleCount * tmpSTTS.sampleDelta;
tmpPos += tmpSTTS.sampleCount;
++tmpIndex;
}
}
initialised = true; initialised = true;
if (index < offsetPos){ if (index < offsetPos){
@ -486,11 +504,10 @@ namespace Mist{
thisPack["trackid"] = (long long)curPart.trackID; thisPack["trackid"] = (long long)curPart.trackID;
thisPack["bpos"] = (long long)curPart.bpos; //(long long)fileSource.tellg(); thisPack["bpos"] = (long long)curPart.bpos; //(long long)fileSource.tellg();
thisPack["data"] = std::string(data+2,txtLen); thisPack["data"] = std::string(data+2,txtLen);
// thisPack["index"] = index;
thisPack["time"] = (long long)curPart.time; thisPack["time"] = (long long)curPart.time;
thisPack["duration"] = 1000; if (curPart.duration){
thisPack["duration"] = (long long)curPart.duration;
// thisPack["time"] = (long long)timestamp; }
thisPack["keyframe"] = true; thisPack["keyframe"] = true;
// Write the json value to lastpack // Write the json value to lastpack
std::string tmpStr = thisPack.toNetPacked(); std::string tmpStr = thisPack.toNetPacked();
@ -506,7 +523,7 @@ namespace Mist{
//get the next part for this track //get the next part for this track
curPart.index ++; curPart.index ++;
if (curPart.index < headerData[curPart.trackID].size()){ if (curPart.index < headerData[curPart.trackID].size()){
headerData[curPart.trackID].getPart(curPart.index, curPart.bpos, curPart.size, curPart.time, curPart.offset); headerData[curPart.trackID].getPart(curPart.index, curPart.bpos, curPart.size, curPart.time, curPart.offset, curPart.duration);
curPositions.insert(curPart); curPositions.insert(curPart);
} }
} }
@ -525,7 +542,7 @@ namespace Mist{
//for all indexes in those tracks //for all indexes in those tracks
for (unsigned int i = 0; i < headerData[*it].size(); i++){ for (unsigned int i = 0; i < headerData[*it].size(); i++){
//if time > seekTime //if time > seekTime
headerData[*it].getPart(i, addPart.bpos, addPart.size, addPart.time, addPart.offset); headerData[*it].getPart(i, addPart.bpos, addPart.size, addPart.time, addPart.offset, addPart.duration);
//check for keyframe time in myMeta and update nextKeyframe //check for keyframe time in myMeta and update nextKeyframe
// //
if (myMeta.tracks[*it].keys[(nextKeyframe[*it])].getTime() < addPart.time){ if (myMeta.tracks[*it].keys[(nextKeyframe[*it])].getTime() < addPart.time){

View file

@ -5,7 +5,7 @@
namespace Mist { namespace Mist {
class mp4PartTime{ class mp4PartTime{
public: public:
mp4PartTime() : time(0), offset(0), trackID(0), bpos(0), size(0), index(0) {} mp4PartTime() : time(0), offset(0), trackID(0), bpos(0), size(0), index(0), duration(0) {}
bool operator < (const mp4PartTime & rhs) const { bool operator < (const mp4PartTime & rhs) const {
if (time < rhs.time){ if (time < rhs.time){
return true; return true;
@ -19,6 +19,7 @@ namespace Mist {
return (trackID == rhs.trackID && bpos < rhs.bpos); return (trackID == rhs.trackID && bpos < rhs.bpos);
} }
uint64_t time; uint64_t time;
uint64_t duration;
int32_t offset; int32_t offset;
size_t trackID; size_t trackID;
uint64_t bpos; uint64_t bpos;
@ -60,7 +61,7 @@ namespace Mist {
MP4::CTTS cttsBox; MP4::CTTS cttsBox;
MP4::STSC stscBox; MP4::STSC stscBox;
uint64_t timeScale; uint64_t timeScale;
void getPart(uint64_t index, uint64_t & offset, uint32_t & size, uint64_t & timestamp, int32_t & timeOffset); void getPart(uint64_t index, uint64_t & offset, uint32_t & size, uint64_t & timestamp, int32_t & timeOffset, uint64_t & duration);
uint64_t size(); uint64_t size();
private: private:
bool initialised; bool initialised;