ComfyUI-H3-Context-Chain
All-in-one MiniMax-H3 Ref2VA custom node with Chained Context Windows (CCW), built-in sampler, 2nd-pass latent upscale, VAE decode, and deflicker for 15s+ video generation.
ComfyUI-H3-Context-Chain
An all-in-one custom node for MiniMax-H3 (Ref2VA) in ComfyUI that generates 15s+ long-form videos with Chained Context Windows (CCW), Audio-Driven generation, built-in sampling, 2nd-pass latent upscaling, VAE/audio decoding, and video deflickering—without overlap-averaging ghosting or single-pass OOM spikes.
Key Features
- Chained Context Windows (
chained-ccw): Denoises overlapping windows sequentially in chronological order instead of averaging overlapping window predictions at every step, eliminating double-exposure ghosting during motion/pose transitions while keeping peak VRAM bounded to roughly one window. - Native Window Mode Fallback: Supports ComfyUI's native
IndexListContextHandlerfusion methods (pyramid,overlap-linear,flat,relative) andfreenoisetoggle for side-by-side comparison. - Audio-Driven Mode (
Audio 1 Mode:reference/driven): Whenref_audio_1is connected (and its upstream loader is active), choose between standard Ref2VA audio conditioning (reference) or encoding the input audio directly into the initial AV audio latent (driven) with adjustable retention (Audio Driven Str). - All-in-One Pipeline: Combines Ref2VA reference encoding, per-window conditioning (
Global Prompt+Window #1..N), 1st-pass sampling, optional 2nd-pass latent upscaling (MiniMaxH3LatentUpscaleWithModel), video/audio VAE decoding, and optionalVideoDeflickerinto a single node (ComfyUIH3ContextChain). - Pass-1 Audio Isolation & Safety: Decodes audio from the 1st-pass audio latent and sanitizes non-finite (
NaN/Inf) samples before output to prevent downstream AAC encoding failures. - Interactive Timeline &
SAMPLER & UPSCALEPanel: Visualizes window ranges and overlap zones on a resizable timeline, offers a one-clickFit Winbutton to eliminate last-window pullback without changing duration, and provides a collapsibleSAMPLER & UPSCALEcard with 32-bit seed generation and auto-randomize toggle.
Installation
- Place
ComfyUI-H3-Context-ChaininsideComfyUI/custom_nodes/. - Restart ComfyUI and hard-refresh the browser (
Ctrl + F5). - Add
ComfyUI-H3-Context-Chainfrom the node search menu.
Quick Usage Guide
1. Wire Required Inputs
model,clip,vae_video,vae_audio: Connect your MiniMax-H3 Ref2VA checkpoints/models and video/audio VAEs.- Optional inputs: Wire
ref_image_1..9,ref_video_1..3,ref_video_audio_1..3,ref_audio_1..3,latent_upscale_model,optical_flow_model, or override inputs (width_in,height_in,duration_in,ctx_len_in,overlap_in,prompt_global,prompt_1..9) as needed. Connected dynamic slots auto-grow (_1->_2-> ...).
2. Set Duration, Resolution & Context Windows
- Set
Dur (s)(e.g.,15.0s),Width, andHeight(multiples of 32). - Set
Ctx Len(default124frames,17k + 5grid) andOverlap(default39frames). - If the timeline shows a tail pullback warning and a
Fit Winchip appears, clickFit Winto snapCtx LenandOverlapto a clean window count while keeping your target duration.
3. Write Global & Window Prompts
- Put persistent subject/reference definitions (
Subject 1/Picture 1), background/camera consistency instructions, and baseline audio notes inGlobal Prompt. - Put per-segment physical actions, posture transitions, and verbatim
<d>...</d>dialogue in eachWindow #Ncard. - Tip for
chained-ccw/ overlapping windows: Describe the continuing posture at the start/end of each window so transitions stay smooth and ghost-free.
4. Audio-Driven Generation (ref_audio_1)
Audio 1 ModeandAudio Driven Strare always visible in theSAMPLER & UPSCALEpanel and automatically grey out whenref_audio_1is disconnected or its upstream audio loader is bypassed/muted.- Connect an
AUDIOsource toref_audio_1to enableAudio 1 Mode:reference(default): Passesref_audio_1as a standard Ref2VA audio reference (minimax_refs).driven: Encodesref_audio_1withvae_audioand injects it directly into the initial AV audio latent so video generation follows the input audio track (e.g., lip-sync, rhythm, or speech timing).
- Adjust
Audio Driven Str(0.00–1.00, default1.00) indrivenmode:1.00locks the encoded audio latent across all windows, while lower values allow partial audio denoising/adaptation.
5. Configure SAMPLER & UPSCALE & Outputs
- Keep
Fuseonchained-ccwfor sequential non-averaging long-form generation (Anchor V = 1.00,Anchor A = 1.00,Audio Fade = 2,Win Seed+ = True). - Configure
Sampler(res_multistep),Scheduler(simple),Steps(8for 8-step turbo setups),Seed(click the shuffle button to toggle auto-randomize vs. fixed;Shift + clickto roll immediately),Latent Upscale,Tiled Decode, andDeflicker(1.00default; automatically skipped ifoptical_flow_modelis not connected). - Connect
image,audio, andfps(24.0) directly to your video/audio preview or save nodes.
Standalone Patch Node: ComfyUI-H3-Context-Chain (Standalone)
This pack also includes ComfyUI-H3-Context-Chain (Standalone) (ComfyUIH3ContextChainStandalone), a drop-in MODEL -> MODEL patch node that extends ComfyUI's native MiniMaxH3ContextWindows with chained-ccw while letting you freely wire native conditioners, samplers (KSampler, SamplerCustomAdvanced), LoRAs, and Audio-Driven setups.
- Drop-in Replacement: Wire
MODELthroughComfyUI-H3-Context-Chain (Standalone)instead ofMiniMaxH3ContextWindows(do not chain both at the same time). - Mode Selection: Set
fuse_methodtochained-ccwfor sequential non-averaging windows, or switch to native methods (pyramid,overlap-linear,flat,relative) withfreenoiseanytime. - Native Compatibility:
- Works with single or
ConditioningCombine-chained multi-window conditionings (split_conds_to_windows = True). - Preserves upstream
denoise_mask(including Audio-Driven audio latent masks) across windows. - Can be reused on 2nd-pass latent upscale samplers for consistent low-VRAM execution.
- Works with single or
Included Workflows
Sample workflows are included under workflows/:
workflows/ComfyUI-H3-Context-Chain.json: Full All-in-One (ComfyUI-H3-Context-Chain) workflow with multi-window prompts, reference loaders, 2nd-pass latent upscale, and deflicker.workflows/ComfyUI-H3-Context-Chain_Standalone.json: Minimal standalone (ComfyUI-H3-Context-Chain (Standalone)) workflow wired with nativeMiniMaxH3ReferenceToVideoandSamplerCustomAdvanced.
Technical Architecture
- H3 Frame, Video Latent & 40Hz Audio Alignment: MiniMax-H3 operates on a
17k + 5frame grid at24 fps(video_latent_tmaps to5k + 2temporal video latents) and40 Hzaudio latent tokens. Window slicing and stitching map latent indices to the17-frame block grid and corresponding audio latent spans so video and audio stay synchronized across chained windows. - Sequential CCW vs. Native Averaging: Native
IndexListContextHandler(split_conds_to_windows=True) averages overlapping window predictions across every denoising step, which can produce semi-transparent double-exposure artifacts when pose or motion changes sharply across a window boundary.chained-ccwstrips any averagingcontext_handler, copies the previous window's committed overlap latent into the head of the next window, applies adenoise_mask(1.0 - anchor_strength) over the anchored overlap, and commits only newly generated tokens to CPU-resident output tensors (out_v,out_a). - Audio-Driven Latent Injection: In
drivenmode,ref_audio_1is resampled tovae_audio's sample rate, encoded into40 Hzaudio latent tokens, and trimmed or edge-padded to match the exact targetaudio_tlength instead of being added tominimax_refs. A per-window (CCW) or full-sequence (native)NestedTensordenoise_masksets the audio mask to1.0 - audio_driven_strengthwhile keeping the video mask at1.0(outside anchored overlaps), preserving the driven audio latent through both Pass 1 and Pass 2 while guiding video synthesis. - VRAM Bounding & Cache Cleanup: Keeping full-length accumulated buffers on CPU and freeing per-window GPU tensors (
del ...+comfy.model_management.soft_empty_cache()) after each window keeps GPU memory footprint tied to a single window rather than scaling linearly with total video duration. - 2nd-Pass Upscale & Deflicker: When
enable_latent_upscaleis enabled andlatent_upscale_modelis connected, the video latent is upscaled viaMiniMaxH3LatentUpscaleWithModel, re-paired with the 1st-pass audio latent, and refined acrossupscale_stepsatupscale_denoiseusing the same window mode. AfterVAEDecode(orVAEDecodeTiled) andVAEDecodeAudio,VideoDeflickerruns when enabled andoptical_flow_modelis connected.
Acknowledgements
This custom node was created with Gemini.
License
This project is licensed under the GNU General Public License v3.0 (GPL-3.0). See LICENSE and README.ja.md for the Japanese documentation.