Nodes/ComfyUI-Apt_Preset/AD_Inject_Latent
ComfyUI Node

AD_Inject_Latent

The node that surgically re-generates one tracked object inside a video

By cardenluo·Created 2 years ago·Updated a day ago· 320
AD_Inject_Latent
  • av_latent
  • vae
  • crop_img
  • transform
  • av_latent
smooth_frames9

You know that ComfyUI workflow where you track a face or an object through a video, and you only want the diffusion pass to touch that one region - not re-roll the whole frame? This is the node in the middle of that pipeline. AD_Inject_Latent takes the crops that AD_sam_Crop tracked out of a source video and injects them into a MiniMax H3 video latent, with a denoise strength that adapts per frame to how big the object is. It's the "make the edit happen" step between tracking and sampling.

The name undersells it a bit. What it actually does is replace the video half of an H3 AV latent with VAE-encoded versions of your crops, then attaches a per-frame noise_mask that tells the sampler how hard to re-generate each frame. That's the whole trick: the sampler denoises the crop region hard where the object is small and unreliable, and barely touches it where the object already fills the frame, so you don't get texture pop-in from over-redoing frames that were fine.

What you plug in

  • av_latent (LATENT) - a MiniMax H3 joint AV latent, the nested video+audio tensor from the pack's H3 loader or a previous AD_MinMax_* node. This node refuses plain latents, so you'll get a clear error if you feed it anything else.
  • vae (VAE) - the model's VAE, used to encode the crops into latent space.
  • crop_img (IMAGE) - the fixed-size per-frame crops straight out of AD_sam_Crop.
  • transform (H3FACEXFORM) - the tracking metadata from AD_sam_Crop (the crop boxes, per-frame weights, and object sizes). The node needs this to know where each crop sits and how confident the track was.
  • smooth_frames (INT, default 9) - the one knob worth touching. It smooths the per-frame strength curve with a Gaussian window so you don't see visible strength "pops" between frames. Crank it toward 61 on shaky footage; drop it toward 1 when you want the strength to track the object aggressively.

Output is a single av_latent, which wires into the pack's sampler (or the context that feeds it).

Why the denoise adapts per frame

The node reads the object rectangle from the transform, works out its size relative to the crop canvas, and maps it to a strength between 0.35 and 1.0: small object gets nearly full denoise, large object gets the floor. Then it multiplies by the per-frame tracking weight (so frames where SAM3 wasn't confident fade toward zero change) and applies the smooth_frames blur. The result is a noise_mask interpolated to the latent's frame count. It's a genuinely thoughtful design - a static-strength approach would either ghost the small object or wreck the large one.

Wiring it into the pipeline

The canonical chain is AD_sam_Crop → (crop_img, transform) → AD_Inject_LatentAD_sam_stitch. The stitch node pastes the refined crops back onto the original frames.

Where people get burned

The most common failure is a dimension mismatch: the crop canvas (crop_width/crop_height on AD_sam_Crop) must equal the generation resolution on the H3 side - the error message "Ensure the H3 width/height matches crop_img" is the giveaway. Also, this pack is built around the RUN_CONTEXT bus (its "Loader → Controller → Sampler" design), so if you're mixing AD_Inject_Latent into a stock workflow, be aware the latent it expects is H3-specific, not a generic EmptyLatent. Keep smooth_frames on the odd numbers it suggests - the step is 2 for a reason.

Installing it

It ships in the cardenluo/ComfyUI-Apt_Preset pack. Easiest: ComfyUI Manager → search "Apt_Preset" → Install. Or:

cd ComfyUI/custom_nodes
git clone https://github.com/cardenluo/ComfyUI-Apt_Preset

Then run install.bat (or pip install -r requirements.txt) and restart ComfyUI. Because this node targets MiniMax H3, you also need a recent ComfyUI build with native H3 support (comfy_extras.nodes_minimax_h3) - on an old install it fails fast with "This ComfyUI build does not provide MiniMax H3 support". It's a heavy pack with optional extras (GGUF, Advanced-ControlNet, nunchaku, segmentation models) that you don't need for this node - install them only if other nodes in your workflow ask.

CategoryApt_Preset/AD

Inputs (5)

NameTypeDefaultDescription
av_latentLATENT
vaeVAE
crop_imgIMAGE
transformH3FACEXFORM
smooth_framesINT91–61Temporally smooths the per-frame strength curve to avoid visible texture pops.

Outputs (1)

NameTypeDescription
av_latentLATENT