Log inGet started

Recording: filming the world and keeping the video

Updated December 5, 2026

The shortest thing that works

task.spawn(function()
    -- Record five seconds of what the player sees. The call waits until the
    -- encoder is open, so a path back means the take is running.
    local take, why = av.record("clip.mp4", { max_duration_sec = 5 })
    if not take then error(why) end

    -- A take is filed when it ends.
    while av.is_recording() do task.wait(0.1) end
    print(av.status().recordingEnd, av.status().recordingBytes)
end)

A relative name lands under /zero/source/local/recordings/, this machine's own content: it survives a restart and never syncs to a world. A take is written to disk as it records, and is read from disk afterwards, so a long take holds none of itself in the engine's memory while it records or after. A clip a player wants on another device has to be saved to it (av.save).

In the browser a take under that folder is written into the page's private storage frame by frame as it records, and stays there once it is filed. A take filed anywhere else (a world path under /zero/source/) is written into the VFS as bytes when it ends.

Keeping a clip: av.save

-- In the handler of the button the player clicks to keep the clip:
task.spawn(function()
    local ok, where, report = av.save("clip.mp4")
    if not ok then print("not saved: " .. where) end
end)

The person at the screen decides where the file lands:

  • In the browser, the clip downloads at once when the save rides the player's click or key press, which is why the call belongs in a button's click handler. A save with no such gesture behind it (a timer, the end of a take, an agent's call) makes the page show the player an offer, which they save with a click of their own: a browser starts a download only for a person who just acted. report.state reads "saved" for the first and "offered" for the second.
  • In a native engine, a save dialog opens in the player's downloads folder with the clip's name filled in, and the file is written where they choose (report.state is "offered"). An engine with no window refuses.

So a clip feature that downloads in one click has two controls: one that records the take, and one, shown once the take has ended, whose click saves it. Saving a take that is still recording is refused: it is filed when it ends. av.save answers false and a reason for that, for a path with no file, and for a clip too large for the browser to hold. The saved file is the take byte for byte. userfile.save(path) saves any other file the engine holds the same way.

In the editor, a take is saved without any code: the Files panel's right-click menu on the take (in /zero/source/local/recordings/) holds Save to this device, and that click is the gesture the download rides.

Putting a take on the world's page

A take becomes a trailer on the world's ZeroMind page by adding it to the world's media gallery, from inside the engine:

tools.use("zeromind", "setMedia", world.guid(), "/source/local/recordings/trailer.mp4",
    "/source/media/poster.png") -- the poster (optional) is the video's tile

The call works wherever Luau runs: execute, tool_exec, or the engine shell's zero zeromind setMedia. An agent connected to the engine over MCP also has it as the set_world_media tool (vfs_path, poster_vfs_path). The file is uploaded a piece at a time, so a take of hundreds of megabytes is never held whole, and it is added after the entries the gallery already holds. ZeroMind takes a file of up to 500 MiB, so a longer take is refused before anything is sent, naming its size: record it shorter, at a lower resolution or at a lower quality. While the upload runs the toolbox prints the bytes sent, and the tool answers a ticket it reads the progress from. Screenshots go in the same gallery the same way, as .png, .jpg, .webp or .gif files. The answer is the world's record: media is the gallery, and added the new entry as the gallery holds it (an image or a poster is kept as a WebP copy, so its sha256 is the copy's). tools.use("zeromind", "worldInfo", world.guid()) reads the gallery back.

Recording from the editor

The editor records without any code. F9 starts a take and ends it again, the record button beside the play and pause buttons on the top bar lights while a take runs, and the Recording panel (Agents menu) chooses what the next take films:

  • Scene view (the default) films the viewport as it shows, with whatever overlays are switched on and none of the editor's panels. The picture is the scene's own, so switch the gizmos off first for a clean take.
  • Whole editor films the editor window with its panels, terminals and pop-ups, at the window's own size.
  • a camera other than the one holding the viewport, a size (the source's own, 1080p or 720p), a frame rate and whether the take carries sound.

Takes are named by the local date and time (recording-2026-11-01_12-30-05.mp4) and filed under /zero/source/local/recordings/: this machine's own content, written to disk as the take records, kept across restarts and never synced to a world. The panel lists them newest first, each with Save to this device and Delete. A script or an agent reaches the same service with the recording toolbox (zero recording start, stop, status, list) or require("@builtin::modules.api.editor.recording"). The scope behind the choice is the scope option of av.record, "viewport" or "window", and av.status().recordingScope reads the one a running take films.

Where a take is on disk. A take under /zero/source/local/ is kept in the engine's blob store, addressed by its content, so it has an engine path and no folder of its own on the host to name. Getting it to a person is a save: the Recording panel's Save to this device (a native engine asks where with its save dialog, the browser downloads it), or userfile.save(path) from Luau. An engine with no window has no one to ask: it serves the take from an httpServer route that answers { file = path } (see "Making a master").

Choosing what the take holds

  • max_duration_sec or frames bound the take; without either it runs until av.stop_recording().
  • renderLayers = "all !EditorUI !debug" films the scene without the editor's chrome; add !ui to leave the HUD out too (the viewport shows what the take films while it runs).
  • camera names the camera the take is filmed from.
  • codec picks the video codec from av.status().codecs; "h264" is the one every player and site opens.
  • cadence = "frame" films a fixed-step timeline (a cutscene) at the length it runs to however slowly the engine draws it.

man modules/av/record and man modules/av/save hold the full reference, and av.status() reports how the last take ended and what it produced.

Recording in HDR

A take records in HDR with hdr: hdr = true records HLG, and hdr = "pq" records PQ. Both are 10-bit 4:2:0 HEVC (Main10) in BT.2020 colour, and the stream and the MP4 both state the primaries, the transfer and the matrix, so a player that shows HDR shows the film as HDR. av.capabilities().hdr says what the machine records in HDR before you ask: the transfers and the codecs, or the reason it records none (an encoder that writes 8-bit only, a driver with no 10-bit entrypoint). A take it cannot record is refused with that reason.

local caps = av.capabilities()
if #caps.hdr.transfers > 0 then
    local hlg = av.record("sunset-hlg.mp4", { fps = 30, hdr = true, max_duration_sec = 10 })
end

When to record HDR. A scene whose sun, emissives, fire or bright saturated colours clip in SDR gains the most. An HDR take holds the picture before the display encode, so it does not depend on the screen the engine runs on: an SDR monitor records HDR. While an HDR take records, every frame is drawn as the take's HDR picture, and an SDR window shows it with its highlights clipped at SDR white.

HLG or PQ. HLG (the default) puts SDR white at the 75% reference level of a 1000 cd/m2 nominal display, so the film also reads on a display or a player that ignores its signalling; it takes no luminances. PQ states absolute light: SDR white is shown at paperWhiteNits (default 203, BT.2408's reference white) and highlights reach peakNits (default 1000). A PQ take states its mastering display (BT.2020 primaries, D65, up to the peak) and a MaxCLL of the peak in both the stream and the file. Pick a peak the films will be watched at: 1000 cd/m2 suits most HDR displays and uploads.

Checking a file's HDR metadata. ffprobe -show_streams on the take reads pix_fmt=yuv420p10le, color_primaries=bt2020, color_space=bt2020nc and color_transfer=arib-std-b67 (HLG) or smpte2084 (PQ); ffprobe -show_frames -read_intervals %+#1 lists a PQ take's mastering display and content light level side data. av.status().recordingHdr reads the transfer a take recorded in.

Making a master

A master is a take cut for editing and delivery rather than for watching once. Four options make one, and Recording.start (and zero recording start) take all of them:

  • Quality. quality runs 1 to 100 and the default of 75 is a good-looking clip at about 3 Mb/s at 1080p. quality = 100 is the near-lossless picture a master is cut from, at several times that bitrate. The codec writes H.264 (or h265 where av.status().codecs offers it) at a constant quantizer, so the file's size follows the picture: read recordingBytes over recordingSeconds for the bitrate a take reached.
  • Size. width and height set the picture of the take, resampled from the rect the scene is drawn into (in the editor, the scene panel); a 4K master is 3840 by 2160. A size of another shape than that rect stretches the picture, so a 16:9 master wants a scene rect of that shape. The level the file declares follows its size and rate (5.1 for 4K at 30, 5.2 at 60). av.status().codecs and av.status().backend say what the machine encodes (an encoder that offers h264 only writes 4:2:0 in limited range), and a size the encoder will not take is refused with the reason.
  • Sound. audioTrack is the VFS path of an audio file (wav, ogg, mp3 or flac) the take writes as its Opus track. The file's first sample sits at the first frame and the track ends where the film does, so a soundtrack mixed ahead of time lines up with the picture. It works on both cadences: the track advances with the film's own clock, which is what makes a fixed-step take (cadence = "frame") carry a pre-mixed soundtrack at the length its timeline runs to however slowly the engine drew it. The master mix (audio = true) is the wall-clock mix of the engine, which a fixed-step take cannot share.
  • Name and bound. name files the take at /zero/source/local/recordings/<name>.mp4 (a name a take already holds is refused), and seconds or frames end it by itself.
local Recording = require("@builtin::modules.api.editor.recording")
local path, why = Recording.start({
    name = "trailer-v1",
    width = 3840, height = 2160, quality = 100,
    cadence = "frame", fps = 30, seconds = 60,
    audioTrack = "/zero/source/local/trailer-mix.wav",
})

A take bounded by seconds or frames ends by itself; poll av.status() for recording == nil and recordingError, or read the take from Recording.list() once it ends.

Getting the file out. A take is the machine's own content and a script writes to no path on the host. The way out is to serve it: register an httpServer route whose answer names the take, and fetch the route.

local handle = httpServer.route("GET", "/master", function()
    return { file = "/zero/source/local/recordings/trailer-v1.mp4" }
end)
print(httpServer.address("/master"))   -- http://127.0.0.1:<port>/app/master

A file answer is sent in pieces read from the VFS as the connection takes them, with the file's length stated first and video/mp4 for an .mp4 (a Content-Type in headers replaces it), so a master of any size leaves the engine without being held whole, and the bytes are the take's own. It answers byte ranges, so a player opens the address and seeks in it, and curl -C - -o master.mp4 <address> resumes a download. Anything that speaks HTTP downloads it, curl -o master.mp4 <address> included; stop serving with httpServer.unroute(handle). In the editor, Save to this device (userfile.save) does the same for a person at the screen.

  • documentation
  • guide