Skip to content

Recording

Tagin T edited this page Sep 4, 2026 · 1 revision

Recording

Recording is the most user-facing feature, so it is wrapped into two one-call helpers in real_time_manim.record. Everything below documents both the helpers and the lower-level hooks they drive.

The two recorders

record_scene fast_record_scene
Window visible (user watches it) hidden by default (hidden=True)
Capture background thread screenshots the live window at fps framebuffer readback piped straight to ffmpeg
Speed wall-clock (user-paced) full speed, no compositing
Output default ~/Downloads/output.mp4 ~/Downloads/output.mp4

Both accept a Scene subclass / instance / callable, auto-record each MLWindow the scene opens, and clean up the transient media/ folder by default.

from real_time_manim.record import fast_record_scene, record_scene

record_scene(MyScene, "live.mp4", fps=30)          # show the window while recording
fast_record_scene(MyScene, "offline.mp4", fps=60)  # hidden, as fast as possible

Which one should I use?

  • Previews / demos for others → record_scene (they see it happen live).
  • CI, batch, or just a file you need fast → fast_record_scene.
  • Only want a frame count (probe) → fast_record_scene(..., count_only=True).

Fast-record sub-modes

fast_record_scene maps to MLWindow.enable_fast_record, which has three modes:

  • Pipe mode (default): every frame is SaveScreenshot → the BMP pixel data is parsed and raw BGR is piped to a resident ffmpeg on stdin → one MP4. No intermediate files on disk.
  • BMP / segment mode (segment=(start, end)): saves each frame as its own BMP into a directory, for range capture or parallel encoding. When segment is set, out_path is treated as a directory.
  • count_only: advances frames but captures nothing — returns how many frames the scene would produce. Useful for estimating length without rendering.

Live record (background thread)

record_scene maps to MLWindow.start_record / stop_record. A background daemon thread snapshots the framebuffer at the requested fps into a temp directory; stop_record joins the thread and encodes the frame sequence with ffmpeg using the actual capture rate (so duration matches wall-clock time, even if the window can't keep up). Temp frames are removed afterwards.

Multi-window scenes

If a scene opens several MLWindows in sequence, the helpers emit one file per window: out.mp4, out_part2.mp4, out_part3.mp4, and each produced path is reported in the returned files.

Auto media cleanup

Rendering leaves transient media/Tex output (see Math Rendering). By default the recorders remove it for you after the run (cleanup=True). Set cleanup=False if you want to keep the raw media directory.

Manual low-level hooks

You usually won't need these, but they are available on MLWindow:

win.start_record("out.mp4", fps=60)   # begin live capture
win.stop_record()                     # encode + finish
win.enable_fast_record("f.mp4", fps=60, hidden=True)  # begin offline capture
win._finish_fast_record()             # flush + encode
win.screenshot("frame.bmp")           # single-frame readback

Dependencies

Recording shells out to ffmpeg (libx264, yuv420p). If ffmpeg is missing, recorders print an error and (for live mode) leave the raw frames in a temp dir for manual encoding.

Clone this wiki locally