Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
195 changes: 195 additions & 0 deletions docs/notes/render-video.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,10 @@ FlightFit a move flown by hand -> keys
FrameRenderer one frame: every model drawn by its own renderer, composited
FrameSink where frames go: image files, a GIF, or an encoder process
GifWriter animated GIF: a palette per frame, ordered dither, LZW
ShotFrames a moment of the project -> what FrameRenderer draws
RenderOutput frame count, size, encoder choice and the sink of an export
RenderSession the mode: viewport interaction, preview, playback, export
RenderCli `spirula render`: the same export with no window
RenderPanel.cpp, RenderTimeline.cpp its panel and its timeline
```

Expand Down Expand Up @@ -426,6 +429,198 @@ ignored and missing ones take their defaults, so it can grow without a
version bump. Sources are listed by path: opening a project opens the ones
it names that are not open, and those open besides join it.

### Key by key

`project_to_json` / `project_from_json` (`RenderProject.cpp`) are the
definition; this is what they read. Only `format` and `keyframes` are
needed. A name it does not know takes the default, and a number out of range
is clamped.

**Coordinates.** Positions are in the primary model's (`sources[0]`) own
file coordinates or, when `placement` is given, in the frame that placement
moved the model into; opening the project moves them back. A rotation is
camera-to-world as a quaternion `[w, x, y, z]` with OpenGL camera axes:
x right, y up, looking down -z.

| Key | Default | Meaning |
|---|---|---|
| `format` | (required) | `"spirula-render"` |
| `version` | `1` | |
| `up` | `[0, 0, 1]` | Which way is up for `look_at` keys and the 3D transitions |
| `background` | `[0, 0, 0]` | RGB, 0..1 |
| `end` | `0` | A loop's end, in seconds; 0 is one average key spacing after the last key |
| `placement` | identity | Row-major 3x4 `[sR\|t]`: the editor placement the keys were laid out against |
| `keyframes` | `[]` | The camera's path (below) |
| `sources` | `[]` | The models; `[0]` is the primary one (below) |
| `shots` | `[]` | Which model is shown when; empty shows `sources[0]` throughout (below) |
| `output`, `motion` | | Below |
| `fade_in`, `fade_out` | none | `{"colour": "none"\|"black"\|"white", "seconds": 1}` |

**`keyframes[]`**, sorted by `time` on load. A video lasts until the last
key, or until `end` when it loops, and needs at least two keys.

| Key | Default | Meaning |
|---|---|---|
| `time` | `0` | Seconds |
| `position` | `[0, 0, 0]` | |
| `rotation` | `[1, 0, 0, 0]` | Normalized on load |
| `look_at` | | A point to aim at; replaces `rotation` (which is then worked out from `position`, `up` and `roll`) |
| `roll` | `0` | Degrees about the view axis, with `look_at` |
| `lens` | | This key's own lens. The first key always has one; between keys with one, the lens glides |
| `hold` | `false` | The camera comes to rest here instead of passing through |
| `looks` | | `[{"source": i, "style": {...}}]`: a model's style from this key on, mixed between keys |

**`lens`**

| Key | Default | Meaning |
|---|---|---|
| `projection` | `perspective` | `perspective`, `fisheye`, `equisolid`, `equirectangular`, `orthographic` |
| `focal` | `0.866` | fx / image width. Perspective: FOV = 2 atan(0.5 / focal), so 0.866 is 60 degrees across, and 35 mm-equivalent = 36 x focal |
| `ortho_distance` | `1` | Orthographic: the distance its view width is taken at, world units |
| `distortion` | `0` | 0 none, 1 OpenCV, 2 thin prism |
| `coefficients` | 8 zeros | That model's coefficients, in its order |

**`sources[]`**: `{"path": ..., "style": {...}}`. A splat `.ply`, a point
cloud or a mesh, kind by file. The CLI tries a relative path from the
current folder, then beside the project. At most 8 models.

| `style` key | Default | For |
|---|---|---|
| `points` | `circle` | Points: `square`, `circle`, `gaussian`, `sphere` |
| `point_px` | `3` | Points: pixels at 1080 lines |
| `sphere_radius` | `0.004` | `sphere` points: share of the scene's size |
| `cameras` | `false` | A reconstruction's own cameras |
| `shade`, `flat`, `colour` | `true`, `false`, `true` | Meshes |
| `sh_degree` | `-1` | Splats: -1 is all the file has |
| `primitive` | automatic | Splats: a `--primitive` name, e.g. `3dgut` |

**`shots[]`**, sorted by `start`: from `start` on, `source` (an index into
`sources`, or -1 for the background alone) is shown, coming in by
`transition` over `duration` seconds.

| Key | Default | Meaning |
|---|---|---|
| `start` | `0` | Seconds |
| `source` | `0` | |
| `transition` | `cut` | `cut`, `crossfade`, `dip`, `wipe`, `iris`, `zoom`, and in 3D `sweep`, `grow`, `dust`, `spiral`, `scatter`, `rain`, `dissolve`, `ripple` |
| `duration` | `1` | Seconds |
| `params` | per transition | Two settings, below |
| `colour` | per transition | RGB 0..1: a dip's colour, a sweep's glow |
| `camera` | per transition | Move relative to the screen rather than the world's `up` |
| `exit` | | `{transition, duration, offset, params, colour, camera}`: leave its own way, `offset` seconds after the next shot starts (after the video's end, for the last shot) |

A `dip` may only end the last shot.

| Transition | `params[0]` | `params[1]` |
|---|---|---|
| `wipe` | direction, degrees (0) | softness (0.03) |
| `iris` | | softness (0.03) |
| `zoom` | strength (0.5) | |
| `sweep` | 1 down, 0 up (0) | glow (0.6) |
| `dust` | 0 fall, 1 rise, 2 blow away (0) | turbulence (0.5) |
| `spiral` | turns (1.25) | spread (1) |
| `scatter` | distance (1) | randomness (0.5) |
| `rain` | height (1.2) | stagger (0.7) |
| `dissolve` | sparkle (0.6) | |
| `ripple` | height (0.25) | width (0.3) |

**`output`**

| Key | Default | Meaning |
|---|---|---|
| `kind` | `video` | `video`, `frames` (a folder of images), `photo` |
| `width`, `height` | `1920`, `1080` | 16..16384; rounded to even for MP4 |
| `fps` | `30` | 1..240 |
| `codec` | `h264` | `h264`, `h265`, `av1` (MP4), `av1_webm`, `gif` |
| `quality` | `1` | 0 best, 1 standard, 2 smallest |
| `image_format` | `png` | Frames and photos: `png`, `png_alpha`, `jpeg` |
| `jpeg_quality` | `95` | 10..100 |
| `path` | | Where to write; the extension is made to fit `kind` and `codec`. From the CLI a relative path is from the current folder |

**`motion`**

| Key | Default | Meaning |
|---|---|---|
| `curve` | `spline` | `spline` (smooth through every key), `catmull_rom`, `linear` |
| `ease` | `true` | Start from rest and come to rest |
| `constant_speed` | `false` | The same speed all the way along |
| `loop` | `false` | Return to the first key; the video ends where it began |
| `tension` | `0` | `catmull_rom` only: 0 loose .. 1 a stop at every key |

### An example

A six-second orbit of a splat model, aimed at one point, at 720p:

```json
{
"format": "spirula-render",
"version": 1,
"up": [0, -1, 0],
"sources": [{"path": "splat_30000.ply"}],
"output": {"kind": "video", "width": 1280, "height": 720, "fps": 30,
"codec": "h264", "path": "orbit.mp4"},
"fade_in": {"colour": "black", "seconds": 0.5},
"keyframes": [
{"time": 0, "position": [3.7, -0.6, 0.2], "look_at": [-0.3, 0.4, 0.2],
"lens": {"projection": "perspective", "focal": 0.8}},
{"time": 3, "position": [-0.3, -0.6, 4.2], "look_at": [-0.3, 0.4, 0.2]},
{"time": 6, "position": [-4.3, -0.6, 0.2], "look_at": [-0.3, 0.4, 0.2], "hold": true}
]
}
```

To cut to a mesh and back, add it as a second source and say when each is
shown; the camera path stays the same:

```json
"sources": [{"path": "splat_30000.ply"}, {"path": "mesh.obj"}],
"shots": [
{"start": 0, "source": 0},
{"start": 2.5, "source": 1, "transition": "crossfade", "duration": 1},
{"start": 4.5, "source": 0, "transition": "dust", "duration": 1.5, "params": [0, 0.5]}
]
```

The easiest way to find positions is to set a few keys in the GUI and save:
the saved file lists every key in this form.

## From the command line

`spirula render <project.json>` is mainly for projects generated outside
Spirula, by a script or another tool, in the format above; one saved by the
mode works too. It renders the way the mode's export does, through the same
`frame_spec` (`ShotFrames.cpp`), renderers, encoder choice and sinks
(`RenderOutput.cpp`): a CLI render and a GUI export of one project write the
same frames. The options override what the file says:

```
spirula render shot.json -o out.mp4 [--overwrite]
--model PATH the first model, instead of the one the file names
--kind video|frames|photo, --size WxH, --fps N, --quality 0|1|2
--codec h264|h265|av1|av1-webm|gif (or av1_webm, as in the file;
a codec alone makes it a video)
--time S a photo's moment; the first key otherwise
--ffmpeg EXE which ffmpeg; `ffmpeg` on the PATH otherwise
```

Models are opened as a fresh GUI session opens them: in the file's own
coordinates, with no placement from the editor (keys laid out against a
`placement` are moved back by it), and a path that is not there is looked
for beside the project. Where no flag says otherwise, the `-o` extension
picks a photo or a video, the image format (`.jpg`, `.png`) and the
container (`.mp4`, `.webm`, `.gif`). An output that is already
there is replaced only with `--overwrite`. A frame that does not render
fails the whole render rather than leaving a broken frame in it; Ctrl+C
stops it, encoder probes included, and removes a half-written video. Exit
codes: 0 written, 1 failed, 2 a usage or project error, 130 stopped.

OpenGL composites the frames and draws points and meshes, so the command
needs a GL context. `HeadlessGl` makes one from a hidden GLFW window, which
needs a display: on a server, run it under `xvfb-run`. Everything draws into
FBOs and `glx::set_proc_loader` takes any loader, so a display-less EGL
context on Linux would be one more `HeadlessGl::create` path; Windows and
macOS have no desktop-GL EGL and keep the window.

## Testing

`render_project_test` covers the pure half: the path through its keys, holds,
Expand Down
1 change: 1 addition & 0 deletions src/app/Main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ const std::vector<Tool>& tools() {
static const std::vector<Tool> kTools = {
#ifdef SS_TOOL_GUI
{app::kToolGui, &cmsg::tool_gui, spirula_gui_main},
{app::kToolRender, &cmsg::tool_render, spirula_render_main},
#endif
#ifdef SS_TOOL_SFM
{app::kToolSfm, &cmsg::tool_sfm, spirula_sfm_main},
Expand Down
Loading