From e94d0634221564338852bf1d412adab3a7ad45aa Mon Sep 17 00:00:00 2001 From: Muaz Ahmad Date: Wed, 23 Aug 2023 23:13:07 +0500 Subject: [PATCH] proper reading of codecs done --- hls-player.js | 1 + mp4-tree.js | 9 +++++++-- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/hls-player.js b/hls-player.js index 5f55aa9..f84b2b3 100644 --- a/hls-player.js +++ b/hls-player.js @@ -51,6 +51,7 @@ class VideoLoader { async prepare_buffer() { let init_frag = await this.fetch_video('/vid/' + this.stream_key + '/init.mp4'); let mime = (new MP4Tree(init_frag)).get_mime(); + console.log(mime); } async fetch_video(uri) { diff --git a/mp4-tree.js b/mp4-tree.js index aec4acf..18ef1aa 100644 --- a/mp4-tree.js +++ b/mp4-tree.js @@ -43,12 +43,17 @@ class MP4Tree { parse_avc1() { this.parse_into('avc1', 86); - console.log(this.read_next_head()); + this.parse_into('avcC', 8); + const avc_profile = (this.data.getUint32(this.idx) & 0xffffff).toString(16); + this.codecs.push('avc1.' + avc_profile); } parse_mp4a() { this.parse_into('mp4a', 36); - console.log(this.read_next_head()); + this.parse_into('esds', 12); + const oti = this.data.getUint8(this.idx + 13).toString(16); + const aot = (this.data.getUint8(this.idx + 31) >> 3).toString(10); + this.codecs.push(["mp4a", oti, aot].join('.')); } get_mime() {