Open iamhujiebin opened 1 year ago
mp4中包含了json信息,可以读取mp4里的vapc字段
你好 请问如何读取mp4里的vapc字段内容呢?开发框架:electron
mp4中包含了json信息,可以读取mp4里的vapc字段
请问下读取方法是什么
mp4中包含了json信息,可以读取mp4里的vapc字段
请问下读取方法是什么
static readVacpJsonFromArrayBuffer(result: ArrayBuffer) {
return new Promise<any>((resolve, reject) => {
try {
console.time('vapc json decode');
let boxHead: ArrayBuffer;
let head: BoxHead | null = null;
let readIndex = 0;
while (readIndex < result.byteLength) {
boxHead = result.slice(readIndex, readIndex + 8);
// console.debug(readIndex, boxHead);
const h = VapVideo.parseBoxHead(boxHead);
if (!h) break;
if (h.vapc) {
head = h;
break;
}
readIndex += h.length;
}
if (head === null) {
console.log('vapc box head not found');
// 按照默认配置生成config
return reject('xxx');
}
const buf = result.slice(readIndex + 8, readIndex + head.length);
const vapcBuf = VapVideo.de.decode(buf);
console.log(vapcBuf);
const json = JSON.parse(vapcBuf);
console.timeEnd('vapc json decode');
resolve(json);
} catch (e) {
console.error(e);
reject(e);
}
});
}
static parseBoxHead(boxHead: ArrayBuffer): BoxHead | null {
if (boxHead.byteLength !== 8) return null;
let length: number = 0;
const arr = new Uint8Array(boxHead);
length |= (arr[0] & 0xff) << 24;
length |= (arr[1] & 0xff) << 16;
length |= (arr[2] & 0xff) << 8;
length |= arr[3] & 0xff;
return {
length,
// 判断字节是否为 “vapc” 字符串
vapc: arr[4] === 0x76 && arr[5] === 0x61 && arr[6] === 0x70 && arr[7] === 0x63,
};
}
static parseBoxHead(boxHead: ArrayBuffer): BoxHead | null { if (boxHead.byteLength !== 8) return null; let length: number = 0; const arr = new Uint8Array(boxHead); length |= (arr[0] & 0xff) << 24; length |= (arr[1] & 0xff) << 16; length |= (arr[2] & 0xff) << 8; length |= arr[3] & 0xff; return { length, // 判断字节是否为 “vapc” 字符串 vapc: arr[4] === 0x76 && arr[5] === 0x61 && arr[6] === 0x70 && arr[7] === 0x63, }; }
大佬请问有代码仓库吗?
static parseBoxHead(boxHead: ArrayBuffer): BoxHead | null { if (boxHead.byteLength !== 8) return null; let length: number = 0; const arr = new Uint8Array(boxHead); length |= (arr[0] & 0xff) << 24; length |= (arr[1] & 0xff) << 16; length |= (arr[2] & 0xff) << 8; length |= arr[3] & 0xff; return { length, // 判断字节是否为 “vapc” 字符串 vapc: arr[4] === 0x76 && arr[5] === 0x61 && arr[6] === 0x70 && arr[7] === 0x63, }; }
大佬请问有代码仓库吗?
没有,思路就是每次都precache,xhr的responseType设为arraybuffer,然后去读取字节获取。可以参考安卓端的实现
Is your feature request related to a problem? Please describe. A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]
Describe the solution you'd like A clear and concise description of what you want to happen.
Describe alternatives you've considered A clear and concise description of any alternative solutions or features you've considered.
Additional context Add any other context or screenshots about the feature request here.