Extensions/ComfyUI-H3-Context-Chain
ComfyUI Extension

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.

By javawock7618·Created a day ago·Updated about 23 hours ago· 3
javawock7618/ComfyUI-H3-Context-Chain
Nodes—
On cloudLocal install
Stars3
Updatedabout 23 hours ago
Readme

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 IndexListContextHandler fusion methods (pyramid, overlap-linear, flat, relative) and freenoise toggle for side-by-side comparison.
  • Audio-Driven Mode (Audio 1 Mode: reference / driven): When ref_audio_1 is 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 optional VideoDeflicker into 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 & UPSCALE Panel: Visualizes window ranges and overlap zones on a resizable timeline, offers a one-click Fit Win button to eliminate last-window pullback without changing duration, and provides a collapsible SAMPLER & UPSCALE card with 32-bit seed generation and auto-randomize toggle.

Installation

  1. Place ComfyUI-H3-Context-Chain inside ComfyUI/custom_nodes/.
  2. Restart ComfyUI and hard-refresh the browser (Ctrl + F5).
  3. Add ComfyUI-H3-Context-Chain from 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, and Height (multiples of 32).
  • Set Ctx Len (default 124 frames, 17k + 5 grid) and Overlap (default 39 frames).
  • If the timeline shows a tail pullback warning and a Fit Win chip appears, click Fit Win to snap Ctx Len and Overlap to 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 in Global Prompt.
  • Put per-segment physical actions, posture transitions, and verbatim <d>...</d> dialogue in each Window #N card.
  • 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 Mode and Audio Driven Str are always visible in the SAMPLER & UPSCALE panel and automatically grey out when ref_audio_1 is disconnected or its upstream audio loader is bypassed/muted.
  • Connect an AUDIO source to ref_audio_1 to enable Audio 1 Mode:
    • reference (default): Passes ref_audio_1 as a standard Ref2VA audio reference (minimax_refs).
    • driven: Encodes ref_audio_1 with vae_audio and 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, default 1.00) in driven mode: 1.00 locks the encoded audio latent across all windows, while lower values allow partial audio denoising/adaptation.

5. Configure SAMPLER & UPSCALE & Outputs

  • Keep Fuse on chained-ccw for 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 (8 for 8-step turbo setups), Seed (click the shuffle button to toggle auto-randomize vs. fixed; Shift + click to roll immediately), Latent Upscale, Tiled Decode, and Deflicker (1.00 default; automatically skipped if optical_flow_model is not connected).
  • Connect image, audio, and fps (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 MODEL through ComfyUI-H3-Context-Chain (Standalone) instead of MiniMaxH3ContextWindows (do not chain both at the same time).
  • Mode Selection: Set fuse_method to chained-ccw for sequential non-averaging windows, or switch to native methods (pyramid, overlap-linear, flat, relative) with freenoise anytime.
  • 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.

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 native MiniMaxH3ReferenceToVideo and SamplerCustomAdvanced.

Technical Architecture

  • H3 Frame, Video Latent & 40Hz Audio Alignment: MiniMax-H3 operates on a 17k + 5 frame grid at 24 fps (video_latent_t maps to 5k + 2 temporal video latents) and 40 Hz audio latent tokens. Window slicing and stitching map latent indices to the 17-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-ccw strips any averaging context_handler, copies the previous window's committed overlap latent into the head of the next window, applies a denoise_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 driven mode, ref_audio_1 is resampled to vae_audio's sample rate, encoded into 40 Hz audio latent tokens, and trimmed or edge-padded to match the exact target audio_t length instead of being added to minimax_refs. A per-window (CCW) or full-sequence (native) NestedTensor denoise_mask sets the audio mask to 1.0 - audio_driven_strength while keeping the video mask at 1.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_upscale is enabled and latent_upscale_model is connected, the video latent is upscaled via MiniMaxH3LatentUpscaleWithModel, re-paired with the 1st-pass audio latent, and refined across upscale_steps at upscale_denoise using the same window mode. After VAEDecode (or VAEDecodeTiled) and VAEDecodeAudio, VideoDeflicker runs when enabled and optical_flow_model is 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.