1
0
Fork 0
mirror of https://github.com/DanielnetoDotCom/YouPHPTube synced 2025-10-04 10:19:24 +02:00

Chromecast moved to PlayerSkins plugin

aisplay option added on PlayerSkins
This commit is contained in:
Daniel Neto 2024-10-30 20:19:49 -03:00
parent 480ae72b99
commit efd0665a44
286 changed files with 72588 additions and 1487 deletions

7
node_modules/mux.js/CHANGELOG.md generated vendored
View file

@ -1,3 +1,10 @@
<a name="7.1.0"></a>
# [7.1.0](https://github.com/videojs/mux.js/compare/v7.0.3...v7.1.0) (2024-10-11)
### Features
* parse WebVTT from fmp4 segments. ([#445](https://github.com/videojs/mux.js/issues/445)) ([432b036](https://github.com/videojs/mux.js/commit/432b036))
<a name="7.0.3"></a>
## [7.0.3](https://github.com/videojs/mux.js/compare/v7.0.2...v7.0.3) (2024-03-12)

6
node_modules/mux.js/README.md generated vendored
View file

@ -125,6 +125,12 @@ Set to `true` to remux audio and video into a single MP4 segment.
This module reads CEA-608 captions out of FMP4 segments.
#### WebVTTParser
`muxjs.mp4.WebVTTParser`
This module reads WebVTT text out of FMP4 segments.
#### Tools
`muxjs.mp4.tools`

View file

@ -17,11 +17,11 @@ var findBox = require('../mp4/find-box.js');
var parseTfdt = require('../tools/parse-tfdt.js');
var parseTrun = require('../tools/parse-trun.js');
var parseTfhd = require('../tools/parse-tfhd.js');
var window = require('global/window');
var _require = require('./samples.js'),
getMdatTrafPairs = _require.getMdatTrafPairs,
parseSamples = _require.parseSamples;
/**
* Maps an offset in the mdat to a sample based on the the size of the samples.
* Assumes that `parseSamples` has been called first.
@ -123,61 +123,6 @@ var findSeiNals = function findSeiNals(avcStream, samples, trackId) {
return result;
};
/**
* Parses sample information out of Track Run Boxes and calculates
* the absolute presentation and decode timestamps of each sample.
*
* @param {Array<Uint8Array>} truns - The Trun Run boxes to be parsed
* @param {Number|BigInt} baseMediaDecodeTime - base media decode time from tfdt
@see ISO-BMFF-12/2015, Section 8.8.12
* @param {Object} tfhd - The parsed Track Fragment Header
* @see inspect.parseTfhd
* @return {Object[]} the parsed samples
*
* @see ISO-BMFF-12/2015, Section 8.8.8
**/
var parseSamples = function parseSamples(truns, baseMediaDecodeTime, tfhd) {
var currentDts = baseMediaDecodeTime;
var defaultSampleDuration = tfhd.defaultSampleDuration || 0;
var defaultSampleSize = tfhd.defaultSampleSize || 0;
var trackId = tfhd.trackId;
var allSamples = [];
truns.forEach(function (trun) {
// Note: We currently do not parse the sample table as well
// as the trun. It's possible some sources will require this.
// moov > trak > mdia > minf > stbl
var trackRun = parseTrun(trun);
var samples = trackRun.samples;
samples.forEach(function (sample) {
if (sample.duration === undefined) {
sample.duration = defaultSampleDuration;
}
if (sample.size === undefined) {
sample.size = defaultSampleSize;
}
sample.trackId = trackId;
sample.dts = currentDts;
if (sample.compositionTimeOffset === undefined) {
sample.compositionTimeOffset = 0;
}
if (typeof currentDts === 'bigint') {
sample.pts = currentDts + window.BigInt(sample.compositionTimeOffset);
currentDts += window.BigInt(sample.duration);
} else {
sample.pts = currentDts + sample.compositionTimeOffset;
currentDts += sample.duration;
}
});
allSamples = allSamples.concat(samples);
});
return allSamples;
};
/**
* Parses out caption nals from an FMP4 segment's video tracks.
*
@ -189,20 +134,8 @@ var parseSamples = function parseSamples(truns, baseMediaDecodeTime, tfhd) {
var parseCaptionNals = function parseCaptionNals(segment, videoTrackId) {
// To get the samples
var trafs = findBox(segment, ['moof', 'traf']); // To get SEI NAL units
var mdats = findBox(segment, ['mdat']);
var captionNals = {};
var mdatTrafPairs = []; // Pair up each traf with a mdat as moofs and mdats are in pairs
mdats.forEach(function (mdat, index) {
var matchingTraf = trafs[index];
mdatTrafPairs.push({
mdat: mdat,
traf: matchingTraf
});
});
var mdatTrafPairs = getMdatTrafPairs(segment);
mdatTrafPairs.forEach(function (pair) {
var mdat = pair.mdat;
var traf = pair.traf;

View file

@ -12,5 +12,6 @@ module.exports = {
Transmuxer: require('./transmuxer').Transmuxer,
AudioSegmentStream: require('./transmuxer').AudioSegmentStream,
VideoSegmentStream: require('./transmuxer').VideoSegmentStream,
CaptionParser: require('./caption-parser')
CaptionParser: require('./caption-parser'),
WebVttParser: require('./webvtt-parser')
};

90
node_modules/mux.js/cjs/mp4/samples.js generated vendored Normal file
View file

@ -0,0 +1,90 @@
"use strict";
var _require = require("../tools/mp4-inspector"),
parseTrun = _require.parseTrun;
var _require2 = require("./probe"),
findBox = _require2.findBox;
var window = require('global/window');
/**
* Utility function for parsing data from mdat boxes.
* @param {Array<Uint8Array>} segment the segment data to create mdat/traf pairs from.
* @returns mdat and traf boxes paired up for easier parsing.
*/
var getMdatTrafPairs = function getMdatTrafPairs(segment) {
var trafs = findBox(segment, ['moof', 'traf']);
var mdats = findBox(segment, ['mdat']);
var mdatTrafPairs = []; // Pair up each traf with a mdat as moofs and mdats are in pairs
mdats.forEach(function (mdat, index) {
var matchingTraf = trafs[index];
mdatTrafPairs.push({
mdat: mdat,
traf: matchingTraf
});
});
return mdatTrafPairs;
};
/**
* Parses sample information out of Track Run Boxes and calculates
* the absolute presentation and decode timestamps of each sample.
*
* @param {Array<Uint8Array>} truns - The Trun Run boxes to be parsed
* @param {Number|BigInt} baseMediaDecodeTime - base media decode time from tfdt
@see ISO-BMFF-12/2015, Section 8.8.12
* @param {Object} tfhd - The parsed Track Fragment Header
* @see inspect.parseTfhd
* @return {Object[]} the parsed samples
*
* @see ISO-BMFF-12/2015, Section 8.8.8
**/
var parseSamples = function parseSamples(truns, baseMediaDecodeTime, tfhd) {
var currentDts = baseMediaDecodeTime;
var defaultSampleDuration = tfhd.defaultSampleDuration || 0;
var defaultSampleSize = tfhd.defaultSampleSize || 0;
var trackId = tfhd.trackId;
var allSamples = [];
truns.forEach(function (trun) {
// Note: We currently do not parse the sample table as well
// as the trun. It's possible some sources will require this.
// moov > trak > mdia > minf > stbl
var trackRun = parseTrun(trun);
var samples = trackRun.samples;
samples.forEach(function (sample) {
if (sample.duration === undefined) {
sample.duration = defaultSampleDuration;
}
if (sample.size === undefined) {
sample.size = defaultSampleSize;
}
sample.trackId = trackId;
sample.dts = currentDts;
if (sample.compositionTimeOffset === undefined) {
sample.compositionTimeOffset = 0;
}
if (typeof currentDts === 'bigint') {
sample.pts = currentDts + window.BigInt(sample.compositionTimeOffset);
currentDts += window.BigInt(sample.duration);
} else {
sample.pts = currentDts + sample.compositionTimeOffset;
currentDts += sample.duration;
}
});
allSamples = allSamples.concat(samples);
});
return allSamples;
};
module.exports = {
getMdatTrafPairs: getMdatTrafPairs,
parseSamples: parseSamples
};

128
node_modules/mux.js/cjs/mp4/webvtt-parser.js generated vendored Normal file
View file

@ -0,0 +1,128 @@
"use strict";
var _require = require("../tools/mp4-inspector"),
parseTfdt = _require.parseTfdt;
var findBox = require("./find-box");
var _require2 = require("./probe"),
getTimescaleFromMediaHeader = _require2.getTimescaleFromMediaHeader;
var _require3 = require("./samples"),
parseSamples = _require3.parseSamples,
getMdatTrafPairs = _require3.getMdatTrafPairs;
/**
* Module for parsing WebVTT text and styles from FMP4 segments.
* Based on the ISO/IEC 14496-30.
*/
var WebVttParser = function WebVttParser() {
// default timescale to 90k
var timescale = 90e3;
/**
* Parses the timescale from the init segment.
* @param {Array<Uint8Array>} segment The initialization segment to parse the timescale from.
*/
this.init = function (segment) {
// We just need the timescale from the init segment.
var mdhd = findBox(segment, ['moov', 'trak', 'mdia', 'mdhd'])[0];
if (mdhd) {
timescale = getTimescaleFromMediaHeader(mdhd);
}
};
/**
* Parses a WebVTT FMP4 segment.
* @param {Array<Uint8Array>} segment The content segment to parse the WebVTT cues from.
* @returns The WebVTT cue text, styling, and timing info as an array of cue objects.
*/
this.parseSegment = function (segment) {
var vttCues = [];
var mdatTrafPairs = getMdatTrafPairs(segment);
var baseMediaDecodeTime = 0;
mdatTrafPairs.forEach(function (pair) {
var mdatBox = pair.mdat;
var trafBox = pair.traf; // zero or one.
var tfdtBox = findBox(trafBox, ['tfdt'])[0]; // zero or one.
var tfhdBox = findBox(trafBox, ['tfhd'])[0]; // zero or more.
var trunBoxes = findBox(trafBox, ['trun']);
if (tfdtBox) {
var tfdt = parseTfdt(tfdtBox);
baseMediaDecodeTime = tfdt.baseMediaDecodeTime;
}
if (trunBoxes.length && tfhdBox) {
var samples = parseSamples(trunBoxes, baseMediaDecodeTime, tfhdBox);
var mdatOffset = 0;
samples.forEach(function (sample) {
// decode utf8 payload
var UTF_8 = 'utf-8';
var textDecoder = new TextDecoder(UTF_8); // extract sample data from the mdat box.
// WebVTT Sample format:
// Exactly one VTTEmptyCueBox box
// OR one or more VTTCueBox boxes.
var sampleData = mdatBox.slice(mdatOffset, mdatOffset + sample.size); // single vtte box.
var vtteBox = findBox(sampleData, ['vtte'])[0]; // empty box
if (vtteBox) {
mdatOffset += sample.size;
return;
} // TODO: Support 'vtta' boxes.
// VTTAdditionalTextBoxes can be interleaved between VTTCueBoxes.
var vttcBoxes = findBox(sampleData, ['vttc']);
vttcBoxes.forEach(function (vttcBox) {
// mandatory payload box.
var paylBox = findBox(vttcBox, ['payl'])[0]; // optional settings box
var sttgBox = findBox(vttcBox, ['sttg'])[0];
var start = sample.pts / timescale;
var end = (sample.pts + sample.duration) / timescale;
var cueText, settings; // contains cue text.
if (paylBox) {
try {
cueText = textDecoder.decode(paylBox);
} catch (e) {
console.error(e);
}
} // settings box contains styling.
if (sttgBox) {
try {
settings = textDecoder.decode(sttgBox);
} catch (e) {
console.error(e);
}
}
if (sample.duration && cueText) {
vttCues.push({
cueText: cueText,
start: start,
end: end,
settings: settings
});
}
});
mdatOffset += sample.size;
});
}
});
return vttCues;
};
};
module.exports = WebVttParser;

View file

@ -1,4 +1,4 @@
/*! @name mux.js @version 7.0.3 @license Apache-2.0 */
/*! @name mux.js @version 7.1.0 @license Apache-2.0 */
(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
typeof define === 'function' && define.amd ? define(factory) :

File diff suppressed because one or more lines are too long

1104
node_modules/mux.js/dist/mux-mp4.js generated vendored

File diff suppressed because it is too large Load diff

File diff suppressed because one or more lines are too long

1874
node_modules/mux.js/dist/mux.js generated vendored

File diff suppressed because it is too large Load diff

File diff suppressed because one or more lines are too long

View file

@ -17,11 +17,11 @@ var findBox = require('../mp4/find-box.js');
var parseTfdt = require('../tools/parse-tfdt.js');
var parseTrun = require('../tools/parse-trun.js');
var parseTfhd = require('../tools/parse-tfhd.js');
var window = require('global/window');
var _require = require('./samples.js'),
getMdatTrafPairs = _require.getMdatTrafPairs,
parseSamples = _require.parseSamples;
/**
* Maps an offset in the mdat to a sample based on the the size of the samples.
* Assumes that `parseSamples` has been called first.
@ -123,61 +123,6 @@ var findSeiNals = function findSeiNals(avcStream, samples, trackId) {
return result;
};
/**
* Parses sample information out of Track Run Boxes and calculates
* the absolute presentation and decode timestamps of each sample.
*
* @param {Array<Uint8Array>} truns - The Trun Run boxes to be parsed
* @param {Number|BigInt} baseMediaDecodeTime - base media decode time from tfdt
@see ISO-BMFF-12/2015, Section 8.8.12
* @param {Object} tfhd - The parsed Track Fragment Header
* @see inspect.parseTfhd
* @return {Object[]} the parsed samples
*
* @see ISO-BMFF-12/2015, Section 8.8.8
**/
var parseSamples = function parseSamples(truns, baseMediaDecodeTime, tfhd) {
var currentDts = baseMediaDecodeTime;
var defaultSampleDuration = tfhd.defaultSampleDuration || 0;
var defaultSampleSize = tfhd.defaultSampleSize || 0;
var trackId = tfhd.trackId;
var allSamples = [];
truns.forEach(function (trun) {
// Note: We currently do not parse the sample table as well
// as the trun. It's possible some sources will require this.
// moov > trak > mdia > minf > stbl
var trackRun = parseTrun(trun);
var samples = trackRun.samples;
samples.forEach(function (sample) {
if (sample.duration === undefined) {
sample.duration = defaultSampleDuration;
}
if (sample.size === undefined) {
sample.size = defaultSampleSize;
}
sample.trackId = trackId;
sample.dts = currentDts;
if (sample.compositionTimeOffset === undefined) {
sample.compositionTimeOffset = 0;
}
if (typeof currentDts === 'bigint') {
sample.pts = currentDts + window.BigInt(sample.compositionTimeOffset);
currentDts += window.BigInt(sample.duration);
} else {
sample.pts = currentDts + sample.compositionTimeOffset;
currentDts += sample.duration;
}
});
allSamples = allSamples.concat(samples);
});
return allSamples;
};
/**
* Parses out caption nals from an FMP4 segment's video tracks.
*
@ -189,20 +134,8 @@ var parseSamples = function parseSamples(truns, baseMediaDecodeTime, tfhd) {
var parseCaptionNals = function parseCaptionNals(segment, videoTrackId) {
// To get the samples
var trafs = findBox(segment, ['moof', 'traf']); // To get SEI NAL units
var mdats = findBox(segment, ['mdat']);
var captionNals = {};
var mdatTrafPairs = []; // Pair up each traf with a mdat as moofs and mdats are in pairs
mdats.forEach(function (mdat, index) {
var matchingTraf = trafs[index];
mdatTrafPairs.push({
mdat: mdat,
traf: matchingTraf
});
});
var mdatTrafPairs = getMdatTrafPairs(segment);
mdatTrafPairs.forEach(function (pair) {
var mdat = pair.mdat;
var traf = pair.traf;

View file

@ -10,5 +10,6 @@ module.exports = {
Transmuxer: require('./transmuxer').Transmuxer,
AudioSegmentStream: require('./transmuxer').AudioSegmentStream,
VideoSegmentStream: require('./transmuxer').VideoSegmentStream,
CaptionParser: require('./caption-parser')
CaptionParser: require('./caption-parser'),
WebVttParser: require('./webvtt-parser')
};

88
node_modules/mux.js/es/mp4/samples.js generated vendored Normal file
View file

@ -0,0 +1,88 @@
var _require = require("../tools/mp4-inspector"),
parseTrun = _require.parseTrun;
var _require2 = require("./probe"),
findBox = _require2.findBox;
var window = require('global/window');
/**
* Utility function for parsing data from mdat boxes.
* @param {Array<Uint8Array>} segment the segment data to create mdat/traf pairs from.
* @returns mdat and traf boxes paired up for easier parsing.
*/
var getMdatTrafPairs = function getMdatTrafPairs(segment) {
var trafs = findBox(segment, ['moof', 'traf']);
var mdats = findBox(segment, ['mdat']);
var mdatTrafPairs = []; // Pair up each traf with a mdat as moofs and mdats are in pairs
mdats.forEach(function (mdat, index) {
var matchingTraf = trafs[index];
mdatTrafPairs.push({
mdat: mdat,
traf: matchingTraf
});
});
return mdatTrafPairs;
};
/**
* Parses sample information out of Track Run Boxes and calculates
* the absolute presentation and decode timestamps of each sample.
*
* @param {Array<Uint8Array>} truns - The Trun Run boxes to be parsed
* @param {Number|BigInt} baseMediaDecodeTime - base media decode time from tfdt
@see ISO-BMFF-12/2015, Section 8.8.12
* @param {Object} tfhd - The parsed Track Fragment Header
* @see inspect.parseTfhd
* @return {Object[]} the parsed samples
*
* @see ISO-BMFF-12/2015, Section 8.8.8
**/
var parseSamples = function parseSamples(truns, baseMediaDecodeTime, tfhd) {
var currentDts = baseMediaDecodeTime;
var defaultSampleDuration = tfhd.defaultSampleDuration || 0;
var defaultSampleSize = tfhd.defaultSampleSize || 0;
var trackId = tfhd.trackId;
var allSamples = [];
truns.forEach(function (trun) {
// Note: We currently do not parse the sample table as well
// as the trun. It's possible some sources will require this.
// moov > trak > mdia > minf > stbl
var trackRun = parseTrun(trun);
var samples = trackRun.samples;
samples.forEach(function (sample) {
if (sample.duration === undefined) {
sample.duration = defaultSampleDuration;
}
if (sample.size === undefined) {
sample.size = defaultSampleSize;
}
sample.trackId = trackId;
sample.dts = currentDts;
if (sample.compositionTimeOffset === undefined) {
sample.compositionTimeOffset = 0;
}
if (typeof currentDts === 'bigint') {
sample.pts = currentDts + window.BigInt(sample.compositionTimeOffset);
currentDts += window.BigInt(sample.duration);
} else {
sample.pts = currentDts + sample.compositionTimeOffset;
currentDts += sample.duration;
}
});
allSamples = allSamples.concat(samples);
});
return allSamples;
};
module.exports = {
getMdatTrafPairs: getMdatTrafPairs,
parseSamples: parseSamples
};

126
node_modules/mux.js/es/mp4/webvtt-parser.js generated vendored Normal file
View file

@ -0,0 +1,126 @@
var _require = require("../tools/mp4-inspector"),
parseTfdt = _require.parseTfdt;
var findBox = require("./find-box");
var _require2 = require("./probe"),
getTimescaleFromMediaHeader = _require2.getTimescaleFromMediaHeader;
var _require3 = require("./samples"),
parseSamples = _require3.parseSamples,
getMdatTrafPairs = _require3.getMdatTrafPairs;
/**
* Module for parsing WebVTT text and styles from FMP4 segments.
* Based on the ISO/IEC 14496-30.
*/
var WebVttParser = function WebVttParser() {
// default timescale to 90k
var timescale = 90e3;
/**
* Parses the timescale from the init segment.
* @param {Array<Uint8Array>} segment The initialization segment to parse the timescale from.
*/
this.init = function (segment) {
// We just need the timescale from the init segment.
var mdhd = findBox(segment, ['moov', 'trak', 'mdia', 'mdhd'])[0];
if (mdhd) {
timescale = getTimescaleFromMediaHeader(mdhd);
}
};
/**
* Parses a WebVTT FMP4 segment.
* @param {Array<Uint8Array>} segment The content segment to parse the WebVTT cues from.
* @returns The WebVTT cue text, styling, and timing info as an array of cue objects.
*/
this.parseSegment = function (segment) {
var vttCues = [];
var mdatTrafPairs = getMdatTrafPairs(segment);
var baseMediaDecodeTime = 0;
mdatTrafPairs.forEach(function (pair) {
var mdatBox = pair.mdat;
var trafBox = pair.traf; // zero or one.
var tfdtBox = findBox(trafBox, ['tfdt'])[0]; // zero or one.
var tfhdBox = findBox(trafBox, ['tfhd'])[0]; // zero or more.
var trunBoxes = findBox(trafBox, ['trun']);
if (tfdtBox) {
var tfdt = parseTfdt(tfdtBox);
baseMediaDecodeTime = tfdt.baseMediaDecodeTime;
}
if (trunBoxes.length && tfhdBox) {
var samples = parseSamples(trunBoxes, baseMediaDecodeTime, tfhdBox);
var mdatOffset = 0;
samples.forEach(function (sample) {
// decode utf8 payload
var UTF_8 = 'utf-8';
var textDecoder = new TextDecoder(UTF_8); // extract sample data from the mdat box.
// WebVTT Sample format:
// Exactly one VTTEmptyCueBox box
// OR one or more VTTCueBox boxes.
var sampleData = mdatBox.slice(mdatOffset, mdatOffset + sample.size); // single vtte box.
var vtteBox = findBox(sampleData, ['vtte'])[0]; // empty box
if (vtteBox) {
mdatOffset += sample.size;
return;
} // TODO: Support 'vtta' boxes.
// VTTAdditionalTextBoxes can be interleaved between VTTCueBoxes.
var vttcBoxes = findBox(sampleData, ['vttc']);
vttcBoxes.forEach(function (vttcBox) {
// mandatory payload box.
var paylBox = findBox(vttcBox, ['payl'])[0]; // optional settings box
var sttgBox = findBox(vttcBox, ['sttg'])[0];
var start = sample.pts / timescale;
var end = (sample.pts + sample.duration) / timescale;
var cueText, settings; // contains cue text.
if (paylBox) {
try {
cueText = textDecoder.decode(paylBox);
} catch (e) {
console.error(e);
}
} // settings box contains styling.
if (sttgBox) {
try {
settings = textDecoder.decode(sttgBox);
} catch (e) {
console.error(e);
}
}
if (sample.duration && cueText) {
vttCues.push({
cueText: cueText,
start: start,
end: end,
settings: settings
});
}
});
mdatOffset += sample.size;
});
}
});
return vttCues;
};
};
module.exports = WebVttParser;

View file

@ -13,9 +13,8 @@ var discardEmulationPreventionBytes = require('../tools/caption-packet-parser').
var CaptionStream = require('../m2ts/caption-stream').CaptionStream;
var findBox = require('../mp4/find-box.js');
var parseTfdt = require('../tools/parse-tfdt.js');
var parseTrun = require('../tools/parse-trun.js');
var parseTfhd = require('../tools/parse-tfhd.js');
var window = require('global/window');
var { getMdatTrafPairs, parseSamples } = require('./samples.js');
/**
* Maps an offset in the mdat to a sample based on the the size of the samples.
@ -118,62 +117,6 @@ var findSeiNals = function(avcStream, samples, trackId) {
return result;
};
/**
* Parses sample information out of Track Run Boxes and calculates
* the absolute presentation and decode timestamps of each sample.
*
* @param {Array<Uint8Array>} truns - The Trun Run boxes to be parsed
* @param {Number|BigInt} baseMediaDecodeTime - base media decode time from tfdt
@see ISO-BMFF-12/2015, Section 8.8.12
* @param {Object} tfhd - The parsed Track Fragment Header
* @see inspect.parseTfhd
* @return {Object[]} the parsed samples
*
* @see ISO-BMFF-12/2015, Section 8.8.8
**/
var parseSamples = function(truns, baseMediaDecodeTime, tfhd) {
var currentDts = baseMediaDecodeTime;
var defaultSampleDuration = tfhd.defaultSampleDuration || 0;
var defaultSampleSize = tfhd.defaultSampleSize || 0;
var trackId = tfhd.trackId;
var allSamples = [];
truns.forEach(function(trun) {
// Note: We currently do not parse the sample table as well
// as the trun. It's possible some sources will require this.
// moov > trak > mdia > minf > stbl
var trackRun = parseTrun(trun);
var samples = trackRun.samples;
samples.forEach(function(sample) {
if (sample.duration === undefined) {
sample.duration = defaultSampleDuration;
}
if (sample.size === undefined) {
sample.size = defaultSampleSize;
}
sample.trackId = trackId;
sample.dts = currentDts;
if (sample.compositionTimeOffset === undefined) {
sample.compositionTimeOffset = 0;
}
if (typeof currentDts === 'bigint') {
sample.pts = currentDts + window.BigInt(sample.compositionTimeOffset);
currentDts += window.BigInt(sample.duration);
} else {
sample.pts = currentDts + sample.compositionTimeOffset;
currentDts += sample.duration;
}
});
allSamples = allSamples.concat(samples);
});
return allSamples;
};
/**
* Parses out caption nals from an FMP4 segment's video tracks.
*
@ -183,21 +126,8 @@ var parseSamples = function(truns, baseMediaDecodeTime, tfhd) {
* a list of seiNals found in that track
**/
var parseCaptionNals = function(segment, videoTrackId) {
// To get the samples
var trafs = findBox(segment, ['moof', 'traf']);
// To get SEI NAL units
var mdats = findBox(segment, ['mdat']);
var captionNals = {};
var mdatTrafPairs = [];
// Pair up each traf with a mdat as moofs and mdats are in pairs
mdats.forEach(function(mdat, index) {
var matchingTraf = trafs[index];
mdatTrafPairs.push({
mdat: mdat,
traf: matchingTraf
});
});
var mdatTrafPairs = getMdatTrafPairs(segment);
mdatTrafPairs.forEach(function(pair) {
var mdat = pair.mdat;

View file

@ -10,5 +10,6 @@ module.exports = {
Transmuxer: require('./transmuxer').Transmuxer,
AudioSegmentStream: require('./transmuxer').AudioSegmentStream,
VideoSegmentStream: require('./transmuxer').VideoSegmentStream,
CaptionParser: require('./caption-parser')
CaptionParser: require('./caption-parser'),
WebVttParser: require('./webvtt-parser')
};

87
node_modules/mux.js/lib/mp4/samples.js generated vendored Normal file
View file

@ -0,0 +1,87 @@
const { parseTrun } = require("../tools/mp4-inspector");
const { findBox } = require("./probe");
var window = require('global/window');
/**
* Utility function for parsing data from mdat boxes.
* @param {Array<Uint8Array>} segment the segment data to create mdat/traf pairs from.
* @returns mdat and traf boxes paired up for easier parsing.
*/
var getMdatTrafPairs = function(segment) {
var trafs = findBox(segment, ['moof', 'traf']);
var mdats = findBox(segment, ['mdat']);
var mdatTrafPairs = [];
// Pair up each traf with a mdat as moofs and mdats are in pairs
mdats.forEach(function(mdat, index) {
var matchingTraf = trafs[index];
mdatTrafPairs.push({
mdat: mdat,
traf: matchingTraf
});
});
return mdatTrafPairs;
};
/**
* Parses sample information out of Track Run Boxes and calculates
* the absolute presentation and decode timestamps of each sample.
*
* @param {Array<Uint8Array>} truns - The Trun Run boxes to be parsed
* @param {Number|BigInt} baseMediaDecodeTime - base media decode time from tfdt
@see ISO-BMFF-12/2015, Section 8.8.12
* @param {Object} tfhd - The parsed Track Fragment Header
* @see inspect.parseTfhd
* @return {Object[]} the parsed samples
*
* @see ISO-BMFF-12/2015, Section 8.8.8
**/
var parseSamples = function(truns, baseMediaDecodeTime, tfhd) {
var currentDts = baseMediaDecodeTime;
var defaultSampleDuration = tfhd.defaultSampleDuration || 0;
var defaultSampleSize = tfhd.defaultSampleSize || 0;
var trackId = tfhd.trackId;
var allSamples = [];
truns.forEach(function(trun) {
// Note: We currently do not parse the sample table as well
// as the trun. It's possible some sources will require this.
// moov > trak > mdia > minf > stbl
var trackRun = parseTrun(trun);
var samples = trackRun.samples;
samples.forEach(function(sample) {
if (sample.duration === undefined) {
sample.duration = defaultSampleDuration;
}
if (sample.size === undefined) {
sample.size = defaultSampleSize;
}
sample.trackId = trackId;
sample.dts = currentDts;
if (sample.compositionTimeOffset === undefined) {
sample.compositionTimeOffset = 0;
}
if (typeof currentDts === 'bigint') {
sample.pts = currentDts + window.BigInt(sample.compositionTimeOffset);
currentDts += window.BigInt(sample.duration);
} else {
sample.pts = currentDts + sample.compositionTimeOffset;
currentDts += sample.duration;
}
});
allSamples = allSamples.concat(samples);
});
return allSamples;
};
module.exports = {
getMdatTrafPairs,
parseSamples
};

126
node_modules/mux.js/lib/mp4/webvtt-parser.js generated vendored Normal file
View file

@ -0,0 +1,126 @@
const { parseTfdt } = require("../tools/mp4-inspector");
const findBox = require("./find-box");
const { getTimescaleFromMediaHeader } = require("./probe");
const { parseSamples, getMdatTrafPairs } = require("./samples");
/**
* Module for parsing WebVTT text and styles from FMP4 segments.
* Based on the ISO/IEC 14496-30.
*/
const WebVttParser = function() {
// default timescale to 90k
let timescale = 90e3;
/**
* Parses the timescale from the init segment.
* @param {Array<Uint8Array>} segment The initialization segment to parse the timescale from.
*/
this.init = function(segment) {
// We just need the timescale from the init segment.
const mdhd = findBox(segment, ['moov', 'trak', 'mdia', 'mdhd'])[0];
if (mdhd) {
timescale = getTimescaleFromMediaHeader(mdhd);
}
};
/**
* Parses a WebVTT FMP4 segment.
* @param {Array<Uint8Array>} segment The content segment to parse the WebVTT cues from.
* @returns The WebVTT cue text, styling, and timing info as an array of cue objects.
*/
this.parseSegment = function(segment) {
const vttCues = [];
const mdatTrafPairs = getMdatTrafPairs(segment);
let baseMediaDecodeTime = 0;
mdatTrafPairs.forEach(function(pair) {
const mdatBox = pair.mdat;
const trafBox = pair.traf;
// zero or one.
const tfdtBox = findBox(trafBox, ['tfdt'])[0];
// zero or one.
const tfhdBox = findBox(trafBox, ['tfhd'])[0];
// zero or more.
const trunBoxes = findBox(trafBox, ['trun']);
if (tfdtBox) {
const tfdt = parseTfdt(tfdtBox);
baseMediaDecodeTime = tfdt.baseMediaDecodeTime;
}
if (trunBoxes.length && tfhdBox) {
const samples = parseSamples(trunBoxes, baseMediaDecodeTime, tfhdBox);
let mdatOffset = 0;
samples.forEach(function(sample) {
// decode utf8 payload
const UTF_8 = 'utf-8';
const textDecoder = new TextDecoder(UTF_8);
// extract sample data from the mdat box.
// WebVTT Sample format:
// Exactly one VTTEmptyCueBox box
// OR one or more VTTCueBox boxes.
const sampleData = mdatBox.slice(mdatOffset, mdatOffset + sample.size);
// single vtte box.
const vtteBox = findBox(sampleData, ['vtte'])[0];
// empty box
if (vtteBox) {
mdatOffset += sample.size;
return;
}
// TODO: Support 'vtta' boxes.
// VTTAdditionalTextBoxes can be interleaved between VTTCueBoxes.
const vttcBoxes = findBox(sampleData, ['vttc']);
vttcBoxes.forEach(function(vttcBox) {
// mandatory payload box.
const paylBox = findBox(vttcBox, ['payl'])[0];
// optional settings box
const sttgBox = findBox(vttcBox, ['sttg'])[0];
const start = sample.pts / timescale;
const end = (sample.pts + sample.duration) / timescale;
let cueText, settings;
// contains cue text.
if (paylBox) {
try {
cueText = textDecoder.decode(paylBox);
} catch(e) {
console.error(e);
}
}
// settings box contains styling.
if (sttgBox) {
try {
settings = textDecoder.decode(sttgBox);
} catch(e) {
console.error(e);
}
}
if (sample.duration && cueText) {
vttCues.push({
cueText,
start,
end,
settings
});
}
});
mdatOffset += sample.size;
});
}
});
return vttCues;
};
};
module.exports = WebVttParser;

2
node_modules/mux.js/package.json generated vendored
View file

@ -1,6 +1,6 @@
{
"name": "mux.js",
"version": "7.0.3",
"version": "7.1.0",
"description": "A collection of lightweight utilities for inspecting and manipulating video container formats.",
"repository": {
"type": "git",