Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add basic bring-your-own-encoder rendering
This adds a basic encoder-agnostic rendering function to renin, so that you can render your demos to video. To use this, you need to add some boilerplate/integration code to your demo project. In your project, you can for instance use mp4-wasm as the encoder. Here is a quick guide on how to do that. First, install mp4-wasm: ```bash yarn add mp4-wasm ``` Then, add these imports to the top of your demo's `main.ts`: ```typescript import loadMP4Module from "mp4-wasm"; import mp4wasm from "mp4-wasm/build/mp4.wasm?url"; ``` And finally, comment out `renin.loop()` in `main.ts` and instead do something like this: ```typescript // commented out for rendering purposes // renin.loop() (async () => { const wasmBinary = await (await fetch(mp4wasm)).arrayBuffer(); const MP4 = await loadMP4Module({ wasmBinary }); const width = 1920; const height = 1080; const encoder = MP4.createWebCodecsEncoder({ width, height, fps: 60, encoderOptions: { framerate: 60, bitrate: 24_000_000, }, }); render(renin, { encoder, width, height }); })(); ``` Now, the demo should play automatically when you visit renin in the browser, and at the end a render.mp4 will be automatically downloaded. It is without sound though, so we can add the music using ffmpeg: ```bash ffmpeg -i render.mp4 -i music.ogg -c:v copy -map 0:v -map 1:a -y output.mp4 ``` Now you have a finished video file that you can upload to YouTube! mp4-wasm doesn't play nice with building renin as a lib -- otherwise we could have bundled it with renin to make things easier.
- Loading branch information