Skip to content

Commit b75a7a4

Browse files
author
Nikola Hristov
authored
feat: parse ctts atom in mp4 inspector (#379)
1 parent cf96c0d commit b75a7a4

File tree

3 files changed

+56
-10
lines changed

3 files changed

+56
-10
lines changed

lib/tools/mp4-inspector.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -425,6 +425,24 @@ var
425425
boxes: inspectMp4(data)
426426
};
427427
},
428+
ctts: function(data) {
429+
var
430+
view = new DataView(data.buffer, data.byteOffset, data.byteLength),
431+
result = {
432+
version: view.getUint8(0),
433+
flags: new Uint8Array(data.subarray(1, 4)),
434+
compositionOffsets: []
435+
},
436+
entryCount = view.getUint32(4),
437+
i;
438+
for (i = 8; entryCount; i += 8, entryCount--) {
439+
result.compositionOffsets.push({
440+
sampleCount: view.getUint32(i),
441+
sampleOffset: view[(result.version === 0 ? 'getUint32' :'getInt32')](i + 4)
442+
});
443+
}
444+
return result;
445+
},
428446
stco: function(data) {
429447
var
430448
view = new DataView(data.buffer, data.byteOffset, data.byteLength),

test/mp4-inspector.test.js

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ QUnit.test('can parse a moov', function(assert) {
215215
var result = QUnit.dump.parse(mp4.tools.inspect(new Uint8Array(data)));
216216
var expected = QUnit.dump.parse([{
217217
type: 'moov',
218-
size: 1061,
218+
size: 1109,
219219
boxes: [{
220220
type: 'mvhd',
221221
version: 1,
@@ -231,7 +231,7 @@ QUnit.test('can parse a moov', function(assert) {
231231
nextTrackId: 2
232232
}, {
233233
type: 'trak',
234-
size: 475,
234+
size: 499,
235235
boxes: [{
236236
type: 'tkhd',
237237
flags: new Uint8Array([0, 0, 0]),
@@ -263,7 +263,7 @@ QUnit.test('can parse a moov', function(assert) {
263263
}]
264264
}, {
265265
type: 'mdia',
266-
size: 327,
266+
size: 351,
267267
boxes: [{
268268
type: 'mdhd',
269269
version: 1,
@@ -283,7 +283,7 @@ QUnit.test('can parse a moov', function(assert) {
283283
size: 37
284284
}, {
285285
type: 'minf',
286-
size: 238,
286+
size: 262,
287287
boxes: [{
288288
type: 'dinf',
289289
size: 36,
@@ -301,7 +301,7 @@ QUnit.test('can parse a moov', function(assert) {
301301
}]
302302
}, {
303303
type: 'stbl',
304-
size: 194,
304+
size: 218,
305305
boxes: [{
306306
type: 'stsd',
307307
size: 114,
@@ -357,13 +357,21 @@ QUnit.test('can parse a moov', function(assert) {
357357
version: 1,
358358
flags: new Uint8Array([0, 0, 0]),
359359
chunkOffsets: [1]
360+
}, {
361+
type: 'ctts',
362+
size: 24,
363+
version: 0,
364+
flags: new Uint8Array([0, 0, 0]),
365+
compositionOffsets: [
366+
{ sampleCount: 1, sampleOffset: 1 }
367+
]
360368
}]
361369
}]
362370
}]
363371
}]
364372
}, {
365373
type: 'trak',
366-
size: 458,
374+
size: 482,
367375
boxes: [{
368376
type: 'tkhd',
369377
flags: new Uint8Array([0, 0, 0]),
@@ -395,7 +403,7 @@ QUnit.test('can parse a moov', function(assert) {
395403
}]
396404
}, {
397405
type: 'mdia',
398-
size: 302,
406+
size: 326,
399407
boxes: [{
400408
type: 'mdhd',
401409
version: 1,
@@ -415,7 +423,7 @@ QUnit.test('can parse a moov', function(assert) {
415423
size: 37
416424
}, {
417425
type: 'minf',
418-
size: 213,
426+
size: 237,
419427
boxes: [{
420428
type: 'dinf',
421429
size: 36,
@@ -433,7 +441,7 @@ QUnit.test('can parse a moov', function(assert) {
433441
}]
434442
}, {
435443
type: 'stbl',
436-
size: 169,
444+
size: 193,
437445
boxes: [{
438446
type: 'stsd',
439447
size: 89,
@@ -492,6 +500,14 @@ QUnit.test('can parse a moov', function(assert) {
492500
sampleDescriptionIndex: 1
493501
}],
494502
size: 28
503+
}, {
504+
type: 'ctts',
505+
size: 24,
506+
version: 1,
507+
flags: new Uint8Array([0, 0, 0]),
508+
compositionOffsets: [
509+
{ sampleCount: 1, sampleOffset: -1 }
510+
]
495511
}, {
496512
type: 'stco',
497513
size: 20,

test/utils/mp4-helpers.js

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,13 @@ module.exports.sampleMoov =
194194
0x01, // version 1
195195
0x00, 0x00, 0x00, // flags
196196
0x00, 0x00, 0x00, 0x01, // entry_count
197-
0x00, 0x00, 0x00, 0x01))))), // chunk_offset
197+
0x00, 0x00, 0x00, 0x01), // chunk_offset
198+
box('ctts',
199+
0x00, // version 0
200+
0x00, 0x00, 0x00, // flags
201+
0x00, 0x00, 0x00, 0x01, // entry_count
202+
0x00, 0x00, 0x00, 0x01, // sample_count
203+
0x00, 0x00, 0x00, 0x01))))), // sample_offset
198204
box('trak',
199205
box('tkhd',
200206
0x01, // version 1
@@ -291,6 +297,12 @@ module.exports.sampleMoov =
291297
0x00, 0x00, 0x00, 0x02, // first_chunk
292298
0x00, 0x00, 0x00, 0x03, // samples_per_chunk
293299
0x00, 0x00, 0x00, 0x01), // sample_description_index
300+
box('ctts',
301+
0x01, // version 1
302+
0x00, 0x00, 0x00, // flags
303+
0x00, 0x00, 0x00, 0x01, // entry_count
304+
0x00, 0x00, 0x00, 0x01, // sample_count
305+
0xff, 0xff, 0xff, 0xff), // sample_offset
294306
box('stco',
295307
0x01, // version 1
296308
0x00, 0x00, 0x00, // flags

0 commit comments

Comments
 (0)