mattdesl / mp4-h264

[project suspended] MP4 + H264 encoding for the browser with WASM
MIT License
223 stars 12 forks source link

Encoding directly into memory with WebGL 1? #1

Open mourner opened 3 years ago

mourner commented 3 years ago

@mattdesl Thanks for the amazing library! Quick question — is there any particular limitation that prevents us from reading RGBA pixels of a WebGL 1 context into encoder memory?

Looking at readPixels docs, WebGL 2 introduces an optional offset argument, but can't we simply make an offset view into the buffer instead, e.g. like this?

const ptr = encoder.getRGBPointer();

gl.readPixels(..., encoder.memory().subarray(ptr));
mourner commented 3 years ago

I tested it locally and it works, so I think you could simplify some code around this and update docs. 🎉

mattdesl commented 3 years ago

Ah nice! Didn’t realize subarray works like that. I guess there is a bit more GC churn compared to WebGL2 but probably not such a big deal.

Thanks! Will update docs.

mourner commented 3 years ago

@mattdesl probably shouldn't affect GC much, since subarray is just a view into the same memory.