Skip to content

Commit

Permalink
mp4-remuxer: fix PTS/DTS adjustement of first audio/video samples on …
Browse files Browse the repository at this point in the history
…first and non contiguous fragment

in case of first/non contiguous fragment, only adjust PTS/DTS if there is a huge (more than 10s) unexpected delta between expected and parsed timestamp
=> respect A/V sync delay as advertised in the MPEG2-TS
=> fix buffer hole that might happen on subsequent contiguous fragment

related to #363
related to #351
  • Loading branch information
mangui committed Apr 14, 2016
1 parent 3fb06c5 commit a1e45d7
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions src/remux/mp4-remuxer.js
Original file line number Diff line number Diff line change
Expand Up @@ -190,8 +190,8 @@ class MP4Remuxer {
ptsnorm = this._PTSNormalize(pts, nextAvcDts);
dtsnorm = this._PTSNormalize(dts, nextAvcDts);
delta = Math.round((dtsnorm - nextAvcDts) / 90);
// if fragment are contiguous, or delta less than 600ms, ensure there is no overlap/hole between fragments
if (contiguous || Math.abs(delta) < 600) {
// if fragment are contiguous, or if there is a huge delta (more than 10s) between expected PTS and sample PTS
if (contiguous || Math.abs(delta) > 10000) {
if (delta) {
if (delta > 1) {
logger.log(`AVC:${delta} ms hole between fragments detected,filling it`);
Expand Down Expand Up @@ -314,8 +314,8 @@ class MP4Remuxer {
ptsnorm = this._PTSNormalize(pts, nextAacPts);
dtsnorm = this._PTSNormalize(dts, nextAacPts);
delta = Math.round(1000 * (ptsnorm - nextAacPts) / pesTimeScale);
// if fragment are contiguous, or delta less than 600ms, ensure there is no overlap/hole between fragments
if (contiguous || Math.abs(delta) < 600) {
// if fragment are contiguous, or if there is a huge delta (more than 10s) between expected PTS and sample PTS
if (contiguous || Math.abs(delta) > 10000) {
// log delta
if (delta) {
if (delta > 0) {
Expand All @@ -327,7 +327,7 @@ class MP4Remuxer {
track.len -= unit.byteLength;
continue;
}
// set DTS to next DTS
// set PTS/DTS to next PTS/DTS
ptsnorm = dtsnorm = nextAacPts;
}
}
Expand Down

0 comments on commit a1e45d7

Please sign in to comment.