Skip to content
This repository was archived by the owner on Oct 20, 2022. It is now read-only.

Commit 95e27f7

Browse files
nicosangbbert
authored andcommitted
add parsing of 'subs' mp4 box
1 parent 141dbbd commit 95e27f7

File tree

2 files changed

+53
-0
lines changed

2 files changed

+53
-0
lines changed

app/lib/mp4lib/mp4lib-boxes.js

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3072,4 +3072,56 @@ mp4lib.boxes.TfrfBox.prototype.read = function(data, pos, end) {
30723072
return this.localPos;
30733073
};
30743074

3075+
// --------------------------- subs -----------------------------
3076+
mp4lib.boxes.SubSampleInformationBox = function(size) {
3077+
mp4lib.boxes.FullBox.call(this, 'subs', size);
3078+
};
3079+
3080+
mp4lib.boxes.SubSampleInformationBox.prototype = Object.create(mp4lib.boxes.FullBox.prototype);
3081+
mp4lib.boxes.SubSampleInformationBox.prototype.constructor = mp4lib.boxes.SubSampleInformationBox;
3082+
3083+
mp4lib.boxes.SubSampleInformationBox.prototype.computeLength = function() {
3084+
mp4lib.boxes.FullBox.prototype.computeLength.call(this);
3085+
// To Define if needed
3086+
};
3087+
3088+
mp4lib.boxes.SubSampleInformationBox.prototype.read = function(data, pos, end) {
3089+
mp4lib.boxes.FullBox.prototype.read.call(this, data, pos, end);
3090+
var i = 0,
3091+
j = 0,
3092+
struct = {},
3093+
subSampleStruct = {};
3094+
3095+
this.entry_count = this._readData(data, mp4lib.fields.FIELD_UINT32);
3096+
this.entry = [];
3097+
for (i = 0; i < this.entry_count; i++) {
3098+
struct = {};
3099+
struct.sample_delta = this._readData(data, mp4lib.fields.FIELD_UINT32);
3100+
struct.subsample_count = this._readData(data, mp4lib.fields.FIELD_UINT16);
3101+
if (struct.subsample_count > 0) {
3102+
struct.subSampleEntries = [];
3103+
for (j=0; j < struct.subsample_count; j++) {
3104+
subSampleStruct = {};
3105+
if (this.version === 1) {
3106+
subSampleStruct.subsample_size = this._readData(data, mp4lib.fields.FIELD_UINT32);
3107+
} else {
3108+
subSampleStruct.subsample_size = this._readData(data, mp4lib.fields.FIELD_UINT16);
3109+
}
3110+
subSampleStruct.subsample_priority = this._readData(data, mp4lib.fields.FIELD_UINT8);
3111+
subSampleStruct.discardable = this._readData(data, mp4lib.fields.FIELD_UINT8);
3112+
subSampleStruct.reserved = this._readData(data, mp4lib.fields.FIELD_UINT32);
3113+
struct.subSampleEntries.push(subSampleStruct);
3114+
}
3115+
}
3116+
this.entry.push(struct);
3117+
}
3118+
3119+
return this.localPos;
3120+
};
3121+
3122+
mp4lib.boxes.SubSampleInformationBox.prototype.write = function(data, pos) {
3123+
mp4lib.boxes.FullBox.prototype.write.call(this, data, pos);
3124+
// To Define if needed
3125+
};
3126+
30753127
mp4lib.registerTypeBoxes();

app/lib/mp4lib/mp4lib.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ var mp4lib = (function() {
9595
boxTypeArray["stss"] = mp4lib.boxes.SyncSampleBox;
9696
boxTypeArray["tref"] = mp4lib.boxes.TrackReferenceBox;
9797
boxTypeArray["frma"] = mp4lib.boxes.OriginalFormatBox;
98+
boxTypeArray["subs"] = mp4lib.boxes.SubSampleInformationBox;
9899
//extended types
99100
boxTypeArray[JSON.stringify([0x6D, 0x1D, 0x9B, 0x05, 0x42, 0xD5, 0x44, 0xE6, 0x80, 0xE2, 0x14, 0x1D, 0xAF, 0xF7, 0x57, 0xB2])] = mp4lib.boxes.TfxdBox;
100101
boxTypeArray[JSON.stringify([0xD4, 0x80, 0x7E, 0xF2, 0xCA, 0x39, 0x46, 0x95, 0x8E, 0x54, 0x26, 0xCB, 0x9E, 0x46, 0xA7, 0x9F])] = mp4lib.boxes.TfrfBox;

0 commit comments

Comments
 (0)