MiniMax H3 Video Inpainting in ComfyUI: Replace Moving Objects with Masks

Esha Sharma
11 Min Read

In this ComfyUI workflow, I use MiniMax H3 Ref2VA with tracked masks to replace
one moving object while keeping the rest of the source video. The workflow file
is a modified derivative of Tensor Alchemist’s MiniMax H3 Ref2VA inpainting
workflow, with a Gemma 4 auto-prompt stage added and my own crop and mask settings.

The difficult part is not writing the prompt.

It is getting the mask right.

My first car and dragon tests failed in different ways. After changing the tracking threshold, crop size, crop mode, and mask expansion, the results became much more stable.

What This MiniMax H3 Inpainting Workflow Does

The workflow has four main jobs.

SAM3 finds and tracks the object.

MaskVidExperiments cleans the tracking and creates a stable crop around the subject.

NKD Mask Ops prepares the mask for MiniMax H3’s latent space and creates another feathered mask for the final composite.

Finally, MiniMax H3 Ref2VA generates the replacement using the source video and a reference image.

For my workflow, I use:

  • MiniMax H3 Ref2VA INT8
  • Qwen3-VL 32B AWQ text encoder
  • MiniMax H3 video VAE
  • MiniMax H3 audio VAE
  • SAM3.1
  • MaskVidExperiments
  • ComfyUI-NKD-Basic-Tools
  • ComfyUI-NKD-Preview-Tools
  • Gemma 4 for prompt generation

ComfyUI officially supports MiniMax H3 Ref2VA for reference-driven generation with images, videos, and audio.

Prepare the Video First

I start with the NKD Timeline node.

This prepares the source video before it reaches the masking workflow.

You can control the working resolution through the megapixel setting. Lowering it can reduce memory use.

The resolution also stays aligned to a multiple of 32, which matches MiniMax H3’s resolution grid.

MiniMax H3 also uses a specific frame structure.

The official ComfyUI documentation describes it as:

17k + 5 frames

at 24 frames per second.

In my workflow, I select the MiniMax H3 17n+5 option and let the timeline prepare the clip.

I can also trim the source video directly inside this node instead of editing the video separately.

Use SAM3 to Find the Object

The SAM3 prompt and the MiniMax H3 generation prompt have completely different jobs.

For SAM3, describe what you want to track.

For example:

car

That is enough for my car test.

The H3 prompt comes later and describes what should replace that object.

ComfyUI’s native SAM3 video tracking currently uses a default text-detection threshold of 0.5.

For my car test, I reduced it to:

0.35

That made detection more permissive and worked better for this clip.

However, I do not recommend copying one threshold into every workflow.

Always check the tracking preview.

Clean the Raw Tracking Mask

The raw SAM3 mask is only the beginning.

I send it through MVEx Mask Cleanup.

MaskVidExperiments describes this node as a way to remove segmentation noise and short-lived mask problems while keeping the real subject. Its Subject Crop node is also designed to prevent unstable crops from creating unwanted camera motion.

This is important for video.

A mask that jumps or changes shape from frame to frame can make the final edit unstable.

Choose the Right Subject Crop Mode

Next, I use MVEx Subject Crop.

Instead of asking H3 to process the complete frame while the target occupies only a small area, this node creates a working crop around the subject.

There are three useful modes:

Tracked follows a moving subject while trying to keep the crop stable.

Combined creates one crop that covers the subject’s complete movement.

Zoomed can also follow larger changes in subject size.

For my moving car, I started with Tracked.

For my harder dragon test, Combined eventually worked better.

Why Crop Scale Matters

crop_scale controls how much surrounding area H3 sees.

A small crop keeps generation focused, but it can become a problem when the subject reaches the edge.

A larger crop gives the model more surrounding context.

My first car result replaced the vehicle correctly, but the edit failed during one part of the movement because the working area was too tight.

I changed only one setting:

Crop scale → 4

The next result was much more stable.

This taught me an important rule:

Give the moving object enough space, but do not make the crop larger than necessary.

A larger crop also means H3 has more of the frame to process.

Use One Mask for Generation and Another for Blending

I use two different mask stages.

The first mask controls where MiniMax H3 is allowed to regenerate.

For this mask, I keep:

Feather: 0

I want a clear generation region.

MaskVidExperiments also includes latent-space mask handling designed around the spatial and temporal compression of video VAEs, including MiniMax H3.

The second mask controls the final blend back into the source video.

For that mask, I use:

Feather: 8

That softer edge helps the generated crop blend back into the original frames.

Using a Reference Image with Ref2VA

For object replacement, I connect:

Picture 1: the new object’s reference image
Video 1: the cropped source video

Picture 1 tells H3 what appearance I want.

Video 1 provides the source movement and shot.

Official H3 guidance also recommends assigning each reference a clear job in the prompt.

For example:

Replace the tracked car with the car from Picture 1. Keep the same black sports-car appearance.

One interesting result appeared here.

My reference car was grey, but I asked for a black car in the prompt.

The generated car became black.

So the reference image strongly guides appearance, but the text prompt can still change visual details.

My Harder Dragon Replacement Test

The dragon test was much more difficult.

At a detection threshold of 0.35, SAM3 did not track the dragon correctly while it entered the scene.

Once the dragon became clearly visible, the tracking improved.

I changed the threshold to:

0.7

For this particular clip, that produced a cleaner mask.

Again, this does not mean 0.7 is always better.

The correct value depends on what the tracking preview shows.

I also saw flickering and areas where the mask did not fully cover the dragon.

That made the later cleanup and mask-expansion stages important.

The Settings That Fixed My Dragon Test

My first dragon attempt used:

Crop mode: Tracked
Crop scale: about 2

The replacement worked after the dragon became visible, but the beginning still failed.

I tried increasing the crop as high as 4.

That helped me understand that crop size alone was not the answer.

The problem came from several things together:

  • tracking quality;
  • mask coverage;
  • crop behaviour;
  • the selected video section;
  • the amount of context around the dragon.

My better result came from this combination:

SettingMy Final Dragon Test
Detection threshold0.7
Crop modeCombined
Crop scale2.25
Mask expand10
Working clip14.38 seconds

This worked better because the camera was fairly stable while the dragon moved into the frame.

A single Combined crop covered its movement more consistently than a crop that kept following it.

The larger mask expansion also gave H3 enough regeneration area around the dragon.

My Main Lesson: Fix the Mask Before Changing the Model

The biggest lesson from these tests is that a failed inpainting result does not automatically mean MiniMax H3 is the problem.

Check the mask first.

If part of the original object remains, inspect the tracking and mask coverage.

If the subject reaches the crop boundary, increase crop_scale.

If a subject moves through a mostly static shot, try Combined instead of Tracked.

If SAM3 loses the object, test the detection threshold and inspect the preview rather than guessing.

For my dragon test, the fix was not simply to make everything larger.

The better result came from choosing the right crop mode, expanding the mask, adjusting the crop scale, and selecting a better working section.

Is MiniMax H3 Good for Video Inpainting?

This custom workflow worked well enough for me to replace both a car and a much harder moving dragon.

The car was easier because SAM3 could track its shape consistently.

The dragon was harder because it entered the scene, changed visible shape, and required much more mask adjustment.

That difference is important.

MiniMax H3 can generate a convincing replacement, but the tracking mask and crop give the model the information it needs to do the job.

For a new shot, I would start with the default SAM3 threshold, inspect the preview, use a stable crop with enough surrounding context, and adjust one setting at a time.

That approach saved me much more time than changing several settings after every failed generation.

Workflow Credit

The JSON below is a modified derivative of the MiniMax H3 Ref2VA inpainting
workflow built by Tensor Alchemist. His original video:
https://www.youtube.com/watch?v=58ydJUg5aR8

Share This Article
Studied Computer Science. Passionate about AI, ComfyUI workflows, and hands-on learning through trial and error. Creator of AIStudyNow — sharing tested workflows, tutorials, and real-world experiments. Dev.to and GitHub.
Leave a Comment

Leave a Reply

Your email address will not be published. Required fields are marked *