threepp icon indicating copy to clipboard operation
threepp copied to clipboard

Render to Video?

Open Choons opened this issue 1 year ago • 3 comments

Hi, I've been using threepp several days now and it's great! This is a question rather than an issue: does threepp have a way to render to video? If not, has anyone done this, or could give a suggestion how I could implement it? Something with GLFW + FFMPEG capturing frames, perhaps?

Choons avatar Oct 01 '24 21:10 Choons

I'm not sure what would be the more effective procedure here, but you do have the possibility to read the underlying pixel data from the GPU from the GLRenderer.

void readPixels(const Vector2& position, const WindowSize& size, Format format, unsigned char* data)

You may also copy the framebuffer into a texture. Demo

markaren avatar Oct 02 '24 07:10 markaren

Thanks for the leads, Mark! I'll experiment with those and report back how it goes.

Choons avatar Oct 02 '24 17:10 Choons

Rendering to video is surprisingly tricky and tends to bring in a lot of external dependencies. The solution for simple video files is something like gwavi [https://github.com/olegk0/libgwavi] which is a tiny library that lets you create AVI files from JPEG and PNG format images. It is pretty easy to convert the raw data from readPixels to JPEG in memory and then you can you can create MJPG movies. Not particularly modern but a widely readable format that is easy to edit. The AVIWriter.cpp class in GaitSym5 uses this and lets you write movies in just over 100 lines of code. It is using threecpp under Qt so it can let Qt do some of the conversion but it looks like threecpp can also do JPEG conversion in writeFramebuffer.

wol101 avatar Jul 11 '25 11:07 wol101