Fixed ELST box in mp4, and use it to fix track desync issues.
This commit is contained in:
parent
ecbb48dbfe
commit
0c41fee7c8
2 changed files with 25 additions and 15 deletions
|
@ -3197,57 +3197,57 @@ namespace MP4 {
|
|||
|
||||
void ELST::setSegmentDuration(uint32_t cnt, uint64_t newVal) {
|
||||
if (getVersion() == 1) {
|
||||
setInt64(newVal, 28*cnt+8);
|
||||
setInt64(newVal, 20*cnt+8);
|
||||
} else {
|
||||
setInt32(newVal, 20*cnt+8);
|
||||
setInt32(newVal, 12*cnt+8);
|
||||
}
|
||||
}
|
||||
|
||||
uint64_t ELST::getSegmentDuration(uint32_t cnt) {
|
||||
if (getVersion() == 1) {
|
||||
return getInt64(28*cnt+8);
|
||||
return getInt64(20*cnt+8);
|
||||
} else {
|
||||
return getInt32(20*cnt+8);
|
||||
return getInt32(12*cnt+8);
|
||||
}
|
||||
}
|
||||
|
||||
void ELST::setMediaTime(uint32_t cnt, uint64_t newVal) {
|
||||
if (getVersion() == 1) {
|
||||
setInt64(newVal, 28*cnt+16);
|
||||
setInt64(newVal, 20*cnt+16);
|
||||
} else {
|
||||
setInt32(newVal, 20*cnt+12);
|
||||
setInt32(newVal, 12*cnt+12);
|
||||
}
|
||||
}
|
||||
|
||||
uint64_t ELST::getMediaTime(uint32_t cnt) {
|
||||
if (getVersion() == 1) {
|
||||
return getInt64(28*cnt+16);
|
||||
return getInt64(20*cnt+16);
|
||||
} else {
|
||||
return getInt32(20*cnt+12);
|
||||
return getInt32(12*cnt+12);
|
||||
}
|
||||
}
|
||||
|
||||
void ELST::setMediaRateInteger(uint32_t cnt, uint16_t newVal) {
|
||||
if (getVersion() == 1) {
|
||||
setInt16(newVal, 28*cnt+24);
|
||||
setInt16(newVal, 20*cnt+24);
|
||||
} else {
|
||||
setInt16(newVal, 20*cnt+16);
|
||||
setInt16(newVal, 12*cnt+16);
|
||||
}
|
||||
}
|
||||
|
||||
uint16_t ELST::getMediaRateInteger(uint32_t cnt) {
|
||||
if (getVersion() == 1) {
|
||||
return getInt16(28*cnt+24);
|
||||
return getInt16(20*cnt+24);
|
||||
} else {
|
||||
return getInt16(20*cnt+16);
|
||||
return getInt16(12*cnt+16);
|
||||
}
|
||||
}
|
||||
|
||||
void ELST::setMediaRateFraction(uint32_t cnt, uint16_t newVal) {
|
||||
if (getVersion() == 1) {
|
||||
setInt16(newVal, 28*cnt+26);
|
||||
setInt16(newVal, 20*cnt+26);
|
||||
} else {
|
||||
setInt16(newVal, 20*cnt+18);
|
||||
setInt16(newVal, 12*cnt+18);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -40,6 +40,12 @@ namespace Mist {
|
|||
uint64_t res = 36 // FTYP Box
|
||||
+ 8 //MOOV box
|
||||
+ 108; //MVHD Box
|
||||
uint64_t firstms = 0xFFFFFFFFFFFFFFFFull;
|
||||
for (std::set<unsigned long>::iterator it = selectedTracks.begin(); it != selectedTracks.end(); it++){
|
||||
if (myMeta.tracks[*it].firstms < firstms){
|
||||
firstms = myMeta.tracks[*it].firstms;
|
||||
}
|
||||
}
|
||||
for (std::set<unsigned long>::iterator it = selectedTracks.begin(); it != selectedTracks.end(); it++){
|
||||
DTSC::Track & thisTrack = myMeta.tracks[*it];
|
||||
uint64_t tmpRes = 0;
|
||||
|
@ -54,6 +60,9 @@ namespace Mist {
|
|||
+ 8 //MINF Box
|
||||
+ 36 //DINF Box
|
||||
+ 8; // STBL Box
|
||||
if (thisTrack.firstms != firstms){
|
||||
tmpRes += 12;// EDTS entry extra
|
||||
}
|
||||
|
||||
//These boxes are empty when generating fragmented output
|
||||
tmpRes += 20 + (partCount * 4);//STSZ
|
||||
|
@ -140,7 +149,7 @@ namespace Mist {
|
|||
//Then override it to set the correct duration
|
||||
uint64_t firstms = 0xFFFFFFFFFFFFFFull;
|
||||
uint64_t lastms = 0;
|
||||
for (std::set<unsigned long>::iterator it = selectedTracks.begin(); it != selectedTracks.end(); it++) {
|
||||
for (std::set<unsigned long>::iterator it = selectedTracks.begin(); it != selectedTracks.end(); it++){
|
||||
lastms = std::max(lastms, (uint64_t)myMeta.tracks[*it].lastms);
|
||||
firstms = std::min(firstms, (uint64_t)myMeta.tracks[*it].firstms);
|
||||
}
|
||||
|
@ -171,6 +180,7 @@ namespace Mist {
|
|||
elstBox.setMediaTime(0, 0);
|
||||
elstBox.setMediaRateInteger(0, 1);
|
||||
elstBox.setMediaRateFraction(0, 0);
|
||||
|
||||
edtsBox.setContent(elstBox, 0);
|
||||
trakBox.setContent(edtsBox, trakOffset++);
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue