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 https://github.com/dailymotion/hls.js/issues/363
related to https://github.com/dailymotion/hls.js/issues/351
  • Loading branch information
mangui committed Apr 13, 2016
1 parent 85cce83 commit 1494a92
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 @@ -161,8 +161,8 @@ class MP4Remuxer {

// check timestamp continuity accross consecutive fragments (this is to remove inter-fragment gap/hole)
let delta = Math.round((firstDTS - 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 @@ -342,8 +342,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 @@ -355,7 +355,7 @@ class MP4Remuxer {
track.len -= unit.byteLength;
continue;
}
// set DTS to next DTS
// set PTS/DTS to expected PTS/DTS
ptsnorm = dtsnorm = nextAacPts;
}
}
Expand Down

0 comments on commit 1494a92

Please sign in to comment.