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
- A reproducible chart, diagram or annotated figure is needed as PNG, SVG or PDF.
- An explanation needs motion: an animated plot, a diagram reveal, a turntable or a short MP4 or GIF.
- An image must be processed or measured (resize, levels, blend, threshold, PSNR, SSIM) without an external image tool.
- A 3D still or sequence is wanted from meshes, PBR materials and lights, as a fast raster preview or a CPU Cycles final.
- Boxes and spheres should fall, collide and stack, or presentation content should tumble, with a fixed step and seed.
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
| Command | Use |
|---|---|
| lmscript --check FILE.lms | Compile 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.lms | Show 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 URL | Fetch and run a published example by its raw URL. |
| lmvideo --lmcode-signatures | List every callable signature of the installed host. Use it to confirm a method exists before writing it. |
| lmvideo --lmcode-schema --json | Print the schema the compiler checks against. |
| lmvideo render IN.svg OUT.png | Rasterize an SVG with no program. Optional --width, --height, --background. |
| lmvideo render-job DIR, lmvideo render-job-batch DIR | Render 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
- Locals are declared with let and are statically typed. Float parameters need float literals such as 40.0, or float(x) to convert an int.
- Outer values enter the block only through splices written ${name}; the block cannot see outer variables otherwise.
- Built in helpers inside the block: float, int, str, sin, cos, sqrt, abs, floor, pow, min, max, clamp, lerp, ease, ease_in, ease_out. Loops use for (i in range(0, n)).
- Colors are hex strings. mix(a, b, t) blends two colors.
- A block level return of a value is rejected; report values with out.print and read them from r.result.output.
Inputs and outputs
| Direction | What | How |
|---|---|---|
| Input | LMScript source with one or more _lmcode_ blocks | lmscript FILE.lms |
| Input | Images, SVG, fonts, meshes, glTF, OBJ, saved pictures | image_file, svg_file, font_load, mesh_load, Scene3D.import_gltf, Scene3D.import_obj, picture_file |
| Output | Video or single frame | video.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. |
| Output | Extra stills | video.save_frame(path), Image.save(path), Surface.png(path) |
| Output | Vector and document formats | Surface.svg, Surface.pdf, Picture.svg, Picture.pdf, Picture.skp, PdfDocument.write |
| Output | GIF | Timeline.save(path) or Timeline.encode_gif() |
| Output | 3D assets and jobs | Scene3D.export_gltf, Mesh3D.save, Material.save, Scene3D.save_job |
| Output | Font record | The host writes NAME.fonts.json beside each output it reports, listing the fonts used with their hashes and licenses. |
| Output | Envelope | run_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
- Read any downloaded script before running it. lmctl autorun and lmscript execute program code, including outer file writes and system commands.
- Run in a fresh or dedicated output directory. Outputs are written relative to the working directory and existing files with the same name are replaced.
- Use lmscript --check, then lmscript --dry-run, before a first real run of an unfamiliar script. The dry run executes no host code and writes nothing.
- Pin the host with install="github:lmctl-ai/lmvideo@v0.1.124" instead of a floating tag when results must be repeatable.
- Always test r.ok. A failed block does not make lmscript exit nonzero by itself; without assert(r.ok) the script continues after a failed render.
- Keep sequences small while iterating: lower size, frames and samples first. Cycles work multiplies with resolution and sample count and a short video can take minutes.
- Preview images in the books document upstream output; they are not a cross platform pixel identity guarantee.
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
| Symptom | Exit code | Cause and fix |
|---|---|---|
| lmscript --check prints No cached host schema for "lmvideo" | 2 | The 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 list | 2 | Compile error in the block. Pick a name from the printed list or from lmvideo --lmcode-signatures. |
| lmscript prints undefined name ... followed by the schema names | 2 | Unknown 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() block | 0 unless asserted | Call 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 asserted | ffmpeg is not on PATH. Install it, or write PNG frames instead. |
| r.ok false, code APP_FAIL | 0 unless asserted | The block called out.fail; the message is the script's own text. |
| r.ok false, code LOAD_UNBOUND | 0 unless asserted | The 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 failed | 1 | assert(r.ok) caught one of the failures above. Print r.message before asserting to see which. |
| lmvideo run by hand with an unknown option | 2 | Envelope with code CLI_USAGE and the usage line. |
| lmvideo --lmcode with an unreadable file | 3 | Envelope with code LOAD_BAD_BYTECODE. |
| lmvideo render with a missing SVG | 3 | Runtime 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
- Compile: lmscript --check FILE.lms exits 0 and prints nothing.
- Run: lmscript FILE.lms exits 0, and the script asserts r.ok.
- Confirm the host line: it prints wrote PATH (WIDTHxHEIGHT) for a still and adds the frame count and rate for a video.
- Check the file exists and has the expected properties. For video, ffprobe reports the stream.
- Read back facts you printed with out.print from r.result.output instead of parsing console text.
- 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