Rendering video
When the animation looks right in the editor, one command turns it into a video file.
oxframe render That's it: the project is built in release mode and every frame goes to out/<project>.mp4. You need ffmpeg installed for video formats; PNG frames
work without it.
For a web page you may not need a file at all: embed the animation with <oxframe-player> and it plays live, sharp at any size.
Common recipes
oxframe render --out film.webm # VP9 with transparency
oxframe render --format prores --out a.mov # ProRes 4444 with transparency, for video editors
oxframe render --out demo.gif # a GIF for a README or a pull request
oxframe render --format png --out frames/ # one PNG per frame
oxframe render --size 3840x2160 # 4K
oxframe render --scene outro # just one scene
oxframe render --range 1..3 # seconds 1 to 3
oxframe render --gpu # draw on the GPU (vello); the CPU is the default
oxframe render --jobs 4 # four segments at once Need just one still? oxframe snapshot --at 2.5 writes a PNG of that moment — no ffmpeg,
no full render.
Transitions
A scene can open by blending in over the one before it. The call waits out the blend, so nodes added before it are on screen while it runs and nodes added after appear when it finishes. The length comes from the theme unless you set one, and the editor can drag it afterwards.
#[oxframe::scene]
async fn outro(view: View) {
transition(Transition::slide(Dir::Left)).await;
let end = view.add(EndCard::new("Thanks for watching"));
end.enter().await;
} Loading live preview…
Source of transitions — edit in the playground
//! Slide from a title into an end card.
use oxframe::prelude::*;
#[oxframe::scene]
pub async fn intro(view: View) {
let title = view.add(TitleCard::new("Scene one"));
title.enter().await;
wait_for(0.4).await;
}
#[oxframe::scene]
pub async fn outro(view: View) {
transition(Transition::slide(Dir::Left)).await;
let end = view.add(EndCard::new("Thanks for watching"));
end.enter().await;
}
pub fn project() -> Project {
Project::new("transitions").scene(intro()).scene(outro())
}fade, slide(Dir::Left) (Right, Up, Down), wipe(dir), zoom_in and zoom_out are
built in. .ease(...) changes the curve, .overlap() lets the previous
scene keep playing instead of holding its last frame, and Transition::custom(|t| ...) places the two layers itself with opacity, offset, scale and a wipe. Transition::shader(shaders::water_wipe()) raises a wavy waterline over the frame;
below it is the next scene, rippled near the line, and .wave() sets the wave height
(see shaders that read pixels). The first scene has
nothing to blend from, so the call does nothing there.
oxframe render includes every transition. oxframe render --scene outro draws that scene on its own, without the blend into it. oxframe check puts a frame
from each blend on the storyboard, and oxframe inspect reports the type and progress. The
same blend keeps its alpha on a transparent background, in 16:9, 9:16 and 1:1.
Shaders
shaders::waves() is a node: a crest of foam over deeper water, painted inside its
box. .amp() is the height of that crest and a signal, so it can move. .deep() and .foam() take a color or a theme role such as Accent. The node has no children. A title goes on the view, above the water.
let sea = view.add(shaders::waves().amp(0.05).deep(Accent).foam(Surface)
.width(pct(100)).height(pct(40)).to_edge(Edge::Bottom));
sea.amp().to(0.12, 1.2).await; Loading live preview…
Source of waves — edit in the playground
//! A wave that grows. The crest is a shader preset, so it renders without a GPU.
use oxframe::prelude::*;
#[oxframe::scene]
pub async fn sea(view: View) {
let water = view.add(
shaders::waves()
.amp(0.05)
.deep(Accent)
.foam(Surface)
.width(pct(100))
.height(pct(40))
.to_edge(Edge::Bottom),
);
view.add(Txt::new().text("Waves").display().to_edge(Edge::Top));
water.amp().to(0.12, 1.2).await;
}
pub fn project() -> Project {
Project::new("waves").size(960, 540).fps(30).scene(sea())
}The preset is rasterized first and then drawn by the CPU or the GPU, so a check with no GPU still shows it. Draft checks paint the layer at half resolution. That does not move the box or change the timing.
Your own shader is WGSL. It defines struct Params, the uniform p, and fn shade. oxframe adds ox (time, frame, resolution, the box size, seed,
the camera matrix, and progress) and ShadeIn (uv, local, world, and screen). Shader::source keeps the text in the scene. Shader::file reads a .wgsl file on every draw, so saving it updates the
picture without a rebuild. .uniform() sets a number. A name or a type that is not in Params fails the check, and the message lists the fields. WGSL that does not compile
fails it too, with the line in your source. Your shade runs on the CPU, a tile of
pixels at a time, with the same bytes on every OS (about 0.13 s for a 1080p frame), in oxframe dev, check, render and the playground, where a 1080p
frame takes about 0.3 s and playback skips frames to keep time. It cannot use textures, samplers or
derivatives; it reads its inputs with functions instead (below).
Your own WGSL: reading the frame, an image or a node
An input is a function in your WGSL. .input("scene", Input::frame()) gives sample_scene(uv), the pixels drawn before the shader; the shader is then painted over
them inside its box. This magnifying glass bends the frame inside a moving circle, and its center,
radius and zoom are uniforms, so .to() animates them:
lens.wgsl:
struct Params { cx: f32, cy: f32, radius: f32, zoom: f32 }
@group(1) @binding(0) var<uniform> p: Params;
fn shade(i: ShadeIn) -> vec4<f32> {
let res = ox.resolution;
let center = vec2<f32>(p.cx, p.cy) * res;
let d = i.screen - center;
let r = length(d) / p.radius;
if (r > 1.0) {
return sample_scene(i.screen / res);
}
let at = center + d * mix(1.0 / p.zoom, 1.0, r * r);
let rim = smoothstep(0.9, 1.0, r);
return vec4<f32>(mix(sample_scene(at / res).rgb, vec3<f32>(1.0), rim * 0.7), 1.0);
} The scene:
#[oxframe::scene]
async fn magnifier(view: View) {
view.add(Txt::new().text("Read the fine print").h1().y(-330.0));
// ... the text to read ...
let lens = view.add(
Shader::file("lens.wgsl")
.uniform("cx", 0.27).uniform("cy", 0.53)
.uniform("radius", 0.0).uniform("zoom", 2.2)
.input("scene", Input::frame())
.fullscreen(), // added last: it reads everything above
);
lens.uniform("radius").to(170.0, 0.5).await;
lens.uniform("cx").to(0.73, 3.0).await;
} Loading live preview…
Source of magnifier — edit in the playground
//! A magnifying glass written in WGSL: the shader reads the frame drawn
//! before it (`Input::frame()`) and bends it inside a moving circle.
//!
//! A custom WGSL shader runs on the CPU, in `oxframe dev`, `check`,
//! `render` and the playground alike.
use oxframe::prelude::*;
/// `cx`, `cy`: the lens center (0..1 across the frame); `radius` in pixels;
/// `zoom`: how much the middle is magnified.
const LENS: &str = r#"
struct Params { cx: f32, cy: f32, radius: f32, zoom: f32 }
@group(1) @binding(0) var<uniform> p: Params;
fn shade(i: ShadeIn) -> vec4<f32> {
let res = ox.resolution;
let center = vec2<f32>(p.cx, p.cy) * res;
let d = i.screen - center;
let r = length(d) / p.radius;
if (r > 1.0) {
return sample_scene(i.screen / res);
}
// A lens bends the middle most and the rim not at all.
let at = center + d * mix(1.0 / p.zoom, 1.0, r * r);
// Glass splits colors a little toward the rim.
let fringe = d * 0.015 * r;
let color = vec3<f32>(
sample_scene((at + fringe) / res).r,
sample_scene(at / res).g,
sample_scene((at - fringe) / res).b,
);
let rim = smoothstep(0.9, 1.0, r);
return vec4<f32>(mix(color, vec3<f32>(1.0), rim * 0.7), 1.0);
}
"#;
#[oxframe::scene]
pub async fn magnifier(view: View) {
let title = view.add(Txt::new().text("Read the fine print").h1().y(-330.0));
let print = view.add(
Txt::new()
.text(
"oxframe draws every frame on the CPU, so a render is the same \
bytes on every machine. Your own WGSL runs there too, a tile \
of pixels at a time, and can read what was drawn before it.",
)
.font_size(32)
.max_width(1200.0)
.fill(Muted)
.y(40.0),
);
// Added last, so it reads the title and the text.
let lens = view.add(
Shader::source(LENS)
.uniform("cx", 0.27)
.uniform("cy", 0.53)
.uniform("radius", 0.0)
.uniform("zoom", 2.2)
.input("scene", Input::frame())
.fullscreen(),
);
all((title.fade_in(), print.fade_in())).await;
lens.uniform("radius").to(170.0, 0.5).await;
lens.uniform("cx").to(0.73, 3.0).await;
all((
lens.uniform("cy").to(0.2, 1.0),
lens.uniform("cx").to(0.5, 1.0),
))
.await;
lens.uniform("zoom").to(1.4, 0.8).await;
lens.uniform("radius").to(0.0, 0.4).await;
}
pub fn project() -> Project {
Project::new("magnifier").scene(magnifier())
}The whole scene, with a color fringe at the rim, is the magnifier example in the gallery. A frame shader inside the box
sees screen pixels: sample_scene(i.screen / ox.resolution) reads the pixel under the one
being shaded.
The other inputs work the same way, each read with sample_<name>(uv), where uv runs from 0 to 1 across the input:
.input("photo", Input::file("photo.png"))reads a PNG or JPEG from the project and givessample_photo(uv).Input::image(include_bytes!(..))builds the file into the binary instead.Input::node(handle)reads another node, children included, across its box. Add that node with.offscreen()and it is drawn only for the shader: never on screen, andoxframe checkskips it. That is how a shader distorts a logo or a title.
Calling sample_x with no input named x fails the check, and the message
says how to add it. Shader::size(width, height) sets the box in one call, like Rect.
Shaders that read pixels
Three presets work on what is already drawn: drops on the lens, rings on a node, and water that rises into the next scene.
#[oxframe::scene]
async fn sea(view: View) {
let water = view.add(shaders::waves().deep(Accent).foam(Surface)
.width(pct(100)).height(pct(45)).to_edge(Edge::Bottom));
let lens = view.add(shaders::lens_drops().wetness(0.0).seed(7).fullscreen()); // last
let rings = water.effect(shaders::ripple().strength(0.0));
rings.strength().to(1.0, 0.4).await;
lens.wetness().to(1.0, 0.4).await;
}
#[oxframe::scene]
async fn shore(view: View) {
view.add(shaders::waves().amp(0.02).width(pct(100)).height(pct(20)).to_edge(Edge::Bottom));
transition(Transition::shader(shaders::water_wipe())).await;
view.add(EndCard::new("").made_by()).enter().await;
} Loading live preview…
Source of splash — edit in the playground
//! A drop rings the water, a splash wets the lens, and the water rises into
//! the next scene. All three shaders run on the CPU, so the example renders
//! without a GPU.
use oxframe::prelude::*;
#[oxframe::scene]
pub async fn sea(view: View) {
let water = view.add(
shaders::waves()
.deep(Accent)
.foam(Surface)
.width(pct(100))
.height(pct(45))
.to_edge(Edge::Bottom),
);
let title = view.add(
Txt::new()
.text("Into the wave")
.display()
.to_edge(Edge::Top),
);
let lens = view.add(shaders::lens_drops().wetness(0.0).seed(7).fullscreen());
title.fade_in().await;
let rings = water.effect(shaders::ripple().strength(0.0));
rings.strength().to(1.0, 0.4).await;
all((water.amp().to(0.14, 1.0), rings.strength().to(0.0, 1.0))).await;
lens.wetness().to(1.0, 0.4).await;
wait_for(0.6).await;
}
#[oxframe::scene]
pub async fn shore(view: View) {
// Added before the transition, so the rising water uncovers it.
view.add(
shaders::waves()
.amp(0.02)
.speed(0.3)
.deep(Accent)
.foam(Surface)
.width(pct(100))
.height(pct(20))
.to_edge(Edge::Bottom),
);
transition(Transition::shader(shaders::water_wipe()).duration(1.0)).await;
let end = view.add(EndCard::new("").made_by());
end.enter().await;
}
pub fn project() -> Project {
Project::new("splash")
.size(960, 540)
.fps(30)
.scene(sea())
.scene(shore())
}shaders::lens_drops() bends everything drawn before it, inside its box, so add it
last and make it .fullscreen(). .wetness() runs from 0 (dry) to 1 and is
a signal: lens.wetness().to(1.0, 0.4) is a splash. .seed() places the
drops and .drop_size() scales them. .input("scene", Input::frame()) names what the shader reads, and outside a layer Input::backdrop() is the same thing.
Node::effect runs a shader on one node's pixels, children included, and returns an Effect. shaders::ripple() sends rings out from the node's center; .strength() and .speed() are signals. The colors move and each ring is lit
on one side, so the rings show on water and flat fills as well as on text or an image; the outline stays.
A node has one effect.
lens_drops, node.effect(..) or a frame-reading shader of your own also
works inside a group with opacity below 1, a blur, a clip, a blend, a shadow or another effect.
The group is drawn on its own first, so a shader in it reads what the group drew before it; then
the group fades, blurs or clips as a whole. oxframe inspect --graph lists these
shaders as effect passes, and a Shader handle works wherever a Node does, for example in Camera::center_on.
Sound
A soundtrack plays for the whole video. Project::audio("music.mp3") still works, and
it is the same as Audio::track:
Project::new("explainer")
.audio(Audio::track("assets/music.mp3").duck_under_voice().volume(0.8))
.scene(intro()) .duck_under_voice() lowers the music while a sound marked .priority() is
playing. .volume(), .fade_in() and .fade_out() shape the
track. .master_fade() fades the whole mix, including the effects.
sound("click.wav") starts at the current frame. .play() does not wait.
Awaiting the sound waits until it ends, and .trim() plays a slice of the file (that slice
is also how long the wait is):
sound("assets/whoosh.wav").volume(0.6).fade_in(0.05).play();
sound("assets/click.wav").trim(0.0, 0.2).priority().await; Loading live preview…
Source of sounds — edit in the playground
//! A beat that plays with the picture, and a tone that ducks under it.
use oxframe::prelude::*;
fn asset(name: &str) -> String {
format!("{}/assets/{name}", env!("CARGO_MANIFEST_DIR"))
}
#[oxframe::scene]
pub async fn sounds(view: View) {
let dot = view.add(Circle::new().size(16.0).fill(color!("#e13238")));
sound(asset("click.wav")).volume(0.8).trim(0.0, 0.18).play();
dot.size().to(140.0, 0.18).await;
dot.size().to(28.0, 0.35).await;
sound(asset("click.wav"))
.volume(0.5)
.fade_out(0.04)
.trim(0.0, 0.18)
.priority()
.play();
dot.size().to(140.0, 0.18).await;
wait_for(0.4).await;
}
pub fn project() -> Project {
Project::new("sounds")
.size(960, 540)
.fps(60)
.audio(
Audio::track(asset("tone.wav"))
.duck_under_voice()
.volume(0.4)
.master_fade(0.05, 0.15),
)
.scene(sounds())
}Effects show up as clips on the timeline and play with the picture, including after a seek. The
mix is written before ffmpeg encodes it, so two renders of the same scene match. --no-audio leaves the soundtrack and the effects out. --range keeps only
the part of them that falls inside that span. Drag the waveform to shift the soundtrack; the
offset is saved in meta.json.
Loudness
A video that is much quieter or louder than the one before it gets turned down or skipped. Project::loudness brings the whole mix (music, voice and effects together) to one integrated
loudness, measured the way YouTube and podcast apps measure it (EBU R128), and keeps peaks under -1
dBFS:
Project::new("explainer")
.audio("assets/music.mp3")
.loudness(-14.0) // YouTube and most players; -16.0 for podcasts
.scene(intro()) The render prints what it got, e.g. sound: -14.0 LUFS (target -14.0); without loudness it prints the level the files give. The gain is one number for the whole
video, so quiet and loud parts keep their difference. To measure a mix of your own, call oxframe_export::loudness; to mix an oxframe_export::MixRequest to a
target yourself, oxframe_export::mix_with_loudness.
Voice
voice("one two").start() speaks the line and keeps going. .at_word() waits until that word. Awaiting the line waits until the end. A line is .priority(),
so it ducks a soundtrack built with .duck_under_voice().
let line = voice("First draw a square, then rotate it").start();
line.at_word("square").await;
square.draw_on().await;
line.at_word("rotate").await;
square.rotation().to(90.0, 0.8).await;
line.await; oxframe does not call a speech service itself. To get real audio, implement TtsProvider and pass it to Project::tts. synthesize receives the line and the voice name and returns mono i16 samples plus one TimedWord per word. .at_word() waits on those times, not on a guess. The
key stays inside the provider, read from the environment. speak below is your function:
the HTTP call and the decode.
use oxframe::{Synthesis, TimedWord, TtsProvider, TtsRequest};
struct ElevenLabs;
impl TtsProvider for ElevenLabs {
fn id(&self) -> &str {
"elevenlabs"
}
fn synthesize(&self, req: &TtsRequest) -> Result<Synthesis, String> {
let key = std::env::var("ELEVENLABS_API_KEY")
.map_err(|_| "set ELEVENLABS_API_KEY".to_string())?;
// Send req.text and req.voice to ElevenLabs with key.
// Decode the body into mono i16 samples and one TimedWord per word.
let (rate, samples, words) = speak(&key, req.voice, req.text)?;
Ok(Synthesis { rate, samples, words })
}
}
Project::new("explainer")
.tts(ElevenLabs)
.speaker("Rachel")
.audio(Audio::track("assets/music.mp3").duck_under_voice())
.scene(intro()) The first render calls synthesize and saves tts/{hash}.wav and tts/{hash}.json. The next render plays that file. Commit the folder to
render in CI without a key. A missing key or a failed call does not fail the scene: oxframe
estimates the length (2.5 words per second, at least 0.3s) and there is no speech audio. An
estimate is not cached. With no provider, a committed cache is still used when the text and voice
match. The playground always estimates.
Loading live preview…
Source of voice — edit in the playground
//! A spoken line. The circle grows when the second word starts.
use oxframe::prelude::*;
#[oxframe::scene]
pub async fn spoken(view: View) {
let dot = view.add(Circle::new().size(24.0).fill(color!("#e13238")));
let line = voice("one two three").start();
line.at_word("two").await;
dot.size().to(160.0, 0.3).await;
line.await;
}
pub fn project() -> Project {
Project::new("voice").size(960, 540).fps(60).scene(spoken())
}oxframe render --subtitles out.srt writes the lines. A path ending in .vtt writes WebVTT. --no-audio still writes them, and --range shifts the cues into
that part of the video. A line that runs past the scene is an error; two lines that overlap are a warning.
GIF for a README or a pull request
GitHub, GitLab and most chats play a GIF in place where an MP4 needs a click, so a GIF is the way to show a feature in a README, a pull request or an issue.
oxframe render --out demo.gif # 720 wide, 15 fps
oxframe render --format gif --scene intro # one scene, out/<project>.gif
oxframe render --out demo.gif --fps 10 --size 480x270 # smaller file A GIF is 720 pixels wide and 15 frames per second unless --size and --fps say otherwise. Only the frames the GIF shows are rendered, from the project's
own frame rate, so the timing is the same as in the MP4. The whole clip shares one palette of 256
colors with an ordered dither, which keeps flat colors flat and does not shimmer from frame to
frame; each frame stores only the rectangle that changed. A GIF has no sound, and --fps works only with it. A tool of your own writes one with Format::Gif in oxframe_export.
Flat backgrounds, text and charts compress well: the 7-second chart example is 137 KB. Photos, gradients and video clips do not, and a GIF of them is large and banded; keep those as MP4 (on GitHub, drop the MP4 into the description and it plays there too). Under 10 seconds and at most 720 wide is a good size for a README.
Transparent backgrounds
Make the background transparent with .background(Color::TRANSPARENT) on the project
and render to webm, prores or png: those keep the alpha
channel, so you can lay the animation over footage in a video editor. MP4 (H.264) has no
transparency.
Parallel rendering
A video longer than two seconds renders in 2-second segments, several at once: each one runs in
its own process, is encoded on its own, and the segments are joined without encoding them again.
The soundtrack is added once at the end. --jobs 4 sets how many run at a time; the default
is one per core, at most eight.
The segments are the same whatever --jobs is, so --jobs 1 and --jobs 8 write the same bytes: a render on your laptop and one in CI match. Scenes
that take long to draw gain the most — a 7-second 3D scene on 8 cores renders 2.7 times faster —
while a short or simple one gains little, because every segment first runs the scene up to where
it starts. Each process holds one frame at a time, so memory does not grow with the length of the
video. A PNG sequence is split the same way. A tool of your own that encodes segments can join
them the same way with oxframe_export::concat.
GPU or CPU?
Frames are drawn on the CPU (tiny-skia) by default. It is faster than the GPU on every scene we
benchmark, and it needs no graphics driver, so CI and servers just work. Pass --gpu to oxframe render, oxframe dev or oxframe present to draw with vello; it falls back to the CPU when no GPU is
available. Before 0.21 the GPU was the default and --cpu opted out; --cpu still works and wins over --gpu. Vector scenes match across the two: they pass the
same reference-frame tests within a color difference of ΔE 1, which you cannot see. The CPU
renderer is also byte-for-byte identical between runs, which is what you want in automated tests.
A shaders::waves() node is painted into an image before either backend, so the two
show the same crest. The same goes for lens_drops, ripple and water_wipe: both renderers draw the
vectors, and the shader runs on those pixels on the CPU. A layer whose vectors did not change is
reused on the next frame. A scene with no effects is one vector pass; oxframe inspect --graph lists the passes.
In a container or CI
ghcr.io/oxygenframe/oxframe has the oxframe command, Rust and ffmpeg, with the SDK
already compiled, so a project's first oxframe check or oxframe render inside it takes seconds instead of compiling the engine. Use the tag of your project's SDK version:
docker run --rm -v "$PWD:/work" ghcr.io/oxygenframe/oxframe:0.24.3 oxframe render In GitHub Actions, run the job in it:
jobs:
video:
runs-on: ubuntu-latest
container: ghcr.io/oxygenframe/oxframe:0.24.3
steps:
- uses: actions/checkout@v4
- run: oxframe check
- run: oxframe render In the browser
The playground can export MP4 too (the Export mp4 button). It encodes with your browser's WebCodecs, so it works offline but is limited to what the browser supports, and the file has no sound — use the CLI for sound, ProRes, 4K or long videos. Share video renders the same way and uploads the result for a public link (up to 30 seconds, kept 30 days; see Privacy).