Skip to content

Commit

Permalink
feat: stss atom parsing (#380)
Browse files Browse the repository at this point in the history
  • Loading branch information
nklhtv committed Mar 29, 2021
1 parent b75a7a4 commit 305eb4f
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 5 deletions.
15 changes: 15 additions & 0 deletions lib/tools/mp4-inspector.js
Original file line number Diff line number Diff line change
Expand Up @@ -443,6 +443,21 @@ var
}
return result;
},
stss: function(data) {
var
view = new DataView(data.buffer, data.byteOffset, data.byteLength),
result = {
version: view.getUint8(0),
flags: new Uint8Array(data.subarray(1, 4)),
syncSamples: []
},
entryCount = view.getUint32(4),
i;
for (i = 8; entryCount; i += 4, entryCount--) {
result.syncSamples.push(view.getUint32(i));
}
return result;
},
stco: function(data) {
var
view = new DataView(data.buffer, data.byteOffset, data.byteLength),
Expand Down
16 changes: 11 additions & 5 deletions test/mp4-inspector.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ QUnit.test('can parse a moov', function(assert) {
var result = QUnit.dump.parse(mp4.tools.inspect(new Uint8Array(data)));
var expected = QUnit.dump.parse([{
type: 'moov',
size: 1109,
size: 1129,
boxes: [{
type: 'mvhd',
version: 1,
Expand All @@ -231,7 +231,7 @@ QUnit.test('can parse a moov', function(assert) {
nextTrackId: 2
}, {
type: 'trak',
size: 499,
size: 519,
boxes: [{
type: 'tkhd',
flags: new Uint8Array([0, 0, 0]),
Expand Down Expand Up @@ -263,7 +263,7 @@ QUnit.test('can parse a moov', function(assert) {
}]
}, {
type: 'mdia',
size: 351,
size: 371,
boxes: [{
type: 'mdhd',
version: 1,
Expand All @@ -283,7 +283,7 @@ QUnit.test('can parse a moov', function(assert) {
size: 37
}, {
type: 'minf',
size: 262,
size: 282,
boxes: [{
type: 'dinf',
size: 36,
Expand All @@ -301,7 +301,7 @@ QUnit.test('can parse a moov', function(assert) {
}]
}, {
type: 'stbl',
size: 218,
size: 238,
boxes: [{
type: 'stsd',
size: 114,
Expand Down Expand Up @@ -357,6 +357,12 @@ QUnit.test('can parse a moov', function(assert) {
version: 1,
flags: new Uint8Array([0, 0, 0]),
chunkOffsets: [1]
}, {
type: 'stss',
size: 20,
version: 0,
flags: new Uint8Array([0, 0, 0]),
syncSamples: [1]
}, {
type: 'ctts',
size: 24,
Expand Down
5 changes: 5 additions & 0 deletions test/utils/mp4-helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,11 @@ module.exports.sampleMoov =
0x00, 0x00, 0x00, // flags
0x00, 0x00, 0x00, 0x01, // entry_count
0x00, 0x00, 0x00, 0x01), // chunk_offset
box('stss',
0x00, // version 0
0x00, 0x00, 0x00, // flags
0x00, 0x00, 0x00, 0x01, // entry_count
0x00, 0x00, 0x00, 0x01), // sync_sample
box('ctts',
0x00, // version 0
0x00, 0x00, 0x00, // flags
Expand Down

0 comments on commit 305eb4f

Please sign in to comment.