H3 Context Media Trim
Cut the context prefix and the temporal-grid tail so every segment is exactly its advertised length
- audio
- images
- images
- audio
When a segment runs in Context mode, the decoded video and audio are longer than the task actually asked for. There's the repeated guide prefix (the copied previous-clip tail, which isn't part of the new content) and there are extra trailing frames the model's temporal grid forced it to generate. easy h3ContextMediaTrim is the internal node that trims both, so the delivered segment is exactly the task's frame count - not the context length, not the grid-padded length. It's the reason the segments in your project folder all line up when the combine node stitches them.
What it does
It's a precise, frame-exact trimmer, and it operates on decoded media (images + audio), which is why it sits after the VAE decode in the pipeline. You give it the decoded frames and audio, the number of frames to remove from the front (trim_frames - the context prefix), and the number of frames you actually want to keep (output_frames). It then:
- keeps images
[trim_frames : trim_frames + output_frames]- and errors rather than silently underflowing if the decoded video is too short; - computes the matching audio range in samples (
start_sample = round(trim_frames / fps × sample_rate)), cutting the same duration out of the waveform; - if
pad_audiois on (default), pads the tail of the trimmed audio with silence so it reaches exactly the wanted duration - this is what handles small sample-rate rounding differences; - returns the trimmed images and audio.
So the audio and video both end at precisely output_frames at the given fps. Two different frames budgets can coexist: the pipeline's default reserves the previous segment's last 22 frames as context plus 34 extra generation frames to satisfy H3's temporal grid, then trims the prefix and excess tail, retaining exactly the task's required frame count.
The inputs are audio (required), trim_frames, output_frames, pad_audio, fps, and optional images. Outputs: images and audio.
Where you'd actually meet this node
You won't add it to a canvas by hand - it's one of the _EasyUse/H3 internals that easy multitrackProject expands into, and it's marked dev-only. You'll notice it the first time you inspect the expanded project graph and wonder why there's a trim node inside. The takeaway for your own graphs: if you're hand-building H3 continuation and not trimming by the context length, your clips are silently longer than planned, and the audio is silently offset from the video. That's the exact bug this node exists to prevent.
Installation
Part of ComfyUI-Easy-Media:
# FFmpeg first (the README's hard requirement)
cd ComfyUI/custom_nodes
git clone https://github.com/yolain/ComfyUI-Easy-Media
Restart ComfyUI or install via Manager (search "ComfyUI-Easy-Media"). No extra dependencies - it's tensor slicing and waveform math.
Troubleshooting
- "H3 context trim exceeds decoded video length" - the decoded video is shorter than
trim_frames + output_frames. That's a sign the segment was decoded at a different frame count than expected (changed dimensions or an interrupted run); regenerate. - "would remove all decoded audio" -
trim_framesat the given fps eats the whole waveform. Your trim budget is wrong for this clip. - Audio-video drift after trimming - with
pad_audiooff, small sample-rate rounding can leave the audio a hair short. Turn padding on (the default) if you're trimming by hand.
It's unglamorous, but every segment in a Context project lands on its exact duration because of this node. If your multi-segment exports have always been mysteriously a beat too long, this is the mechanism that fixes it.
Inputs (7)
| Name | Type | Default | Description |
|---|---|---|---|
| audio | AUDIO | — | |
| trim_frames | INT | — | |
| output_frames | INT | — | |
| pad_audio | BOOLEAN | true | — |
| phase_align_video_encode | BOOLEAN | false | — |
| fps | FLOAT | 24.0001–240 | — |
| imagesopt | IMAGE | — |
Outputs (2)
| Name | Type | Description |
|---|---|---|
| images | IMAGE | — |
| audio | AUDIO | — |