mattdesl / mp4-h264

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

RGB vs YUV clarification #3

Closed mourner closed 3 years ago

mourner commented 3 years ago

One more thing that's not clear from the docs / examples alone:

encoder.encodeYUV(yuv) Encodes a YUV image. See ./test/util/RGBAtoYUV.js for an example of how to go from RGB to YUV.

This implies there would be a reason to convert RGB to YUV prior to encoding, rather than calling encodeRGB directly — if that's the case, what's the advantage of this? Woes the resulting video differ in any way? mediainfo on the encodeRGB-encoded resulting videos shows that it's YUV-encoded.

Thanks in advance for any clarification on this!

mourner commented 3 years ago

Addressed in https://github.com/mattdesl/mp4-h264/commit/7ffcba9baca72c9cd91afa75fa6b604850568237, thank you!

mattdesl commented 3 years ago

The H264 encoder only accepts YUV frames. When you call encodeRGB it will just do the conversion into YUV natively, which I assume is faster than doing it in JS, but there may be some special cases where you want to send YUV frames.

Might need to explore this a little more actually, and perhaps add a way to enable JS-side RGB to YUV conversion. YUV frames are much smaller than sending RGB(A), and an encoder that only needs to handle YUV will use much less memory.