Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

mux.js

Package Overview
Dependencies
Maintainers
15
Versions
104
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

mux.js - npm Package Compare versions

Comparing version 5.6.4 to 5.6.5

lib/mp4/find-box.js

21

lib/mp4/caption-parser.js

@@ -14,3 +14,6 @@ /**

var CaptionStream = require('../m2ts/caption-stream').CaptionStream;
var inspect = require('../tools/mp4-inspector');
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');

@@ -137,3 +140,3 @@ /**

// moov > trak > mdia > minf > stbl
var trackRun = inspect.parseTrun(trun);
var trackRun = parseTrun(trun);
var samples = trackRun.samples;

@@ -174,5 +177,5 @@

// To get the samples
var trafs = inspect.findBox(segment, ['moof', 'traf']);
var trafs = findBox(segment, ['moof', 'traf']);
// To get SEI NAL units
var mdats = inspect.findBox(segment, ['mdat']);
var mdats = findBox(segment, ['mdat']);
var captionNals = {};

@@ -193,10 +196,10 @@ var mdatTrafPairs = [];

var traf = pair.traf;
var tfhd = inspect.findBox(traf, ['tfhd']);
var tfhd = findBox(traf, ['tfhd']);
// Exactly 1 tfhd per traf
var headerInfo = inspect.parseTfhd(tfhd[0]);
var headerInfo = parseTfhd(tfhd[0]);
var trackId = headerInfo.trackId;
var tfdt = inspect.findBox(traf, ['tfdt']);
var tfdt = findBox(traf, ['tfdt']);
// Either 0 or 1 tfdt per traf
var baseMediaDecodeTime = (tfdt.length > 0) ? inspect.parseTfdt(tfdt[0]).baseMediaDecodeTime : 0;
var truns = inspect.findBox(traf, ['trun']);
var baseMediaDecodeTime = (tfdt.length > 0) ? parseTfdt(tfdt[0]).baseMediaDecodeTime : 0;
var truns = findBox(traf, ['trun']);
var samples;

@@ -203,0 +206,0 @@ var seiNals;

@@ -13,3 +13,7 @@ /**

var toHexString = require('../utils/bin').toHexString;
var mp4Inspector = require('../tools/mp4-inspector.js');
var findBox = require('../mp4/find-box.js');
var parseType = require('../mp4/parse-type.js');
var parseTfhd = require('../tools/parse-tfhd.js');
var parseTrun = require('../tools/parse-trun.js');
var parseTfdt = require('../tools/parse-tfdt.js');
var timescale, startTime, compositionStartTime, getVideoTrackIds, getTracks,

@@ -39,3 +43,3 @@ getTimescaleFromMediaHeader;

result = {},
traks = mp4Inspector.findBox(init, ['moov', 'trak']);
traks = findBox(init, ['moov', 'trak']);

@@ -46,3 +50,3 @@ // mdhd timescale

tkhd = mp4Inspector.findBox(trak, ['tkhd'])[0];
tkhd = findBox(trak, ['tkhd'])[0];
if (!tkhd) {

@@ -58,3 +62,3 @@ return null;

mdhd = mp4Inspector.findBox(trak, ['mdia', 'mdhd'])[0];
mdhd = findBox(trak, ['mdia', 'mdhd'])[0];
if (!mdhd) {

@@ -93,7 +97,7 @@ return null;

// we need info from two childrend of each track fragment box
trafs = mp4Inspector.findBox(fragment, ['moof', 'traf']);
trafs = findBox(fragment, ['moof', 'traf']);
// determine the start times for each track
baseTimes = [].concat.apply([], trafs.map(function(traf) {
return mp4Inspector.findBox(traf, ['tfhd']).map(function(tfhd) {
return findBox(traf, ['tfhd']).map(function(tfhd) {
var id, scale, baseTime;

@@ -110,3 +114,3 @@

// get the base media decode time from the tfdt
baseTime = mp4Inspector.findBox(traf, ['tfdt']).map(function(tfdt) {
baseTime = findBox(traf, ['tfdt']).map(function(tfdt) {
var version, result;

@@ -160,3 +164,3 @@

compositionStartTime = function(timescales, fragment) {
var trafBoxes = mp4Inspector.findBox(fragment, ['moof', 'traf']);
var trafBoxes = findBox(fragment, ['moof', 'traf']);
var baseMediaDecodeTime = 0;

@@ -170,11 +174,23 @@ var compositionTimeOffset = 0;

// We will assume that they are, so we only need the first to calculate start time.
var parsedTraf = mp4Inspector.parseTraf(trafBoxes[0]);
var tfhd = findBox(trafBoxes[0], ['tfhd'])[0];
var trun = findBox(trafBoxes[0], ['trun'])[0];
var tfdt = findBox(trafBoxes[0], ['tfdt'])[0];
for (var i = 0; i < parsedTraf.boxes.length; i++) {
if (parsedTraf.boxes[i].type === 'tfhd') {
trackId = parsedTraf.boxes[i].trackId;
} else if (parsedTraf.boxes[i].type === 'tfdt') {
baseMediaDecodeTime = parsedTraf.boxes[i].baseMediaDecodeTime;
} else if (parsedTraf.boxes[i].type === 'trun' && parsedTraf.boxes[i].samples.length) {
compositionTimeOffset = parsedTraf.boxes[i].samples[0].compositionTimeOffset || 0;
if (tfhd) {
var parsedTfhd = parseTfhd(tfhd);
trackId = parsedTfhd.trackId;
}
if (tfdt) {
var parsedTfdt = parseTfdt(tfdt);
baseMediaDecodeTime = parsedTfdt.baseMediaDecodeTime;
}
if (trun) {
var parsedTrun = parseTrun(trun);
if (parsedTrun.samples && parsedTrun.samples.length) {
compositionTimeOffset = parsedTrun.samples[0].compositionTimeOffset || 0;
}

@@ -204,11 +220,11 @@ }

getVideoTrackIds = function(init) {
var traks = mp4Inspector.findBox(init, ['moov', 'trak']);
var traks = findBox(init, ['moov', 'trak']);
var videoTrackIds = [];
traks.forEach(function(trak) {
var hdlrs = mp4Inspector.findBox(trak, ['mdia', 'hdlr']);
var tkhds = mp4Inspector.findBox(trak, ['tkhd']);
var hdlrs = findBox(trak, ['mdia', 'hdlr']);
var tkhds = findBox(trak, ['tkhd']);
hdlrs.forEach(function(hdlr, index) {
var handlerType = mp4Inspector.parseType(hdlr.subarray(8, 12));
var handlerType = parseType(hdlr.subarray(8, 12));
var tkhd = tkhds[index];

@@ -250,3 +266,3 @@ var view;

getTracks = function(init) {
var traks = mp4Inspector.findBox(init, ['moov', 'trak']);
var traks = findBox(init, ['moov', 'trak']);
var tracks = [];

@@ -256,3 +272,3 @@

var track = {};
var tkhd = mp4Inspector.findBox(trak, ['tkhd'])[0];
var tkhd = findBox(trak, ['tkhd'])[0];
var view, tkhdVersion;

@@ -268,7 +284,7 @@

var hdlr = mp4Inspector.findBox(trak, ['mdia', 'hdlr'])[0];
var hdlr = findBox(trak, ['mdia', 'hdlr'])[0];
// type
if (hdlr) {
var type = mp4Inspector.parseType(hdlr.subarray(8, 12));
var type = parseType(hdlr.subarray(8, 12));

@@ -286,3 +302,3 @@ if (type === 'vide') {

// codec
var stsd = mp4Inspector.findBox(trak, ['mdia', 'minf', 'stbl', 'stsd'])[0];
var stsd = findBox(trak, ['mdia', 'minf', 'stbl', 'stsd'])[0];

@@ -292,5 +308,5 @@ if (stsd) {

// gives the codec type string
track.codec = mp4Inspector.parseType(sampleDescriptions.subarray(4, 8));
track.codec = parseType(sampleDescriptions.subarray(4, 8));
var codecBox = mp4Inspector.findBox(sampleDescriptions, [track.codec])[0];
var codecBox = findBox(sampleDescriptions, [track.codec])[0];
var codecConfig, codecConfigType;

@@ -304,3 +320,3 @@

codecConfig = codecBox.subarray(78);
codecConfigType = mp4Inspector.parseType(codecConfig.subarray(4, 8));
codecConfigType = parseType(codecConfig.subarray(4, 8));

@@ -325,3 +341,3 @@ if (codecConfigType === 'avcC' && codecConfig.length > 11) {

codecConfig = codecBox.subarray(28);
codecConfigType = mp4Inspector.parseType(codecConfig.subarray(4, 8));
codecConfigType = parseType(codecConfig.subarray(4, 8));

@@ -343,3 +359,3 @@ if (codecConfigType === 'esds' && codecConfig.length > 20 && codecConfig[19] !== 0) {

var mdhd = mp4Inspector.findBox(trak, ['mdia', 'mdhd'])[0];
var mdhd = findBox(trak, ['mdia', 'mdhd'])[0];

@@ -358,4 +374,4 @@ if (mdhd) {

// export mp4 inspector's findBox and parseType for backwards compatibility
findBox: mp4Inspector.findBox,
parseType: mp4Inspector.parseType,
findBox: findBox,
parseType: parseType,
timescale: timescale,

@@ -362,0 +378,0 @@ startTime: startTime,

@@ -15,69 +15,7 @@ /**

textifyMp4,
toUnsigned = require('../utils/bin').toUnsigned,
parseMp4Date = function(seconds) {
return new Date(seconds * 1000 - 2082844800000);
},
parseSampleFlags = function(flags) {
return {
isLeading: (flags[0] & 0x0c) >>> 2,
dependsOn: flags[0] & 0x03,
isDependedOn: (flags[1] & 0xc0) >>> 6,
hasRedundancy: (flags[1] & 0x30) >>> 4,
paddingValue: (flags[1] & 0x0e) >>> 1,
isNonSyncSample: flags[1] & 0x01,
degradationPriority: (flags[2] << 8) | flags[3]
};
},
/**
* Returns the string representation of an ASCII encoded four byte buffer.
* @param buffer {Uint8Array} a four-byte buffer to translate
* @return {string} the corresponding string
*/
parseType = function(buffer) {
var result = '';
result += String.fromCharCode(buffer[0]);
result += String.fromCharCode(buffer[1]);
result += String.fromCharCode(buffer[2]);
result += String.fromCharCode(buffer[3]);
return result;
},
// Find the data for a box specified by its path
findBox = function(data, path) {
var results = [],
i, size, type, end, subresults;
if (!path.length) {
// short-circuit the search for empty paths
return null;
}
for (i = 0; i < data.byteLength;) {
size = toUnsigned(data[i] << 24 |
data[i + 1] << 16 |
data[i + 2] << 8 |
data[i + 3]);
type = parseType(data.subarray(i + 4, i + 8));
end = size > 1 ? i + size : data.byteLength;
if (type === path[0]) {
if (path.length === 1) {
// this is the end of the path and we've found the box we were
// looking for
results.push(data.subarray(i + 8, end));
} else {
// recursively search for the next box along the path
subresults = findBox(data.subarray(i + 8, end), path.slice(1));
if (subresults.length) {
results = results.concat(subresults);
}
}
}
i = end;
}
// we've finished searching all of data
return results;
},
parseType = require('../mp4/parse-type'),
findBox = require('../mp4/find-box'),
nalParse = function(avcStream) {

@@ -442,29 +380,3 @@ var

},
sidx: function(data) {
var view = new DataView(data.buffer, data.byteOffset, data.byteLength),
result = {
version: data[0],
flags: new Uint8Array(data.subarray(1, 4)),
references: [],
referenceId: view.getUint32(4),
timescale: view.getUint32(8),
earliestPresentationTime: view.getUint32(12),
firstOffset: view.getUint32(16)
},
referenceCount = view.getUint16(22),
i;
for (i = 24; referenceCount; i += 12, referenceCount--) {
result.references.push({
referenceType: (data[i] & 0x80) >>> 7,
referencedSize: view.getUint32(i) & 0x7FFFFFFF,
subsegmentDuration: view.getUint32(i + 4),
startsWithSap: !!(data[i + 8] & 0x80),
sapType: (data[i + 8] & 0x70) >>> 4,
sapDeltaTime: view.getUint32(i + 8) & 0x0FFFFFFF
});
}
return result;
},
sidx: require('./parse-sidx.js'),
smhd: function(data) {

@@ -560,61 +472,4 @@ return {

},
tfdt: function(data) {
var result = {
version: data[0],
flags: new Uint8Array(data.subarray(1, 4)),
baseMediaDecodeTime: toUnsigned(data[4] << 24 | data[5] << 16 | data[6] << 8 | data[7])
};
if (result.version === 1) {
result.baseMediaDecodeTime *= Math.pow(2, 32);
result.baseMediaDecodeTime += toUnsigned(data[8] << 24 | data[9] << 16 | data[10] << 8 | data[11]);
}
return result;
},
tfhd: function(data) {
var
view = new DataView(data.buffer, data.byteOffset, data.byteLength),
result = {
version: data[0],
flags: new Uint8Array(data.subarray(1, 4)),
trackId: view.getUint32(4)
},
baseDataOffsetPresent = result.flags[2] & 0x01,
sampleDescriptionIndexPresent = result.flags[2] & 0x02,
defaultSampleDurationPresent = result.flags[2] & 0x08,
defaultSampleSizePresent = result.flags[2] & 0x10,
defaultSampleFlagsPresent = result.flags[2] & 0x20,
durationIsEmpty = result.flags[0] & 0x010000,
defaultBaseIsMoof = result.flags[0] & 0x020000,
i;
i = 8;
if (baseDataOffsetPresent) {
i += 4; // truncate top 4 bytes
// FIXME: should we read the full 64 bits?
result.baseDataOffset = view.getUint32(12);
i += 4;
}
if (sampleDescriptionIndexPresent) {
result.sampleDescriptionIndex = view.getUint32(i);
i += 4;
}
if (defaultSampleDurationPresent) {
result.defaultSampleDuration = view.getUint32(i);
i += 4;
}
if (defaultSampleSizePresent) {
result.defaultSampleSize = view.getUint32(i);
i += 4;
}
if (defaultSampleFlagsPresent) {
result.defaultSampleFlags = view.getUint32(i);
}
if (durationIsEmpty) {
result.durationIsEmpty = true;
}
if (!baseDataOffsetPresent && defaultBaseIsMoof) {
result.baseDataOffsetIsMoof = true;
}
return result;
},
tfdt: require('./parse-tfdt.js'),
tfhd: require('./parse-tfhd.js'),
tkhd: function(data) {

@@ -692,80 +547,3 @@ var

},
trun: function(data) {
var
result = {
version: data[0],
flags: new Uint8Array(data.subarray(1, 4)),
samples: []
},
view = new DataView(data.buffer, data.byteOffset, data.byteLength),
// Flag interpretation
dataOffsetPresent = result.flags[2] & 0x01, // compare with 2nd byte of 0x1
firstSampleFlagsPresent = result.flags[2] & 0x04, // compare with 2nd byte of 0x4
sampleDurationPresent = result.flags[1] & 0x01, // compare with 2nd byte of 0x100
sampleSizePresent = result.flags[1] & 0x02, // compare with 2nd byte of 0x200
sampleFlagsPresent = result.flags[1] & 0x04, // compare with 2nd byte of 0x400
sampleCompositionTimeOffsetPresent = result.flags[1] & 0x08, // compare with 2nd byte of 0x800
sampleCount = view.getUint32(4),
offset = 8,
sample;
if (dataOffsetPresent) {
// 32 bit signed integer
result.dataOffset = view.getInt32(offset);
offset += 4;
}
// Overrides the flags for the first sample only. The order of
// optional values will be: duration, size, compositionTimeOffset
if (firstSampleFlagsPresent && sampleCount) {
sample = {
flags: parseSampleFlags(data.subarray(offset, offset + 4))
};
offset += 4;
if (sampleDurationPresent) {
sample.duration = view.getUint32(offset);
offset += 4;
}
if (sampleSizePresent) {
sample.size = view.getUint32(offset);
offset += 4;
}
if (sampleCompositionTimeOffsetPresent) {
if (result.version === 1) {
sample.compositionTimeOffset = view.getInt32(offset);
} else {
sample.compositionTimeOffset = view.getUint32(offset);
}
offset += 4;
}
result.samples.push(sample);
sampleCount--;
}
while (sampleCount--) {
sample = {};
if (sampleDurationPresent) {
sample.duration = view.getUint32(offset);
offset += 4;
}
if (sampleSizePresent) {
sample.size = view.getUint32(offset);
offset += 4;
}
if (sampleFlagsPresent) {
sample.flags = parseSampleFlags(data.subarray(offset, offset + 4));
offset += 4;
}
if (sampleCompositionTimeOffsetPresent) {
if (result.version === 1) {
sample.compositionTimeOffset = view.getInt32(offset);
} else {
sample.compositionTimeOffset = view.getUint32(offset);
}
offset += 4;
}
result.samples.push(sample);
}
return result;
},
trun: require('./parse-trun.js'),
'url ': function(data) {

@@ -772,0 +550,0 @@ return {

{
"name": "mux.js",
"version": "5.6.4",
"version": "5.6.5",
"description": "A collection of lightweight utilities for inspecting and manipulating video container formats.",

@@ -5,0 +5,0 @@ "repository": {

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is too big to display

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc