MVEx Mask To Latent Space
The Correct Way to Feed a Video Mask Into Set Latent Noise Mask
- masks
- vae
- mask
Here's a video-inpainting trap that's cost people a lot of wasted renders: your pixel-space mask is beautifully feathered and sharp, you feed it to Set Latent Noise Mask, and the result bleeds. The background you were trying to keep regenerates anyway, or the thing you were replacing leaks through. The culprit is ComfyUI's own mask preprocessing - reshape_mask trilinear-interpolates video masks across time, which drifts from how causal video VAEs actually group frames and mean-blends your coverage into mush.
MVEx Mask To Latent Space reduces a pixel-space mask batch to latent resolution using the real VAE geometry instead of a generic resize - the actual spatial and temporal compression factors, aligned to how the model groups frames - and the README shows the payoff: replacing a car with a German shepherd in an LTX clip, where the naive path blurs the mask across frames and lets the car bleed through, while this node's mask inpaints cleanly.
How it works
Your VAE compresses pixels to latents on a fixed grid, and video VAEs compress time too - Wan and Hunyuan pack groups of pixel frames into one latent frame, LTX uses its own 8-frame cycle, and chunked models like MiniMax H3 read the mask per 2x2 latent-pixel token. A generic trilinear resize has no idea about any of this. This node reads the compression geometry off the connected VAE - including the exact frame cycle and the 2x2 token grid of chunked models - and reduces the mask with it, so each latent cell gets one value that matches what the model will actually act on.
The inputs that matter
- masks - pixel-space, one per frame.
- compression -
autoreads the geometry from the connected VAE (this is what you want; it handles H3's chunked cycle automatically).manuallets you type the grid in, with presets in the tooltips - spatial 16,frames_per_latent1,4,4,4,4for MiniMax H3. - vae - required when compression is
auto. Connect the VAE of the model you're masking. - spatial_method and temporal_method - how a block reduces to one value. Default
maxmarks a cell if any pixel/frame is masked (conservative, keeps bleed-out away);minonly if all are (tight, leaves the mask smaller). If you're getting "background regenerates" the answer is usually max; if you're getting "subject not fully replaced" it's the opposite. - grow_spatial / grow_temporal - dilate (+) or erode (−) the mask before reduction, in pixels and frames. Cheap insurance against a mask that's a hair too tight.
Output is a single mask - latent-resolution, ready for Set Latent Noise Mask. The README's shorthand for the whole flow: pixel mask → this node → Set Latent Noise Mask → sampler.
Install and gotchas
It's part of MaskVidExperiments, the pack from drozbay (the RES4LYF maintainer, and the same person who wrote WanMaskToLatentSpace in ComfyUI-WanVaceAdvanced - this node is the generalization of that one). Manager search "MaskVidExperiments" or:
cd ComfyUI/custom_nodes
git clone https://github.com/drozbay/MaskVidExperiments
restart. No model downloads, no extra deps, needs ComfyUI v0.15.0+.
The failure modes are mostly about the VAE connection. auto with no VAE connected throws - that's by design, it can't guess your model's geometry. On an image model or anything without temporal compression it degrades gracefully to spatial-only reduction, so it's safe to leave in a graph. And if the mask comes back looking blocky at token boundaries on H3, that's not a bug - that's the 2x2 token grid doing exactly what the model reads. Which is also the reason you'd grab the pack's companion node, MVEx Latent Mask To Mask: previewing the latent mask at pixel resolution shows you precisely what the model will see, token blocks and all.
Inputs (7)
| Name | Type | Default | Description |
|---|---|---|---|
| masks | MASK | Pixel-space masks, one per frame. | |
| compression | COMBO | auto: read the compression geometry from the connected VAE, including the exact frame cycle and 2x2 token grid of chunked models like MiniMax H3. manual: enter it directly. | |
| spatial_method | COMBO | max | How a block of pixels reduces to one latent pixel. max marks the cell if any pixel is masked, min only if all are. |
| temporal_method | COMBO | max | How a group of frames reduces to one latent frame. max marks the frame if any grouped frame is masked. |
| grow_spatial | INT | 0-256–256 | Grow (+) or shrink (-) the mask this many pixels before reduction. |
| grow_temporal | INT | 0-64–64 | Grow (+) or shrink (-) the mask this many frames before reduction. |
| vaeopt | VAE | The VAE used to encode the latents this mask will be applied to. Required when compression is auto. |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| mask | MASK | Latent-resolution mask for Set Latent Noise Mask. |