---
name: nabumotion
description: Render animations to MP4 or GIF through the NabuMotion API by sending scene code for one of 17 open-source engines (Remotion, Motion Canvas, Manim, Motion, anime.js, Lottie, TweenJS, Shifty, Ola, two.js, Konva, Proton, three.js, Babylon.js, Lume, Blender, Godot; gifenc for GIF). Use when a brief asks for a short video, reel, explainer, motion graphic, 3D shot or GIF, including Persian/RTL text.
---

# NabuMotion

NabuMotion turns scene code into a video file. You pick an engine, write the
scene in that engine's own language, POST it, poll, and download the MP4/GIF.
Every engine below has a tested example in `examples/<engine>/` next to this
file (the same sources the service's test suite renders and checks), in two
editions: the Persian scene (`scene.js`, `Scene.tsx`, `scene.py`, `scene.gd`)
and an English one next to it (`scene.en.js`, `Scene.en.tsx`, ...), with the
same layout and motion and left-to-right copy. Both are tested in all four
frame shapes.

## 1. Pick the engine

| Brief | Engine | Source |
|---|---|---|
| Branded reel, ad, social post with Persian/RTL copy, text-heavy layouts | `remotion` | TSX (React) |
| Explainer with precise step-by-step sequencing (diagrams, code, graphs) | `motion-canvas` | TSX (generators) |
| Math / technical explainer: geometry, plots, morphing shapes | `manim` | Python |
| UI / product motion: cards, buttons, charts on HTML, springs | `motion` or `animejs` | JS |
| Play an existing After Effects / Bodymovin JSON | `lottie` | JS |
| Simple tweens on canvas-drawn objects | `tweenjs`, `shifty` | JS |
| Smooth counters and followers (values that glide to targets) | `ola` | JS |
| Flat vector / generative geometry | `twojs` | JS |
| 2D canvas scene graph (shapes, text, tweens) | `konva` | JS |
| Particles: confetti, sparks, fireworks | `proton` (or `godot`) | JS |
| Real-time 3D (WebGL): product spin, abstract 3D | `threejs` or `babylonjs` | JS |
| 3D mixed with HTML content via custom elements | `lume` | JS |
| Photoreal / extruded 3D type, physically lit | `blender` | Python (bpy) |
| Game-like motion: sprites, physics, particles, tilemaps | `godot` | GDScript |
| Any of the above as a GIF | same engine, `"format": "gif"` (gifenc) | |

Persian text: every engine has the Vazirmatn font installed locally: the variable
file (any weight 100–900) in the browser engines, Remotion and Motion Canvas, and
Regular/Bold (400/700) in Manim, Blender and Godot. Browser engines, Remotion, Motion Canvas, Manim (Pango) and Godot
shape RTL text natively. Blender cannot: the runner shapes text objects for
you (or call `nabu.fa(text)` for text you change per frame). For Lottie, put
Persian copy in HTML next to the animation, not in Lottie text layers.

## 2. Call the API

Base URL and key come from the environment (`NABUMOTION_URL`,
`NABUMOTION_API_KEY`). All `/v1` routes need `Authorization: Bearer <key>`.

```bash
# 1. submit (source is the scene file as a JSON string)
curl -s -X POST "$NABUMOTION_URL/v1/renders" \
  -H "Authorization: Bearer $NABUMOTION_API_KEY" -H 'content-type: application/json' \
  -d "$(jq -n --rawfile src scene.py '{engine:"manim", source:$src, width:720, height:1280, fps:30, duration_seconds:4, format:"mp4"}')"
# -> {"id":"r_...","status":"queued","status_url":"...","file_url":"..."}

# 2. poll until status is "done" or "failed"
curl -s -H "Authorization: Bearer $NABUMOTION_API_KEY" "$NABUMOTION_URL/v1/renders/$ID"
# -> {"status":"rendering","progress":0.42,...} ... {"status":"done","url":".../file"}
# -> on failure: {"status":"failed","error":"scene error: ...","log":[...]}  (fix the scene and resubmit)

# 3. download
curl -s -H "Authorization: Bearer $NABUMOTION_API_KEY" -o out.mp4 "$NABUMOTION_URL/v1/renders/$ID/file"
```

Request fields:

- `engine` (required): an id from the table.
- `source` (required): the scene code.
- `width`, `height`: layout size the scene is written for (default 1080x1920; even numbers for mp4). 9:16 = 720x1280 or 1080x1920; 1:1 = 1080x1080; 16:9 = 1920x1080.
- `scale` (default 1): output pixels = width*scale x height*scale. Write the scene once at 720x1280 and render it at `scale: 1.5` for 1080x1920.
- `fps` (default 30), `duration_seconds` (default 4). The output always has exactly round(duration*fps) frames.
- `format`: `"mp4"` (H.264, yuv420p, faststart) or `"gif"`.
- `assets` (optional): `{"logo.png": "<base64>" | "https://..."}`. Browser engines: `nabu.asset("logo.png")`; Remotion: `staticFile("assets/logo.png")`; Motion Canvas: `nabu.asset(...)`; Manim/Blender: path via `nabu.asset(...)` (Blender) or `os.path` in the job's assets dir; Godot: `Nabu.texture("logo.png")`.

`GET /v1/engines` returns every engine's contract and its tested example.

## 3. Lay the scene out for any shape

The same scene is often rendered as 9:16 (720x1280), 4:5 (720x900), 1:1 (720x720)
and 16:9 (1280x720), usually at `scale: 1.5`. Never hard-code pixel positions
tuned to one frame:

- Read the size from the engine (`nabu.width`/`nabu.height`, Remotion
  `useVideoConfig()`, Motion Canvas `useScene().getSize()`, Manim
  `config.frame_width`/`frame_height` (height is always 8 units), Blender
  `nabu.width`/`nabu.height` + the camera's visible area, Godot `Nabu.width`/`Nabu.height`).
- Use a min-side unit `u = min(width, height)`: font sizes and object sizes are
  fractions of `u` (headline about 0.07–0.1u, body 0.04–0.05u, nothing under
  0.035u; Persian line-height 1.35–1.45).
- Keep a safe margin of 6 % of each side; place things by fractions of the
  width/height or from the centre.
- Stack art above text when the frame is portrait or square; put them side by side
  (art left, text right) when `width > height`.
- Fit one-line text to its box (`nabu.fitText`) or let it wrap; never let it run
  off the frame.

Helpers: browser engines and Motion Canvas get `nabu.u`, `nabu.landscape`,
`nabu.safe` (6 % margins), `nabu.layout(ratio)` → `{art, text}` boxes and
`nabu.fitText(text, {size, maxWidth, weight})`; Godot gets `Nabu.u`,
`Nabu.landscape`, `Nabu.safe` and `Nabu.layout(ratio)` (Rect2s).

Every example in `examples/` follows these rules and is tested in all four shapes
(`npm test -- --aspects 9:16,4:5,1:1,16:9`). All of them switch to a side-by-side
landscape layout at 16:9 except `proton` (fountain centred, caption below in every
shape) and `manim`, which keeps its title across the top and puts the shape left of
the chart. Good starting points for a landscape layout: `remotion`, `motion` (card
with a text column and a chart), `threejs`/`babylonjs`/`blender` (layout from the
camera's visible area), `motion-canvas` (centre-origin coordinates), `godot`.

## 4. Write the scene (per engine contract)

- **remotion**: default-export a React component. Use `useCurrentFrame`, `useVideoConfig`, `interpolate`, `spring`, `AbsoluteFill`, `Sequence`. Size, fps and duration come from the request. `fontFamily: 'Vazirmatn'`, `direction: 'rtl'` for Persian.
- **motion-canvas**: `export default makeScene2D(function* (view) {...})`. Origin is the centre. `yield*` tweens (`node().x(100, 0.5)`), `all`, `sequence`, `waitFor`. `<Txt fontFamily="Vazirmatn">`. A scene shorter than the duration holds its last frame.
- **manim**: `from manim import *`, `class Main(Scene)`. The 9:16 frame is 4.5 x 8 units (frame height is always 8). `Text("...", font="Vazirmatn")`: the runner routes Persian `Text` through `MarkupText`, because plain `Text` drops Persian glyphs at some sizes (keep `t2c`/`t2f` off Persian strings, they force the old path). No LaTeX: avoid `Tex`/`MathTex`.
- **browser engines** (motion, animejs, lottie, tweenjs, shifty, ola, twojs, konva, proton, threejs, babylonjs, lume): an ES module run in a page with the library as a global (`Motion`, `anime`, `lottie`, `createjs`, `shifty`, `Ola`, `Two`, `Konva`, `Proton`, `THREE`, `BABYLON`, `LUME`) or imported by npm name. Draw into `nabu.stage` (width x height). Time is virtual: rAF, timers, `performance.now`, `Date`, CSS/Web Animations all advance exactly 1/fps per frame, so animate normally. `nabu.time` (seconds), `nabu.onFrame((t, i) => ...)` to seek manually, `nabu.delay()`/`nabu.done(h)` to hold capture while loading, `nabu.scale` for canvas backing stores (`canvas.width = nabu.width * nabu.scale`). No internet at render time: send files as `assets`.
- **blender**: a bpy script on an empty scene; add a camera and set `scene.camera`; keyframe over frames 1..`nabu.frames`; `nabu.font(bold=True)` for Vazirmatn. Cycles at 32 samples by default (set `scene.cycles.samples` lower for speed). Renders are slow on CPU (seconds per frame): keep scenes small.
- **godot**: GDScript that `extends Node2D` (or `Node3D`/`Control`); animate in `_process(delta)` or with tweens; `Nabu.width/height/time/font_bold`, `Nabu.u`, `Nabu.layout(ratio)`; Labels already use Vazirmatn. 2D is laid out at width x height and rendered at width*scale x height*scale.

## 5. Check the result

The status tells you `output_width`, `output_height` and `frames`. If a render
fails, the `error` and `log` fields carry the engine's own message (JS stack,
Python traceback, GDScript error); fix the source and resubmit.
