Nodes/ComfyUI-H3-Motion-Context/H3 Motion Context Trim
ComfyUI Node

H3 Motion Context Trim

The trim node that keeps your chained H3 soundtrack on the beat

By NikoDemon80·Created 4 months ago·Updated about 12 hours ago· 1,483
H3 Motion Context Trim
  • images
  • audio
  • images
  • audio
◄trim_frames0►
◄fps24.000►
◄level_first_frametrue►
◄match_tailtrue►
◄geiru_drop—►
◄last_clipfalse►

If you're chaining H3 clips with the Motion Context node, you've seen this node's job already: the pinned frames come back at the start of the delivered clip, and they have to come off before you concatenate. This is the node that takes them off. The reason it exists as a separate thing rather than just an image crop is the sound - trim the images only and your audio is left trim_frames/24 seconds longer than the picture. At 5 frames that's 208 ms, silent on ambience but squarely offbeat on anything with a pulse.

So it removes the same span from both streams: whole frames off the images, the matching number of samples off the waveform. Picture and sound stay locked, which is the whole point of chaining H3, since H3 generates them together.

There's a second, sneakier job here. H3's audio latent runs at 40 Hz against 24 fps picture, and the grid rarely lands on a frame boundary - the model rounds to the nearest audio step, so every clip ships either about 8 ms too much sound or about 8 ms too little, depending on its length. A single clip, nobody notices. Concatenate a chain and the error stacks: 16.7 ms at the second seam, 25 ms at the third, growing without bound. It reads as a faint dampening at the first join and a short click at later ones. The match_tail setting fixes exactly that by making the audio duration equal frames/fps, truncating a long tail or padding a short one with silence. Leave it on - the node has no way of knowing what the Motion Context node did, so it stays a setting, but every "it works" in the pack's README assumes it.

Inputs and outputs

The two inputs that matter:

  • images - the decoded clip from your VAE decode.
  • trim_frames - wire this from the Motion Context node's trim_frames output. Don't type it in. The pinned span is whatever the encoder actually produced, and the Motion Context node reports that number to you; typing a guess into two widgets is how you get a seam.

Optionally wire audio (decoded sound for the same clip; skip it for silent clips) and set fps to match what you feed Create Video - it converts the frame trim into an audio duration. Outputs are images and audio, both trimmed by the same span, ready to feed Create Video or a Save Audio node.

Install

Same as the rest of the pack - ComfyUI Manager (search "H3 Motion Context") or:

cd ComfyUI/custom_nodes
git clone https://github.com/NikoDemon80/ComfyUI-H3-Motion-Context

then restart. No model downloads, no extra dependencies; the H3 model and its video/audio VAEs are the things you already had.

Common issues

The one real error is asking it to trim more frames than the clip has - the node refuses rather than handing back a negative-length clip, which usually means your fps doesn't match the clip's real rate. If you're scripting the output afterward, remember H3 emits 32 kHz audio, not 48; a stream-copy concat can't change rate partway, so a hardcoded 48000 silently turns the tail of a long episode into nothing while every duration check still passes. Read the rate off the clip before you mux. There's also a logged note if you trim without wiring audio: the node tells you your soundtrack is about to run ahead of the picture, which is the polite version of the failure this node exists to prevent.

Categoryconditioning/minimax

Inputs (8)

NameTypeDefaultDescription
imagesIMAGEThis clip's decoded frames.
trim_framesINT00–4096Wire from Motion Context's trim_frames.
audiooptAUDIOThis clip's decoded sound, trimmed with the picture so they stay in sync. Leave empty for silent clips.
fpsoptFLOAT24.0001–240The clip's frame rate. Must match Create Video. H3 is 24.
level_first_frameoptBOOLEANtruePinned hold only. H3 makes the first new frame after the join about 5% too bright, so it flashes. This evens that one frame out to match the next. Can be off with masked hold.
match_tailoptBOOLEANtrueMakes the sound exactly as long as the picture. H3's sound runs a few milliseconds long or short on every clip, which adds up across a chain. Leave on.
geiru_dropoptINTWire from Motion Context's geiru_drop. When on, this clip's last 17 frames are cut too, because the next clip carries on from before them.
last_clipoptBOOLEANfalseTurn on for the last clip of a chain only. With Geiru drop on, its last 17 frames are kept, picture and sound, since no clip comes after it. Only this clip's ending changes: leave Geiru drop on in Motion Context. Does nothing with Geiru drop off.

Outputs (2)

NameTypeDescription
imagesIMAGE—
audioAUDIO—