Video math
Edit every frame of a video with one formula
- V
- F
- Expression
- Expression_pi
- stack
- VIDEO
- STACK
Video nodes in ComfyUI are usually all-in-one generators or complex tiling beasts. Video math from More Math is the boring-sounding one that quietly does the work: it runs an expression over every frame of your video tensor, with the frame index available as a variable. Want a time-based fade, a frame-accurate color grade, or a moving crop computed from the frame number? One expression, no frame-by-frame workflow.
How it works
A video tensor is basically an image tensor with the batch axis meaning "frame". The pack says it plainly: for the visual part, video behaves like the image/latent nodes - X, Y, W, H, C for channel, and crucially B (batch = frame index) and T (batch count = frame count). So a fade over the clip is I0 * (B/T), and a horizontal wipe is if(X < W*(B/T), I0, I1) between two videos. The whole shared function library is in scope: blur, fft, perlin, remap, smoothstep.
Like the conditioning node, this one has two expression fields. Expression handles the tensor part (default I0*(1-F0)+I1*F0, a crossfade between videos V0 and V1 by float F0), and Expression_pi handles the pooled part for the audio/auxiliary side of the video - the README notes video refers to the image variables for visuals and to the audio variables (S, R, sample count) for the sound part.
Inputs and outputs
V is the autogrow video list (V0, V1, ...), F the floats, and the two expression fields as above. length_mismatch handles differing video lengths - error default, plus tile (repeat shorter clips) and pad (treat missing frames as zero).
Outputs are VIDEO and STACK. The video feeds the usual video consumers - a save node, an upscaler, or a video model's decode stage.
Installing it
Identical to the rest of the pack:
cd ComfyUI/custom_nodes
git clone https://github.com/mcDandy/more_math
cd more_math
pip install -r requirements.txt
Restart ComfyUI, or install "More math" from ComfyUI Manager. Only real dependency is antlr4-python3-runtime beyond torch. No model downloads.
Gotchas
Frame-count math bites everyone once: if your video's frame count isn't what you think, B/T fades land in the wrong place - check T first with print(T) (the library has print, which logs and returns its argument). Two videos with different lengths will trip the default error on length_mismatch immediately; decide whether you want the short one tiled or zero-padded. And per-frame evaluation across hundreds of frames is slow - keep expressions light. It's a new, solo-maintained pack, so the video path has the fewest battle-tested war stories, but for frame-accurate edits this is exactly the node that should exist and didn't.
Inputs (6)
| Name | Type | Default | Description |
|---|---|---|---|
| V | COMFY_AUTOGROW_V3 | — | |
| F | COMFY_AUTOGROW_V3 | — | |
| Expression | STRING,SYNTAX_TREE | V0 | Expression to apply on tensor part of video |
| Expression_pi | STRING,SYNTAX_TREE | V0 | Expression to apply on audio part of video |
| length_mismatch | COMBO | error | How to handle mismatched video lengths. tile: repeat shorter inputs; error: raise error on mismatch; pad: treat missing frames as zero. |
| stackopt | STACK | Access stack between nodes |
Outputs (2)
| Name | Type | Description |
|---|---|---|
| VIDEO | VIDEO | — |
| STACK | STACK | — |