Tencent / vap

VAP是企鹅电竞开发,用于播放特效动画的实现方案。具有高压缩率、硬件解码等优点。同时支持 iOS,Android,Web 平台。
Other
3.84k stars 513 forks source link

web端vap必须要传config文件吗,不能从mp4中获取吗 #333

Open iamhujiebin opened 1 year ago

iamhujiebin commented 1 year ago

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.

wangbo122 commented 1 year ago

mp4中包含了json信息,可以读取mp4里的vapc字段

yongquan88 commented 10 months ago

你好 请问如何读取mp4里的vapc字段内容呢?开发框架:electron

pipihua666 commented 5 months ago

mp4中包含了json信息,可以读取mp4里的vapc字段

请问下读取方法是什么

oloshe commented 2 months ago

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);
        }
    });
}
oloshe commented 2 months ago
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,
    };
}
Leidianfawangck commented 2 months ago
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,
    };
}

大佬请问有代码仓库吗?

oloshe commented 2 months ago
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,然后去读取字节获取。可以参考安卓端的实现