Trim Frames and Audio
Trim an image sequence and its audio to the exact frame you asked for
- images
- audio
- images
- audio
Video models are pedantic about frame counts in a way your footage isn't. LTX needs 8n+1 frames, Wan needs 4n+1, and chunkers pad your segments up to whatever valid number is next so the model doesn't error out or render garbage. The catch: padding means your chunk is now longer than you actually wanted, and the audio that belongs with it is longer too. TKTrimFrames is the cleanup step - give it a target frame_count and it cuts both the image batch and the matching audio back to exactly that, keeping them in sync.
It's the boring, unglamorous node in the TKNodes pack, and it's precisely the kind of glue that makes a chunked video pipeline work. The author's own description says it all: "Trim an image sequence and/or matching audio down to an exact target duration."
How it works
Two inputs in, two outputs out, and both are optional. Feed it images and it keeps min(frame_count, images.shape[0]) frames - the first frame_count frames of your batch. Feed it audio and it trims the waveform to frame_count / target_fps seconds worth of samples, using the audio's own sample rate to convert. Feed it both, which is the point of the node, and both come back trimmed to the same duration, so the audio you later fuse onto the clip still lines up with the visuals.
There's no resampling and no frame interpolation here. It's a pure trim. If your input is shorter than the target, it just leaves it alone - this node never pads, it only cuts. If you need padding, that's the job of the chunker that ran before this one.
The inputs that matter
Two, both simple. frame_count is the true target frame count of the video - the number you actually want in the final clip, not the padded count the model demanded. target_fps is the FPS of your final video, and it only matters for the audio trim: the node needs it to convert frames into seconds of audio. That's the whole list. The tooltip on frame_count ("true target frame count (video)") is the author signaling the exact trap people hit - they feed in the snapped count and get back more than they bargained for.
Where it fits
Think of the pipeline as snap-then-trim. TKSnapFrames or the pack's smart chunkers round your duration up to a valid 8n+1 or 4n+1 count so the model will run; TKTrimFrames rounds it back down to the exact duration you wanted before you stitch segments together. Pair it with TKTrimImageOverlap if your chunks also carry crossfade padding - one strips overlap, this one sets the true length. Audio stays matched the whole way, which is the thing that silently breaks if you do this math by hand.
Install
Same as every node in this pack: ComfyUI Manager, search "Handy Nodes", install, restart. Manual install is the standard clone:
cd ComfyUI/custom_nodes
git clone https://github.com/trashkollector/TKNodes
Restart ComfyUI and you're done. This node is pure tensor slicing - no model downloads, no heavy deps, nothing to configure. It's the kind of node you install for the pack and then quietly rely on in every single workflow.
Inputs (4)
| Name | Type | Default | Description |
|---|---|---|---|
| frame_count | INT | 11–100000 | true target frame count (video) |
| target_fps | FLOAT | 25.001–240 | — |
| imagesopt | IMAGE | — | |
| audioopt | AUDIO | — |
Outputs (2)
| Name | Type | Description |
|---|---|---|
| images | IMAGE | — |
| audio | AUDIO | — |