TiledWan Inpaint Crop Improved
Inpaint moving objects in video without the flicker
- image
- mask
- optional_context_mask
- stitcher
- cropped_image
- cropped_mask
If you've ever tried to inpaint a moving object across a video one frame at a time, you know the specific misery this node exists to fix: the mask slides around, so every frame crops a different region, and the result strobes like a broken neon sign. TiledWan Inpaint Crop Improved is the crop half of a two-node inpainting pair that solves it by thinking in video, not single images.
It's one of six nodes in Baverne's comfyUI-TiledWan pack, which exists to push Wan 2.1 VACE video inpainting past its native 832×480 / 81-frame wall (the TiledWan Video VACE Pipeline article covers that half). The crop node is a rework of lquesada's ComfyUI-Inpaint-CropAndStitch - the pack that made "crop, inpaint, stitch" the standard way to guarantee unmasked pixels stay untouched. Where the original assumed stills, this one was rebuilt for batches: per the pack README, it ignores size variation (which caused inconsistencies) and handles masks that appear and disappear over time.
How it works: you feed it a batch of frames plus a mask. It finds the tight box around the masked area, expands it into a context region, then runs a preprocessing chain on the mask - fill holes, expand by N pixels, optional invert, a feathered blur, and a high-pass threshold that kills weak or noisy mask values. Optionally it extends the canvas for outpainting and preresizes the input to a sane range. Finally it resizes the crop to your inpainting model's preferred resolution, pads it to a multiple you choose, and packages everything into a stitcher record so the matching TiledWan Inpaint Stitch Improved can put it back exactly.
The one setting that makes it video-aware is keep_window_size. Instead of letting each frame pick its own crop box, the node takes the largest window across the batch, forces every frame to use it, and linearly interpolates the box's position frame to frame. That's the anti-flicker trick, and it's why you should have it on whenever you're feeding actual footage.
The few inputs you'll actually touch:
keep_window_size- on for video, off for stillscontext_from_mask_extend_factor(default 1.2) - how much surrounding context to keep. More helps the model understand the scene; too much just wastes generation budgetoutput_target_width/output_target_height(default 512×512) - set these to your model's native resolution; 832×480 if you're feeding Wan VACEoutput_padding- keep it a multiple of 8 for VAE, 32 for many diffusion models
It also takes an optional mask (if you leave it empty, the whole image gets processed) and an optional_context_mask if you want to force areas into the crop without inpainting them.
Outputs: stitcher (STITCHER), cropped_image (IMAGE), and cropped_mask (MASK). Wire the image and mask into your inpainting stage, then feed the result plus stitcher into TiledWan Inpaint Stitch Improved. Depending on the build you have, the node may also expose a row of DEBUG outputs showing each intermediate stage - they're the author's debugging aids, and you can ignore them.
Install is the pack install: ComfyUI Manager (search "comfyUI-TiledWan"), or cd ComfyUI/custom_nodes && git clone https://github.com/Baverne/comfyUI-TiledWan, then restart. The pack declares no extra pip dependencies.
Two gotchas worth knowing. First, there's a guard: if you feed a batch without keep_window_size, output_resize_to_target_size must be on, because every frame in a batch has to come out the same size. Second, an unedited mask straight from Load Image sometimes arrives at the wrong shape; the node detects and fixes that, but a manually painted mask is more trustworthy - give it a clean pass before you commit to a long render.
Inputs (27)
| Name | Type | Default | Description |
|---|---|---|---|
| image | IMAGE | Input image(s) to be processed. Can be a single image or batch of images for video processing. | |
| downscale_algorithm | COMBO | bilinear | Algorithm used when downscaling images. Bilinear provides good balance of quality and speed. |
| upscale_algorithm | COMBO | bicubic | Algorithm used when upscaling images. Bicubic provides better quality for upscaling. |
| preresize | BOOLEAN | false | Enable to resize the original image before processing. Useful for normalizing input sizes. |
| preresize_mode | COMBO | ensure minimum resolution | Mode for pre-resizing: minimum ensures image is at least the specified size, maximum caps the size, both enforces a range. |
| preresize_min_width | INT | 10240–16384 | Minimum width for pre-resize operation. Image will be upscaled if smaller. |
| preresize_min_height | INT | 10240–16384 | Minimum height for pre-resize operation. Image will be upscaled if smaller. |
| preresize_max_width | INT | 163840–16384 | Maximum width for pre-resize operation. Image will be downscaled if larger. |
| preresize_max_height | INT | 163840–16384 | Maximum height for pre-resize operation. Image will be downscaled if larger. |
| mask_fill_holes | BOOLEAN | true | Fill holes in the mask using iterative morphological operations. Helps create more complete masked regions. |
| mask_expand_pixels | INT | 00–16384 | Expand the mask by this many pixels before processing. Useful for including more context around masked areas. |
| mask_invert | BOOLEAN | false | Invert the mask so that masked areas become unmasked and vice versa. |
| mask_blend_pixels | INT | 320–64 | Create a soft transition zone around mask edges. Higher values create smoother blending during stitching. |
| mask_hipass_filter | FLOAT | 0.100–1 | Remove mask values below this threshold. Helps eliminate weak mask areas and noise. |
| extend_for_outpainting | BOOLEAN | false | Extend the image canvas for outpainting. Adds padding around the image for generating content beyond original boundaries. |
| extend_up_factor | FLOAT | 1.000.01–100 | Factor to extend image upward. 1.0 = no extension, 1.5 = 50% extension upward. |
| extend_down_factor | FLOAT | 1.000.01–100 | Factor to extend image downward. 1.0 = no extension, 1.5 = 50% extension downward. |
| extend_left_factor | FLOAT | 1.000.01–100 | Factor to extend image leftward. 1.0 = no extension, 1.5 = 50% extension leftward. |
| extend_right_factor | FLOAT | 1.000.01–100 | Factor to extend image rightward. 1.0 = no extension, 1.5 = 50% extension rightward. |
| context_from_mask_extend_factor | FLOAT | 1.201–100 | Expand the context area around the mask by this factor. 1.2 = 20% expansion in all directions. Larger values include more surrounding context for better inpainting. |
| output_resize_to_target_size | BOOLEAN | true | Resize the output to specific dimensions. When disabled, output size depends on mask area and extend factor. |
| output_target_width | INT | 51264–16384 | Target width for output image when resize to target size is enabled. Should match your inpainting model's preferred resolution. |
| output_target_height | INT | 51264–16384 | Target height for output image when resize to target size is enabled. Should match your inpainting model's preferred resolution. |
| output_padding | COMBO | 32 | Padding to ensure output dimensions are multiples of this value. Important for models that require specific dimension alignment (e.g., 8 for VAE, 32 for some diffusion models). |
| keep_window_size | BOOLEAN | false | Maintain consistent crop window size across all images in batch. Essential for video processing to avoid flickering. Uses maximum dimensions found and interpolates missing coordinates. |
| maskopt | MASK | Mask defining areas to be inpainted. White areas will be inpainted, black areas will be preserved. If not provided, the entire image will be processed. | |
| optional_context_maskopt | MASK | Additional mask defining extra context areas to include in the crop. Useful for ensuring important surrounding details are preserved during inpainting. |
Outputs (3)
| Name | Type | Description |
|---|---|---|
| stitcher | STITCHER | Stitcher data containing all information needed to reconstruct the original image after inpainting. Pass this to InpaintStitchImproved. |
| cropped_image | IMAGE | Cropped and processed image ready for inpainting. Contains the masked area plus surrounding context. |
| cropped_mask | MASK | Processed mask corresponding to the cropped image. Shows which areas need to be inpainted. |