Animation and video in Rust
oxframe is a Rust library for motion graphics: explainers, code walkthroughs, charts and release
videos. A scene is an async fn, every value is a signal, and the same code renders
to MP4 natively, headless in CI, or live in the browser through WebAssembly.
A scene is an async function
use oxframe::prelude::*;
#[oxframe::scene]
async fn intro(view: View) {
let square = view.add(Rect::new().size(200.0).x(-300.0).fill(color!("#e13238")));
all((
square.x().to(300.0, 1.0),
square.radius().to(100.0, 1.0),
square.fill().to(color!("#68abdf"), 1.0),
))
.await;
}
fn main() {
Project::new("intro").scene(intro()).main();
} Each .await is a beat of the video; all((…)) runs animations together.
The project's binary is also its tool: cargo run -- render writes the MP4 and cargo run -- check reviews the frames; the oxframe CLI adds the editor,
presentations and agent setup on top.
What it is built on
- A deterministic executor. Scenes run on a single-threaded coroutine executor
in
oxframe-core; a frame is a point where every scene task has awaited. Seeking replays from the start, so frame 900 is the same whether you play, scrub or render. - Two renderers. vello on the GPU and tiny-skia on the CPU, from the same scene
graph;
--cpurenders on a machine without a GPU. 3D is a software rasterizer with byte-identical output. - Text. parley and skrifa lay out and outline text, with Inter and JetBrains
Mono embedded and any font through
register_font. - Export. Frames are piped to ffmpeg for MP4, WebM with alpha and ProRes 4444,
with audio mixed in;
--jobsrenders segments in parallel with the same bytes as one job. - WebAssembly. The
wasmfeature runs a project in the browser; that is how the playground works.
Crates and features
cargo add oxframe brings the whole SDK (0.20.2); the parts are separate
crates, and the core has no graphics in it.
| Crate | What it does |
|---|---|
oxframe-core | signals, tweens, the coroutine executor |
oxframe-2d | the scene graph and its nodes |
oxframe-components | titles, lists, diagrams, code explainers |
oxframe-render | tiny-skia on the CPU, vello on the GPU |
oxframe-3d | meshes, lights and a software rasterizer |
oxframe-export | ffmpeg video, PNG sequences, audio |
Features: gpu (default), 3d, icons, video, wasm and unstable-node-api for nodes of your own. The API reference is
on docs.rs.
Start
cargo install oxframe-cli
oxframe init my-video
cd my-video && oxframe dev Getting started walks through it, the guide teaches the API in fifteen lessons, and the gallery has the source of every example.