Added FLV extractor.

This commit is contained in:
n1474335 2019-01-03 18:40:22 +00:00
parent cd0c86e0d6
commit 0449c46b38
2 changed files with 79 additions and 8 deletions

View file

@ -417,7 +417,7 @@ export const FILE_SIGNATURES = {
2: 0x56,
3: 0x1
},
extractor: null
extractor: extractFLV
},
],
"Audio": [
@ -1285,3 +1285,49 @@ export function extractBMP(bytes, offset) {
return stream.carve();
}
/**
* FLV extractor.
*
* @param {Uint8Array} bytes
* @param {number} offset
* @returns {Uint8Array}
*/
export function extractFLV(bytes, offset) {
const stream = new Stream(bytes.slice(offset));
// Move past signature, version and flags
stream.moveForwardsBy(5);
// Read header size
const headerSize = stream.readInt(4, "be");
// Skip through the rest of the header
stream.moveForwardsBy(headerSize - 9);
let tagSize = -11; // Fake size of previous tag header
while (stream.position < stream.length) {
const prevTagSize = stream.readInt(4, "be");
const tagType = stream.readInt(1, "be");
if ([8, 9, 18].indexOf(tagType) < 0) {
// This tag is not valid
stream.moveBackwardsBy(1);
break;
}
if (prevTagSize !== tagSize + 11) {
// Previous tag was not valid
stream.moveBackwardsBy(tagSize + 11);
break;
}
tagSize = stream.readInt(3, "be");
// Move past the rest of the tag header and payload
stream.moveForwardsBy(7 + tagSize);
}
return stream.carve();
}