A Rust-based renderer for Remotion videos.

Overview

Rustymotion

A Rust-based renderer for Remotion projects.

🚧 WARNING: This is exploratory work only, use at your own risk.

Design

Remotion allows you to easily write videos using React.

It bundles a React app exposing some global functions to change the layout, depending on the composition and frame set. The Remotion Renderer then serves this app bundle on a URL and uses Puppeteer to open it on a Chromium-based browser to take a screenshot. All the frames in a composition are "screenshotted", and then FFmpeg stitches them into a video file.

For one of my projects, I could neither use a server and nor was happy to ship a Chromium binary. So I thought of emulating the Remotion renderer using what I had on hand — this repo is the result of it working just enough.

Approach

  1. We start with your Bundle. You can create one using either the Remotion CLI (set log-level to verbose) or the @remotion/bundler tool. There's one included in the project.
  2. This bundled site is opened in your browser's native Webview using the excellent wry crate. It handles Webview management across platforms and is used by Tauri apps under the hood.
  3. We run some JS commands in the webview to:
    1. Get a list of compositions and their metadata (dimensions, default props, etc.)
    2. Select one based on input and set it up for rendering.
  4. Then, we start off the "frame screenshotting" process using Wry's Event Loop. This project uses my fork of Wry, which adds a .screenshot() method. The screenshots are written to a file on disk.
  5. We finally use FFmpeg to encode all the screenshots into an .mp4 the same way Remotion does.
  6. Profit ???

Instructions

  1. See src/main.rs for how to use the renderer.
  2. Most of the renderer's code is in src/lib.rs.
  3. Relevant findings from my tinkering with the Remotion bundle are in reference.js.
  4. The included bundle is from Remotion's Hello World with minimal design tweaks.
  5. Running cargo run should hopefully give you the video in out.mp4 if all goes well.

Caveats

I made this hack over some sleepless nights — it is not intended for production, nor can I offer any support for it. I just hope to present this as a proof-of-concept to the Remotion team and hopefully spark some new ideas in folks.

Here's a list of oopsies/gotchas in my current approach. Most of them have solutions:

  1. I've manually inlined bundle.js into its index.html to make it easier to load. It is possible to serve the whole bundle using Wry's custom protocol feature and even support public assets.
  2. The .screenshot() is prone to failing. I plan to properly solve this piece and make an upstream PR in Wry.
  3. We save screenshots in the file system and later on use Ffmpeg to encode them at once.
    1. This is inefficient. We can instead likely capture and encode in parallel. Just store the screenshots in memory and "stream" them to Ffmpeg using the ffmpeg-next crate.
    2. This should be easily doable, I simply don't know how to — maybe @Jonny Burger can help 🙈
  4. It is assumed FFmpeg is available in your PATH, I don't have it bundled in the project but this should also be easily fixable with point 3.1.
  5. Your OS could impose security rules/restrictions on what your webview can do and this might impact your rendering.

There are plenty of other caveats, but hopefully the comments in my code clarify how things are working.

Closing

Thanks for checking out this project. I hope it was insightful and gives you some ideas.

I unfortunately can't take reponsibility of getting this working in your setup at the moment — but I'm happy to answer any questions or have on it over on Twitter or the Remotion Discord. See you there! 👋

You might also like...
Warp is a blazingly fast, Rust-based terminal that makes you and your team more productive at running, debugging, and deploying code and infrastructure.
Warp is a blazingly fast, Rust-based terminal that makes you and your team more productive at running, debugging, and deploying code and infrastructure.

Warp is a blazingly fast, Rust-based terminal that makes you and your team more productive at running, debugging, and deploying code and infrastructure.

Simple test app based on rust-psp

PSP Test App Simple test app based on rust-psp. Demonstrating the usage of C libs. Build Download and unzip the prebuilt PSPSDK (built from clang-psp)

A cli based pastebin in Rust, but very insecure

pasta A cli based pastebin in Rust, but very insecure Use nightly toolchain to build rustup override set nightly When this program is running, you can

Terminal based GUI for eAsistent written in Rust

Terminal based GUI for eAsistent written in Rust This project is currently work in progress. I will update this readme with features that I'm currentl

A Rust-based Garry's Mod module for fetching environment variables.

gm_environ Using Environment Variables in Garry's Mod. Installation Download a copy of the module from the releases (or compile from source) Move the

A CLI-based pride flag generator written in Rust
A CLI-based pride flag generator written in Rust

🌈 prideful (in development) A CLI-based pride flag generator written in Rust. How to run Build the project using cargo. Install cargo by following th

A native screenshot tool for wlroots based compositors such as sway and river written in Rust
A native screenshot tool for wlroots based compositors such as sway and river written in Rust

A native screenshot tool for wlroots based compositors such as sway and river written in Rust. X11 support coming soon.

A simple lexer which creates over 75 various tokens based on the rust programming language.

Documentation. This complete Lexer/Lexical Scanner produces tokens for a string or a file path entry. The output is a Vector for the user to handle ac

An easy-to-use TUI crate for Rust, based off of the Elm architecture.

Rustea An easy-to-use TUI crate for Rust, based off of the Elm architecture. This is a re-implementation of Go's Tea, created by TJ Holowaychuk. Featu

Owner
Siddharth
design engineer @headout ✱ building creative tools for sound and visuals.
Siddharth
Nazuna - 🐦 Download Twitter videos using your terminal!

Nazuna ?? Download Twitter videos using your terminal! Installation Binary Download the desired file for your OS (Windows, Mac, Linux) from https://gi

Felipe Garcia 27 Nov 22, 2022
Play videos on IT8951-controlled e-paper displays

it8951-video Play videos on IT8951-controlled e-paper displays via USB. This has been tested with a Waveshare 7.8inch e-Paper HAT display. Design This

Andreas Dzialocha 4 Nov 28, 2022
Enhance low quality images and videos using AI technology.

Real ESRGAN GUI Real ESRGAN GUI is a simple and minimal GUI for xinntao's Real-ESRGAN This allows you to enhance low quality images and videos using A

null 20 Dec 21, 2022
A terminal ASCII media player. View images, gifs, videos, webcam, YouTube, etc.. directly in the terminal as ASCII art.

Terminal Media Player View images, videos (files or YouTube links), webcam, etc directly in the terminal as ASCII. All images you see below are just m

Max Curzi 36 May 8, 2023
Just a simple object renderer, written in under 500 lines using Rust.

All cargoes that the project runs are: bitflags: a crate for defining bitflag types cfg-if: a small macro crate for defining cfg-based - conditional c

null 3 May 4, 2023
A tiny software renderer written in Rust.

tiny-renderer 简单的软光栅化渲染器 基础数学库 Bresenham画线算法 Cohen-Sutherland线段裁剪算法 glTF模型加载 模型/视图/投影变换 背面剔除 视椎剔除 齐次空间裁剪 深度测试 Blinn–Phong着色模型 重心坐标插值 运行 bresenham画线算法

Night's Watch Games 9 May 29, 2023
Gauzilla: a 3D Gaussian Splatting renderer written in Rust for WebAssembly with lock-free multithreading

Gauzilla A 3D Gaussian Splatting (3DGS) renderer written in Rust for platform-agnostic WebAssembly (WASM) with lock-free multithreading. Uses WebGL an

Yoshi Sato 90 Jan 2, 2024
Fast Symbol Ranking based compressor. Based on the idea of Matt Mahoney's SR2

Fast Symbol Ranking based compressor. Based on the idea of Matt Mahoney's SR2

Mai Thanh Minh 3 Apr 29, 2023
A Rust-based shell script to create a folder structure to use for a single class every semester. Mostly an excuse to use Rust.

A Rust Course Folder Shell Script PROJECT IN PROGRESS (Spring 2022) When completed, script will create a folder structure of the following schema: [ro

Sebastián Romero Cruz 1 Apr 10, 2022
Another TUI based system monitor, this time in Rust!

Another TUI based system monitor, this time in Rust!

Caleb Bassi 2.1k Jan 3, 2023