lmvideo skill

How an agent uses the lmvideo host to turn an LMScript program into PNG, SVG, PDF, GIF or MP4 output: the exact block form, the video lifecycle, safe paths, real error envelopes and a verification loop. All commands and outputs on this page were run with lmscript 0.2.482 and the lmvideo v0.1.124 Linux binary.

Purpose

lmvideo draws 2D graphics, plots, diagrams, image processing results, CPU rendered 3D scenes and rigid body motion, and encodes frames to video. The drawing code is an _lmcode_ block inside an LMScript file; lmscript type checks the block against the host schema, the host executes it and returns a JSON envelope.

When to use it

Do not use it for interactive playback, for audio, or for scripts written for the legacy lmdraw, lmimg, lmmagnum or lmfilament hosts without migrating them first; see the migration book.

Install

npm install -g @lmctl-ai/lmctl@0.2.460

The repository examples and toolchain lock name compiler 0.2.460; newer compilers work as well. No separate lmvideo install step exists: the block header carries install="github:lmctl-ai/lmvideo@v0.1.124" and lmscript downloads that release into its tool cache on the first real run. Pin the tag, as every repository example does, so reruns use the same host.

MP4 output needs ffmpeg and ffprobe on PATH, supplied by the user. Linux needs glibc 2.35 or newer. Platforms: Linux x86_64 and arm64, macOS x86_64 and arm64 (13 or newer), Windows x86_64 (10 or newer).

Commands

CommandUse
lmscript --check FILE.lmsCompile only. Reports block type errors with file, line and column. Needs the host schema in the cache, so do one real run of any lmvideo program first on a new machine.
lmscript --dry-run FILE.lmsShow the plan without running the host or writing files. Add --plan-format json for a machine readable plan.
lmscript FILE.lms [args]Run for real. Arguments reach the outer script as ARGV.
lmctl autorun URLFetch and run a published example by its raw URL.
lmvideo --lmcode-signaturesList every callable signature of the installed host. Use it to confirm a method exists before writing it.
lmvideo --lmcode-schema --jsonPrint the schema the compiler checks against.
lmvideo render IN.svg OUT.pngRasterize an SVG with no program. Optional --width, --height, --background.
lmvideo render-job DIR, lmvideo render-job-batch DIRRender scene jobs saved with Scene3D.save_job. Options --renderer raster or cycles, --pass color, --output.

The block is always written and executed the same way.

prog = _lmcode_ cli="lmvideo" install="github:lmctl-ai/lmvideo@v0.1.124";
# typed drawing code: let bindings, for loops, if, fn, host calls
end _lmcode_
r = run_lmcode(prog);
if (!r.ok) { println(r.message); }
assert(r.ok);

Block syntax that differs from outer LMScript

Inputs and outputs

DirectionWhatHow
InputLMScript source with one or more _lmcode_ blockslmscript FILE.lms
InputImages, SVG, fonts, meshes, glTF, OBJ, saved picturesimage_file, svg_file, font_load, mesh_load, Scene3D.import_gltf, Scene3D.import_obj, picture_file
OutputVideo or single framevideo.output(path) with video.begin, video.frame, video.end. One frame and a .png path gives a PNG; an .mp4 path is encoded through ffmpeg.
OutputExtra stillsvideo.save_frame(path), Image.save(path), Surface.png(path)
OutputVector and document formatsSurface.svg, Surface.pdf, Picture.svg, Picture.pdf, Picture.skp, PdfDocument.write
OutputGIFTimeline.save(path) or Timeline.encode_gif()
Output3D assets and jobsScene3D.export_gltf, Mesh3D.save, Material.save, Scene3D.save_job
OutputFont recordThe host writes NAME.fonts.json beside each output it reports, listing the fonts used with their hashes and licenses.
OutputEnveloperun_lmcode returns ok and result. result.output holds the out.print lines; result also reports file, width, height, frames, fps and timing counters.

Relative output paths resolve against the directory lmscript runs in. The host does not create missing parent directories: writing into one fails with code RUN_HOST and a cannot write message, so call mkdir in the outer script first, as the repository examples do.

Safety rules

Worked examples

A chart as one PNG

One frame and a PNG path make the video object a still image writer. The plot is retained: configure it, add points, then draw.

# A retained plot drawn into a single PNG frame.
mkdir("build");
prog = _lmcode_ cli="lmvideo" install="github:lmctl-ai/lmvideo@v0.1.124";
video.size(640, 360);
video.frames(1);
video.output("build/plot.png");
video.begin();
video.frame();
canvas.clear("#f5f7fa");
let plot = canvas.plot(20.0, 20.0, 600.0, 320.0).title("Decay").xlabel("t").ylabel("x").x_range(0.0, 10.0).y_range(-1.0, 1.0).background("#ffffff");
let s = plot.series("x(t)", "line", "#2878b5").width(2.5);
for (k in range(0, 101)) {
  let t = float(k) * 0.1;
  s.add(t, pow(2.718281828459045, -0.3 * t) * cos(3.0 * t));
}
plot.draw();
video.end();
end _lmcode_
r = run_lmcode(prog);
if (!r.ok) { println(r.message); }
assert(r.ok);
lmscript plot.lms
wrote build/plot.png (640x360)

A 3D still with a renderer check

The three argument render_image is the raster path with a supersampling count. The seven argument form selects a named renderer, for example scene.render_image(960, 540, "cycles", 32, 4, 42, true) for samples 32, bounces 4, seed 42 and denoising on.

# A raster 3D still: one sphere, one light, one camera.
mkdir("build");
prog = _lmcode_ cli="lmvideo" install="github:lmctl-ai/lmvideo@v0.1.124";
let scene = scene3d().background("#111923");
scene.camera(camera3d().look_at(4.0, 2.8, 6.0, 0.0, 0.6, 0.0).perspective(42.0, 0.1, 100.0));
scene.directional_light(2.0, 3.0, 4.0, "#ffffff", 2.0);
scene.add(mesh_sphere(1.0, 32, 48), material("#d9a441", 0.25, 0.45));
let preview = scene.render_image(480, 270, 2);
preview.save("build/sphere.png");
out.print("cycles available: " + str(render_available("cycles")));
end _lmcode_
r = run_lmcode(prog);
if (!r.ok) { println(r.message); }
assert(r.ok);
println(r.result.output[0]);
lmscript scene.lms
wrote build/sphere.png (480x270)
cycles available: true

Physics replayed into a video

Bake the simulation once, then place each body from the take for every frame. Rendering an Image does not paint the frame: draw it with canvas.image. This example needs ffmpeg.

# A ball dropped on a static floor: bake once, replay the take, paint each frame.
mkdir("build");
prog = _lmcode_ cli="lmvideo" install="github:lmctl-ai/lmvideo@v0.1.124";
let rubber = physics_material(0.55, 0.4);
let world = physics_world(1.0 / 120.0, 42).gravity(0.0, -9.81, 0.0);
world.box(8.0, 0.2, 8.0, 0.0, -0.1, 0.0, 0.0, rubber);
let ball = world.sphere(0.4, 0.0, 3.0, 0.0, 1.0, rubber);
let take = world.bake(120, 2);
video.size(320, 240); video.fps(24); video.frames(48); video.output("build/drop.mp4"); video.begin();
let scene = scene3d().background("#121a2a").ambient(0.25);
let cam = camera3d().look_at(5.0, 3.0, 7.0, 0.0, 1.0, 0.0).perspective(42.0, 0.1, 40.0);
for (f in range(0, video.count())) {
  video.frame();
  scene.clear().camera(cam).directional_light(-2.0, 5.0, 4.0, "#ffefd4", 1.4);
  scene.add(mesh_box(8.0, 0.2, 8.0), "#c49b74").position(0.0, -0.1, 0.0);
  let node = scene.add(mesh_sphere(0.4, 16, 24), "#ef8f8f");
  take.pose(video.t(), ball.id()).sync(node);
  canvas.clear("#121a2a");
  canvas.image(scene.render_image(320, 240, 2), 0.0, 0.0);
}
video.end();
out.print("bodies " + str(take.body_count()) + ", samples " + str(take.frames()));
end _lmcode_
r = run_lmcode(prog);
if (!r.ok) { println(r.message); }
assert(r.ok);
println(r.result.output[0]);
lmscript drop.lms
wrote build/drop.mp4 (320x240, 48 frames at 24 fps)
bodies 2, samples 120

More complete programs, each with its command and preview, are in the Getting started, Examples, Physics, Cycles and Showcase books.

Errors and exit codes

SymptomExit codeCause and fix
lmscript --check prints No cached host schema for "lmvideo"2The host has never been downloaded on this machine. Do one real run of a program whose block has the install attribute, then check again.
lmscript prints type Canvas has no method ... followed by the method list2Compile error in the block. Pick a name from the printed list or from lmvideo --lmcode-signatures.
lmscript prints undefined name ... followed by the schema names2Unknown function, or an outer variable used without a ${name} splice.
r.ok false, code RUN_HOST, message video.frame requires an active video.begin()/video.end() block0 unless assertedCall video.begin before the first video.frame and video.end after the last.
r.ok false, message Video.frame: ffmpeg stopped reading frames ... cannot execute 'ffmpeg'0 unless assertedffmpeg is not on PATH. Install it, or write PNG frames instead.
r.ok false, code APP_FAIL0 unless assertedThe block called out.fail; the message is the script's own text.
r.ok false, code LOAD_UNBOUND0 unless assertedThe block calls a function the pinned host lacks, such as a rest_ function from the newer standard catalog. Remove the call or use a host release that provides it.
Error in host function 'assert': Assertion failed1assert(r.ok) caught one of the failures above. Print r.message before asserting to see which.
lmvideo run by hand with an unknown option2Envelope with code CLI_USAGE and the usage line.
lmvideo --lmcode with an unreadable file3Envelope with code LOAD_BAD_BYTECODE.
lmvideo render with a missing SVG3Runtime error: Cannot open file for reading.

A failed block returns an envelope like this one, produced by calling out.fail on line 3 of a block.

{"ok":false,"phase":"app","code":"APP_FAIL","message":"dsl line 3:5: stopped on purpose","line":3,"column":5}

How to verify

  1. Compile: lmscript --check FILE.lms exits 0 and prints nothing.
  2. Run: lmscript FILE.lms exits 0, and the script asserts r.ok.
  3. Confirm the host line: it prints wrote PATH (WIDTHxHEIGHT) for a still and adds the frame count and rate for a video.
  4. Check the file exists and has the expected properties. For video, ffprobe reports the stream.
  5. Read back facts you printed with out.print from r.result.output instead of parsing console text.
  6. For repeatability, keep the install tag, seeds, sample counts and thread count fixed, and compare with Image.psnr or Image.ssim against a stored reference where an exact match is not expected across platforms.
ffprobe -v error -show_entries stream=codec_name,width,height,nb_frames,r_frame_rate -of default=nw=1 build/clip.mp4
codec_name=h264
width=320
height=180
r_frame_rate=30/1
nb_frames=60