Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion src/containers.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,10 @@ const CONSTANTS = {
'moov': toUint8([0x6D, 0x6F, 0x6F, 0x76]),

// moof string literal in hex
'moof': toUint8([0x6D, 0x6F, 0x6F, 0x66])
'moof': toUint8([0x6D, 0x6F, 0x6F, 0x66]),

// "WEBVTT" string literal in hex
'vtt': toUint8([0x57, 0x45, 0x42, 0x56, 0x54, 0x54])
};

const _isLikely = {
Expand Down Expand Up @@ -104,6 +107,11 @@ const _isLikely = {
return bytesMatch(bytes, CONSTANTS.ac3, {offset});
},

// Must be checked before ts. The sorting of isLikelyTypes ensures this.
vtt(bytes) {
return bytesMatch(bytes, CONSTANTS.vtt);
},

ts(bytes) {
if (bytes.length < 189 && bytes.length >= 1) {
return bytes[0] === 0x47;
Expand Down
24 changes: 23 additions & 1 deletion test/container.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,29 @@ const testData = {
// seq_parameter_set_rbsp
'h264': toUint8([0x00, 0x00, 0x00, 0x01, 0x67, 0x42, 0xc0, 0x0d, 0xd9, 0x01, 0xa1, 0xfa, 0x10, 0x00, 0x00, 0x03, 0x20, 0x00, 0x00, 0x95, 0xe0, 0xf1, 0x42, 0xa4, 0x80, 0x00, 0x00, 0x00, 0x01]),
// video_parameter_set_rbsp
'h265': toUint8([0x00, 0x00, 0x00, 0x01, 0x40, 0x01, 0x0c, 0x01, 0xff, 0xff, 0x24, 0x08, 0x00, 0x00, 0x00, 0x9c, 0x08, 0x00, 0x00, 0x00, 0x00, 0x78, 0x95, 0x98, 0x09, 0x00, 0x00, 0x00, 0x01])
'h265': toUint8([0x00, 0x00, 0x00, 0x01, 0x40, 0x01, 0x0c, 0x01, 0xff, 0xff, 0x24, 0x08, 0x00, 0x00, 0x00, 0x9c, 0x08, 0x00, 0x00, 0x00, 0x00, 0x78, 0x95, 0x98, 0x09, 0x00, 0x00, 0x00, 0x01]),
// A vtt similar to one seen in the wild that coincidently would match the test for ts,
// by having 0x47 ("G") 188 bytes apart
'vtt': toUint8([
0x57, 0x45, 0x42, 0x56, 0x54, 0x54, 0x09, 0x23, 0x45, 0x6c, 0x65, 0x6d, 0x65, 0x6e, 0x74, 0x61,
0x6c, 0x20, 0x4d, 0x65, 0x64, 0x69, 0x61, 0x20, 0x45, 0x6e, 0x67, 0x69, 0x6e, 0x65, 0x28, 0x54,
0x4d, 0x29, 0x20, 0x32, 0x2e, 0x31, 0x38, 0x2e, 0x30, 0x2e, 0x30, 0x0a, 0x58, 0x2d, 0x54, 0x49,
0x4d, 0x45, 0x53, 0x54, 0x41, 0x4d, 0x50, 0x2d, 0x4d, 0x41, 0x50, 0x3d, 0x4c, 0x4f, 0x43, 0x41,
0x4c, 0x3a, 0x30, 0x30, 0x3a, 0x30, 0x30, 0x3a, 0x30, 0x30, 0x2e, 0x30, 0x30, 0x30, 0x2c, 0x4d,
0x50, 0x45, 0x47, 0x54, 0x53, 0x3a, 0x31, 0x38, 0x33, 0x36, 0x30, 0x30, 0x0a, 0x0a, 0x30, 0x30,
0x3a, 0x30, 0x30, 0x3a, 0x30, 0x30, 0x2e, 0x30, 0x30, 0x30, 0x20, 0x2d, 0x2d, 0x3e, 0x20, 0x30,
0x30, 0x3a, 0x30, 0x30, 0x3a, 0x30, 0x33, 0x2e, 0x34, 0x34, 0x30, 0x0a, 0x21, 0x20, 0x54, 0x68,
0x69, 0x73, 0x20, 0x68, 0x61, 0x70, 0x70, 0x65, 0x6e, 0x73, 0x20, 0x74, 0x6f, 0x20, 0x6d, 0x61,
0x74, 0x63, 0x68, 0x20, 0x74, 0x68, 0x65, 0x20, 0x74, 0x65, 0x73, 0x74, 0x20, 0x66, 0x6f, 0x72,
0x0a, 0x74, 0x73, 0x20, 0x66, 0x69, 0x6c, 0x65, 0x73, 0x0a, 0x0a, 0x30, 0x30, 0x3a, 0x30, 0x30,
0x3a, 0x30, 0x33, 0x2e, 0x34, 0x34, 0x30, 0x20, 0x2d, 0x2d, 0x3e, 0x20, 0x30, 0x30, 0x3a, 0x30,
0x30, 0x3a, 0x30, 0x34, 0x2e, 0x36, 0x34, 0x30, 0x0a, 0x62, 0x65, 0x63, 0x61, 0x75, 0x73, 0x65,
0x20, 0x74, 0x68, 0x61, 0x74, 0x20, 0x6c, 0x6f, 0x6f, 0x6b, 0x73, 0x20, 0x66, 0x6f, 0x72, 0x20,
0x30, 0x78, 0x34, 0x37, 0x2c, 0x20, 0x77, 0x68, 0x69, 0x63, 0x68, 0x20, 0x69, 0x73, 0x0a, 0x0a,
0x30, 0x30, 0x3a, 0x30, 0x30, 0x3a, 0x30, 0x34, 0x2e, 0x38, 0x30, 0x30, 0x20, 0x2d, 0x2d, 0x3e,
0x20, 0x30, 0x30, 0x3a, 0x30, 0x30, 0x3a, 0x30, 0x38, 0x2e, 0x32, 0x34, 0x30, 0x0a, 0x47, 0x2c,
0x20, 0x31, 0x38, 0x38, 0x20, 0x62, 0x79, 0x74, 0x65, 0x73, 0x20, 0x61, 0x70, 0x61, 0x72, 0x74
])
};

// seq_parameter_set_rbsp
Expand Down