Module prerender

Source
Expand description

Pre-render (“movie mode”): render ranges at full quality into a cache so playback shows exactly what an export would, without re-running the effect chain every frame.

Cache: Settings::cache_dir()/prerender/<hash>.rgba, one file per second of timeline at project resolution, keyed by a hash of everything affecting the picture in that second. A worker thread renders whole seconds with the CPU compositor; the UI thread only hands out seconds and collects finished ones, so a slow frame lands on the worker and never on a repaint.

File layout: SEPR + version + width + height + frame count (u32 LE each), then that many width * height * 4 RGBA frames. frame() seeks to the one it needs, so a served frame costs one read and never a whole second of RAM.

Rendering decodes on the worker thread and, when the GPU renderer is up, composites by round-tripping layers to the UI thread’s GL context through a GpuFrameRequest — the same channel export::GpuScratch uses, so movie mode gets the identical shaders the preview does. Falls back to the CPU Compositor per-second if the GPU stops answering (renderer died, or it was never on).

Structs§

Job 🔒
One second of timeline for one worker, against a snapshot of the project it was queued from.
Open 🔒
A half-written second; dropping it without finish() throws the temp file away.
PreRender
Work 🔒
Per-worker scratch: a compositor with its own decoders and font cache.
Worker 🔒
The render worker. Dropping it closes the job channel, so the thread finishes its second and exits.

Enums§

Res 🔒
How a worker’s second ended.

Constants§

CACHE_BUDGET 🔒
Stop growing the cache past this (raw RGBA is big); the oldest files go first.
DEPTH 🔒
Seconds handed over at once: one rendering plus one waiting, so the worker never idles between frames of the UI but an edit still gets picked up within a second of work.
HEADER 🔒
MAGIC 🔒
VERSION 🔒

Functions§

dir 🔒
hash_json 🔒
key_for
Hash of everything that changes the picture during second sec: format, and every clip (with its effects, graph, mask and asset) visible in that second on an active video track.
key_of 🔒
The cache key a file name encodes (path_for’s inverse); None for anything else in the folder.
open_sec 🔒
Create the temp file for one second and write its header.
path_for 🔒
prune 🔒
Keep the cache under budget bytes, oldest files first. Returns the keys it deleted so the caller can forget the seconds they held.
read_frame 🔒
Frame i of a cache file, or None when the file is missing/short/foreign.
sec_range 🔒
Whole seconds covered by [a, b).