Skip to content

Commit

Permalink
Revert PTS wrapping code which produces incorrect cue times (video-de…
Browse files Browse the repository at this point in the history
  • Loading branch information
johnBartos authored Dec 13, 2018
1 parent 45436cd commit 23a07d9
Showing 1 changed file with 3 additions and 24 deletions.
27 changes: 3 additions & 24 deletions src/utils/webvtt-parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,29 +58,6 @@ const calculateOffset = function (vttCCs, cc, presentationTime) {
vttCCs.presentationOffset = presentationTime;
};

const wrapPtsInteger = function (value, reference) {
let offset;
if (!Number.isFinite(reference)) {
return value;
}

if (reference < value) {
// - 2^33
offset = -8589934592;
} else {
// + 2^33
offset = 8589934592;
}
/* PTS is 33bit (from 0 to 2^33 -1)
if diff between value and reference is bigger than half of the amplitude (2^32) then it means that
PTS looping occured. fill the gap */
while (Math.abs(value - reference) > 4294967296) {
value += offset;
}

return value;
};

const WebVTTParser = {
parse: function (vttByteArray, syncPTS, vttCCs, cc, callBack, errorCallBack) {
// Convert byteArray into string, replacing any somewhat exotic linefeeds with "\n", then split on that character.
Expand Down Expand Up @@ -163,7 +140,9 @@ const WebVTTParser = {
});
try {
// Calculate subtitle offset in milliseconds.
mpegTs = wrapPtsInteger(mpegTs - syncPTS, vttCCs.ccOffset * 90000);
syncPTS = syncPTS < 0 ? syncPTS + 8589934592 : syncPTS;
// Adjust MPEGTS by sync PTS.
mpegTs -= syncPTS;
// Convert cue time to seconds
localTime = cueString2millis(cueTime) / 1000;
// Convert MPEGTS to seconds from 90kHz.
Expand Down

0 comments on commit 23a07d9

Please sign in to comment.