parsing upto avc1 and mp4a boxes
This commit is contained in:
parent
33a01c9552
commit
7447699735
1 changed files with 40 additions and 6 deletions
46
mp4-tree.js
46
mp4-tree.js
|
@ -17,8 +17,38 @@ class MP4Tree {
|
|||
}
|
||||
|
||||
parse_codecs() {
|
||||
this.parse_until('moov');
|
||||
console.log(this.idx);
|
||||
this.parse_into('moov', 8);
|
||||
while (this.idx < this.data.byteLength) {
|
||||
if (!this.parse_until('trak')) {
|
||||
break;
|
||||
}
|
||||
const curr_track_end = this.idx + this.read_next_head().len;
|
||||
this.idx += 8
|
||||
this.parse_into('mdia', 8);
|
||||
this.parse_into('minf', 8);
|
||||
const track_type_head = this.read_next_head().name;
|
||||
if (track_type_head == 'smhd' || track_type_head == 'vmhd') {
|
||||
this.parse_into('stbl', 8);
|
||||
this.parse_into('stsd', 16);
|
||||
const media_sample = this.read_next_head().name;
|
||||
if (media_sample == 'avc1') {
|
||||
this.parse_avc1();
|
||||
} else if (media_sample == 'mp4a') {
|
||||
this.parse_mp4a();
|
||||
}
|
||||
}
|
||||
this.idx = curr_track_end;
|
||||
}
|
||||
}
|
||||
|
||||
parse_avc1() {
|
||||
this.parse_into('avc1', 86);
|
||||
console.log(this.read_next_head());
|
||||
}
|
||||
|
||||
parse_mp4a() {
|
||||
this.parse_into('mp4a', 36);
|
||||
console.log(this.read_next_head());
|
||||
}
|
||||
|
||||
get_mime() {
|
||||
|
@ -29,21 +59,25 @@ class MP4Tree {
|
|||
return this.codecs.join(', ');
|
||||
}
|
||||
|
||||
parse_into(name, header_offset) {
|
||||
this.parse_until(name);
|
||||
this.idx += header_offset;
|
||||
}
|
||||
|
||||
parse_until(name) {
|
||||
let curr_head = null;
|
||||
while (this.idx < this.data.byteLength) {
|
||||
while (this.idx + 8 < this.data.byteLength) {
|
||||
curr_head = this.read_next_head();
|
||||
console.log(curr_head);
|
||||
if (curr_head.name == name) {
|
||||
break;
|
||||
return true;
|
||||
} else {
|
||||
this.idx += curr_head.len;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
read_next_head() {
|
||||
return {"len": this.data.getUint32(this.idx), "name": this.data.getString(this.idx + 4, 4)};
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue