Inconsistent Behavior of WebCodecs' copyTo() Method Across Different Browsers and Systems

45 Views Asked by At

I'm currently facing an intriguing issue with the WebCodecs API, specifically the copyTo() method. While implementing a feature using this method, I've encountered an 'undefined' error. Curiously, this error does not occur consistently across all platforms. On some devices, the code executes perfectly, but on others, it fails with this error.
I would appreciate any insights or experiences you might have regarding this issue.

const decoder = new VideoDecoder({
    output(frame) {
        // console.log('frame', frame);
        videoFrames.push(frame);
        ctx.drawImage(frame, 0, 0);
        checkFrameReady();
        frame.close();
    },
    error(e) {
        console.error(e);
    },
});
function checkFrameReady() {
    if (videoFrames.length) {
        const vf = videoFrames[0];
        if (vf && !videoBuffer) {
            videoBuffer = new Uint8Array(vf.allocationSize());
            createVideoTextures(vf, videoBuffer.buffer);
        }
        processNewChunk();
    } 
}

async function createVideoTextures(frame: VideoFrame, buffer: ArrayBuffer) {
    let f
    try {
        // console.log('frame', frame, buffer, typeof frame.codedHeight);
        f = frame.clone();
        await f.copyTo(buffer);
    } catch (e) {
        console.error('Error caught:', e);
    } finally {
        // console.log('videoBuffer', buffer);

        // frame.close();
    }
    
}
hardware Browser error
MacBook Pro 13-inch, 2020 2 GHz 4 core Intel Core i5 Chrome 121 undefined
MacBook air 13-inch, 2020 Intel Core i3 Chrome 121 undefined
MacBook Pro 13-inch, 2020 2 GHz 4 core Intel Core i5 Safari no error but very laggy
MacBook Pro 13-inch, 2020 2 GHz 4 core Intel Core i5 Chrome 109 no error
MacBook Pro 14-inch, 2021 M1 pro Chrome 121 no error
MacBook Pro 13-inch, 2021 M1 Chrome 121 no error
MacBook Pro 13-inch, 2021 M1 Chrome 121 no error
Ipad pro, 2021 M1 Chrome 120 no error but very laggy
Ipad pro, 2021 M1 Safari no error but very laggy
Iphone 13 Chrome 120 no error but very laggy
Iphone 13 Safari no error but very laggy
Xiaomi 11 pro, snapdragon 888 Chrome 120 no error

I guess it is a problem with the chip architecture, but there is an x86 device that does not meet the requirements.

0

There are 0 best solutions below