Skip to content

Instantly share code, notes, and snippets.

View djkskqyr3's full-sized avatar

James Chan djkskqyr3

View GitHub Profile
@saravanannkl
saravanannkl / mediastream-I420A-to-I420-converter.js
Created November 23, 2021 01:02
Media stream video frame I420A to I420 converter
// Based on https://web.dev/mediastreamtrack-insertable-media-processing/
// Uses Webcodecs API, which is supported only in Chrome as of November 2021
function convertI420AFrameToI420Frame(frame) {
const { width, height } = frame.codedRect;
// Y, U, V, Alpha values are stored sequentially. Take only YUV values
const buffer = new Uint8Array(width * height * 3);
frame.copyTo(buffer, { rect: frame.codedRect });
const init = {
timestamp: 0,