Skip to content

Commit

Permalink
feat: parse ctts atom in mp4 inspector (#379)
Browse files Browse the repository at this point in the history
  • Loading branch information
nklhtv committed Mar 15, 2021
1 parent cf96c0d commit b75a7a4
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 10 deletions.
18 changes: 18 additions & 0 deletions lib/tools/mp4-inspector.js
Original file line number Diff line number Diff line change
Expand Up @@ -425,6 +425,24 @@ var
boxes: inspectMp4(data)
};
},
ctts: function(data) {
var
view = new DataView(data.buffer, data.byteOffset, data.byteLength),
result = {
version: view.getUint8(0),
flags: new Uint8Array(data.subarray(1, 4)),
compositionOffsets: []
},
entryCount = view.getUint32(4),
i;
for (i = 8; entryCount; i += 8, entryCount--) {
result.compositionOffsets.push({
sampleCount: view.getUint32(i),
sampleOffset: view[(result.version === 0 ? 'getUint32' :'getInt32')](i + 4)
});
}
return result;
},
stco: function(data) {
var
view = new DataView(data.buffer, data.byteOffset, data.byteLength),
Expand Down
34 changes: 25 additions & 9 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: 1061,
size: 1109,
boxes: [{
type: 'mvhd',
version: 1,
Expand All @@ -231,7 +231,7 @@ QUnit.test('can parse a moov', function(assert) {
nextTrackId: 2
}, {
type: 'trak',
size: 475,
size: 499,
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: 327,
size: 351,
boxes: [{
type: 'mdhd',
version: 1,
Expand All @@ -283,7 +283,7 @@ QUnit.test('can parse a moov', function(assert) {
size: 37
}, {
type: 'minf',
size: 238,
size: 262,
boxes: [{
type: 'dinf',
size: 36,
Expand All @@ -301,7 +301,7 @@ QUnit.test('can parse a moov', function(assert) {
}]
}, {
type: 'stbl',
size: 194,
size: 218,
boxes: [{
type: 'stsd',
size: 114,
Expand Down Expand Up @@ -357,13 +357,21 @@ QUnit.test('can parse a moov', function(assert) {
version: 1,
flags: new Uint8Array([0, 0, 0]),
chunkOffsets: [1]
}, {
type: 'ctts',
size: 24,
version: 0,
flags: new Uint8Array([0, 0, 0]),
compositionOffsets: [
{ sampleCount: 1, sampleOffset: 1 }
]
}]
}]
}]
}]
}, {
type: 'trak',
size: 458,
size: 482,
boxes: [{
type: 'tkhd',
flags: new Uint8Array([0, 0, 0]),
Expand Down Expand Up @@ -395,7 +403,7 @@ QUnit.test('can parse a moov', function(assert) {
}]
}, {
type: 'mdia',
size: 302,
size: 326,
boxes: [{
type: 'mdhd',
version: 1,
Expand All @@ -415,7 +423,7 @@ QUnit.test('can parse a moov', function(assert) {
size: 37
}, {
type: 'minf',
size: 213,
size: 237,
boxes: [{
type: 'dinf',
size: 36,
Expand All @@ -433,7 +441,7 @@ QUnit.test('can parse a moov', function(assert) {
}]
}, {
type: 'stbl',
size: 169,
size: 193,
boxes: [{
type: 'stsd',
size: 89,
Expand Down Expand Up @@ -492,6 +500,14 @@ QUnit.test('can parse a moov', function(assert) {
sampleDescriptionIndex: 1
}],
size: 28
}, {
type: 'ctts',
size: 24,
version: 1,
flags: new Uint8Array([0, 0, 0]),
compositionOffsets: [
{ sampleCount: 1, sampleOffset: -1 }
]
}, {
type: 'stco',
size: 20,
Expand Down
14 changes: 13 additions & 1 deletion test/utils/mp4-helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,13 @@ module.exports.sampleMoov =
0x01, // version 1
0x00, 0x00, 0x00, // flags
0x00, 0x00, 0x00, 0x01, // entry_count
0x00, 0x00, 0x00, 0x01))))), // chunk_offset
0x00, 0x00, 0x00, 0x01), // chunk_offset
box('ctts',
0x00, // version 0
0x00, 0x00, 0x00, // flags
0x00, 0x00, 0x00, 0x01, // entry_count
0x00, 0x00, 0x00, 0x01, // sample_count
0x00, 0x00, 0x00, 0x01))))), // sample_offset
box('trak',
box('tkhd',
0x01, // version 1
Expand Down Expand Up @@ -291,6 +297,12 @@ module.exports.sampleMoov =
0x00, 0x00, 0x00, 0x02, // first_chunk
0x00, 0x00, 0x00, 0x03, // samples_per_chunk
0x00, 0x00, 0x00, 0x01), // sample_description_index
box('ctts',
0x01, // version 1
0x00, 0x00, 0x00, // flags
0x00, 0x00, 0x00, 0x01, // entry_count
0x00, 0x00, 0x00, 0x01, // sample_count
0xff, 0xff, 0xff, 0xff), // sample_offset
box('stco',
0x01, // version 1
0x00, 0x00, 0x00, // flags
Expand Down

0 comments on commit b75a7a4

Please sign in to comment.