Skip to content

arigl snapshot --mp4 FILE --seconds S: record the scene running on its clock - #1310

Merged
transfix merged 2 commits into
masterfrom
feat/snapshot-record
Nov 16, 2026
Merged

transfix merged 2 commits into
masterfrom
feat/snapshot-record

Conversation

@transfix

Copy link
Copy Markdown
Owner

arigl snapshot rendered --frames frames and kept the last, so a scene's physics, water and clouds never got far. This adds a recording: arigl snapshot --mp4 FILE --seconds S runs the scene clock S seconds, --fps frames a second (30 by default), offscreen at --width x --height, and encodes the frames as an MP4.

arigl snapshot --mp4 crates.mp4 --seconds 5 --width 1280 --height 720 \
  --set viewers.main.camera.mode=2 --set viewers.main.camera.track.target=crate_b \
  --set viewers.main.camera.track.back=14 --set viewers.main.camera.track.height=5 \
  examples/ariadne/documents/terrain_lab.ari

What changed

  • Recording loop (inc/cvc/gl/ariadne/record.h, src/cvcGL/ariadne/record.cpp): gla::record_frames(rt, view, opt) runs a loaded document on a fixed clock (AriRuntime::set_fixed_clock). Each frame steps the scene clock by exactly 1/fps of scene time, whatever the wall time, so physics, the clock's tickers (water, clouds) and the custom nodes' ticks move with it. A slow machine makes the same video, only more slowly. Each frame is read back with SceneRenderer::frameRGB and encoded. Frames are paced no faster than real time, as a snapshot's are. The world clock runs at most max_steps_per_advance quanta per advance (1/15 s by default) and drops the rest. So a recorded frame longer than that (under 15 fps) runs as several runtime frames, and no quantum is dropped. Without this, a 10 fps recording ran 0.667 s of clock in 1 s of video.

  • Encoder (inc/cvc/media/video_writer.h, src/cvcMedia/record/video_writer.cpp): cvc::media::VideoWriter takes RGB frames and writes an MP4. It tries three paths in this order:

    1. In process, through the FFmpeg libraries cvcMedia already links for its player, as H.264 when they have libx264 or libopenh264.
    2. An ffmpeg program on PATH, fed raw RGB on its stdin through CreateProcessW or posix_spawn. No shell is involved, and SIGPIPE is held off the writing thread.
    3. In process with FFmpeg's own MPEG-4 Part 2 encoder. cvcpkg's ffmpeg-lgpl has no H.264 encoder, so builds against it land here.

    With none of them, video_encoder() returns "" with the reason. probe_video() decodes a file back, for tests. FFmpeg stays an optional, shared, cvcMedia-only dependency, and the core libraries don't depend on it. The FFmpeg log stays quiet, as the player keeps it, unless CVC_MEDIA_FFMPEG_LOG=1.

  • arigl (src/arigl/main.cpp): --mp4 and --seconds work in a window's snapshot.

    • Before the document loads, arigl checks that an encoder exists and that the size is even, and exits 2 with the reason if not.
    • It prints what it recorded with, e.g. arigl: recorded 150 frames (5 s at 30 fps, 1280x720, libx264) to ....
    • --png writes the last recorded frame. --frames N runs N frames first without recording them.
    • --seconds without --mp4 runs the same frames and writes only the PNG.
    • run, check, --terminal and the browser shell refuse both flags. So does ari (src/ari/main.cpp).
  • host_cli: adds the two flags, their help lines and HostOptions::mp4 / seconds.

  • Docs: docs/ARIADNE.md (the hosts' section, "Recording a video") and arigl's usage text. The old line saying a window snapshot's clock "is fixed" now says it steps a fixed 1/30 s per frame, which is what set_fixed_clock(true) with frame(1/30) does.

How it was checked (Windows 11, MSVC, Release)

FFmpeg 7.1.2 here comes from cvcpkg's ffmpeg-cli (H.264 only, libx264). Its headers come from the ffmpeg recipe's identical 7.1.2 install, named through CVC_FFMPEG_INCLUDE_DIR / CVC_FFMPEG_*_LIBRARY.

  • cvcgl_ari_record (new): records a ball falling onto a static box, 1 s at 10 fps, 160x120. It checks:

    • the file has ftyp, moov and mdat boxes;
    • decoded back, it has 10 frames of 160x120 at 10 fps (h264);
    • app.world_clock() went 0 -> 1.0000;
    • the ball's body fell from z 6.0 to 1.6;
    • the first and last decoded frames differ;
    • --png wrote the last frame.

    It runs the same checks through an ffmpeg program on PATH, where there is one, and passed both ways. It also checks that an odd size and a missing program are refused with a reason. It skips, printing why, when there is no encoder.

  • AriadneHostCli.Mp4AndSecondsRecordASnapshot (new), arigl_record_mp4, arigl_record_needs_seconds, arigl_record_not_in_terminal, ari_refuses_mp4 (new), plus the existing AriadneHostCli.*, arigl_window_snapshot, arigl_check, arigl_url_document, cvcgl_ari_switch and cvcmedia_audio_output: all pass.

  • The writer compiled on its own without CVC_MEDIA_FFMPEG, which is what a cvcMedia without FFmpeg gets:

    • With no ffmpeg on PATH it refuses: no video encoder: this cvcMedia was built without FFmpeg, and there is no ffmpeg program on PATH.
    • With one on PATH it pipes to it and writes a 10-frame H.264 file, to a path with a space in it.
  • terrain_lab, 5 s at 1280x720, 30 fps, with the track camera on crate_b (command above): 150 frames, libx264, 4.9 MB, about 35 s of wall time. Two runs gave the same frames. In the frames:

    • The crates start in the air over the lake, fall, and splash in about 1.5–2 s, with a ring of foam.
    • After that they float, tilt and drift, with rings of ripples around them.
    • The water near the camera has moving waves and whitecaps, and they differ from frame to frame.
    • So with the clock running, nothing stays frozen above the water.

Not checked

  • Linux and macOS: the POSIX program path (posix_spawn, SIGPIPE) and in-process encoders other than libx264. CI will compile them. Whether CI's runners have an ffmpeg program decides whether arigl_record_mp4 and cvcgl_ari_record run there or skip.
  • CI's own FFmpeg (cvcpkg's ffmpeg-lgpl): the MPEG-4 Part 2 path in process wasn't run here, since the local FFmpeg has only libx264. libopenh264 wasn't run either.
  • cvcmedia_player fails locally because this machine's FFmpeg (ffmpeg-cli, H.264 only) has no WebM/Opus decoders for its clip. This branch doesn't touch the player.
  • The browser shell's refusal compiles under __EMSCRIPTEN__, but no wasm build was run.

…s clock

snapshot held still: it renders --frames frames and keeps the last, so a scene's physics, water
and clouds never get far. --seconds S runs the scene clock S seconds instead, --fps frames a
second (30 by default), each frame exactly 1/fps of scene time whatever the wall time, and
--mp4 FILE records those frames as a video at --width x --height. --png still writes the last
frame; --frames N runs N frames first, unrecorded.

- cvcMedia: cvc::media::VideoWriter (cvc/media/video_writer.h), RGB frames in, an MP4 out. In
  process through the FFmpeg libraries the player already links, H.264 where they have libx264
  or libopenh264; else an ffmpeg program on PATH fed raw RGB on its stdin (no shell); else
  FFmpeg's own MPEG-4 Part 2 (cvcpkg's ffmpeg-lgpl has no H.264 encoder). With none it says
  why. probe_video decodes a file back for tests. FFmpeg stays optional and cvcMedia's alone.
- cvcGL: gla::record_frames (cvc/gl/ariadne/record.h) runs a loaded document on a fixed clock
  and encodes each frame read back from the offscreen view. A frame longer than the clock runs
  at once (max_steps_per_advance quanta, under 15 fps by default) runs as several, so no
  quantum is dropped.
- arigl: --mp4 and --seconds in a window's snapshot; it checks the encoder and an even size
  before the document loads (exit 2), and says what it recorded with. run, check, --terminal
  and the browser shell refuse them; so does ari.
- host_cli: the two flags, their help lines and their tests. ARIADNE.md and arigl's usage text
  describe the recording.

Tests: cvcgl_ari_record records a falling ball 1 s at 10 fps, decodes it back (10 frames,
160x120, 10 fps), and checks the scene clock ran 1 s and the ball fell, in process and through
an ffmpeg program where one is on PATH; arigl_record_* and ari_refuses_mp4 check the command
line.
@transfix
transfix enabled auto-merge (squash) November 16, 2026 08:21
@transfix
transfix merged commit 3af6037 into master Nov 16, 2026
29 checks passed
@transfix
transfix deleted the feat/snapshot-record branch November 16, 2026 18:36
transfix added a commit that referenced this pull request Nov 16, 2026
The one conflict, docs/ARIADNE.md, keeps both: #1310's 'Recording a video'
section, then the browser's texture units. cvcgl_ariadne_realize's 16-unit
block still passes with #1311's uWindFetch in the water: no draw runs out.
transfix added a commit that referenced this pull request Nov 16, 2026
…#1305, #1310, #1311)

#1305 gives each Runtime program-lane providers of its own (add_program_intrinsics), so two
documents on one app no longer reach each other's verbs and host functions, and moves
AppRuntime's provider there from the app's list. This branch had split that provider in seven,
each registered on the app with its kind (S1-Q7). Conflicts in ariadne.h, app_runtime.cpp and
ariadne.cpp keep both:

- Runtime::add_program_intrinsics takes a kind too (the form without one is host_only, as
  register_action_intrinsics's), and the Runtime's own list keeps it. AppRuntime adds its seven
  providers there, each with the kind it had, in the same order.
- install_providers runs any list by kind; the Runtime's own run after the app's, by the same
  rules, wherever an env is built: an action, a resident, a spawned child (finish_context), the
  names probe, and init: and a module's init: (every kind as it is, on their own thread).
- host_only_bindings counts the Runtime's own host_only providers, so one that binds anything
  pumps the document's group on the host thread, as an app provider does.
- add_program_intrinsics marks the placement stale, as a late host verb does.
- The own list is read where an env is built, a spawned child's on its pumping worker, so it is
  under a mutex of its own (own_mutex), copied, and run unlocked; names_mutex no longer guards it.

STATE_EXEC_THREADED.md: the Runtime's own providers, AppRuntime's seven among them, and the
fourth late-registration path. Built locally (MSVC Release; AB.lock held the box, so the suites
were not run here); a test of the own providers by kind follows.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant