Nodes/kubakub nodes/kubakub trim to exact duration (ltx safe)
ComfyUI Node

kubakub trim to exact duration (ltx safe)

LTX audio that never drifts — trim to exact duration

By kubakubkub·Created about a month ago·Updated 2 days ago· 10
kubakub trim to exact duration (ltx safe)
  • audio
  • audio
  • actual_start_seconds
  • num_samples
◄start_seconds0.000►
◄duration_seconds9.960►
◄wrap_starttrue►
◄overrun_modeloop►
◄snap_samples_to0►

If you've built music-video or projection-mapped work on an audio-driven video model, you've met this bug. You cut a slice of the track at an arbitrary offset, feed it to the audio-video pipeline, and some runs come out a hair shorter than others - because the slice ended at the end of the file, or a rounding landed on a different sample count. The video sampler happily generates frames; the audio side expects a fixed number of samples; the two stop agreeing and you get a drift, a silent tail, or a straight-up shape error.

This node exists to make that impossible. It takes an audio clip and returns exactly the requested duration, every time, as a fixed number of samples, whatever the start position is and whatever it runs into.

How it stays exact

Sample maths, done deliberately. The output sample count is round(duration_seconds × sample_rate), so for a given duration it's the same number on every run. The start is round(start_seconds × sample_rate). Then it reads:

  • loop (the default) - a circular read. The index wraps around the track, so if your window runs off the end it continues seamlessly from the beginning. Exactly the target length, no silence, no gap.
  • clamp - the window slides backwards so it ends exactly at the end of the track, and actual_start_seconds tells you where it really starts.
  • silence_pad - take what's there, fill the rest with zeros. Sometimes you want the gap, usually you don't.

wrap_start handles the other half of the problem: with it on, the start is taken modulo the track length, so you can feed raw cumulative seconds - the running total of clip starts as the show progresses - straight in and never touch an upstream modulo node again. That's the point of the "raw cumulative seconds" tooltip. Before this node, that modulo was a hand-built node chain you had to remember to duplicate.

Inputs and outputs

audio is the clip, straight from Load Audio.

start_seconds is where the clip starts in the track. With wrap_start on, big cumulative values are fine.

duration_seconds defaults to 9.96, which looks like a typo and isn't: at 25 fps that's 249 frames, and LTX generates in 8n+1 frame blocks. Change your fps or your frame count and this number changes with it - it's the single most important field on the node.

overrun_mode is the loop/silence_pad/clamp choice above. snap_samples_to (0 = off) rounds the length up to a multiple of that many samples. It's a targeted fix for a one-frame audio/picture drift after the audio VAE - set it to the VAE's sample stride when you see that, and leave it at 0 otherwise. Rounding up, not down, so you never lose a frame.

The three outputs: audio, the clip itself; actual_start_seconds, where it truly begins after wrapping or clamping; and num_samples, the length, which is exactly the kind of number you want to see once in your life when debugging an AV alignment problem.

The combination worth stealing: wire actual_start_seconds into the kubakub timecode filename prefix node so your saved clips are named for where they actually sit in the song, not where you asked for. If the wrap moved the clip, the filename tells the truth.

Context

LTX is Lightricks' video family, and the reason it keeps coming up in audio-shaped workflows is that LTX-2 onward generates picture and sound in one model - the first open-weights release to do so, shipping in January 2026 with a rough first month and a much smoother 2.3 after it. It's fast, it's open, and its guide-mask machinery is the reason a shorter-than-expected audio clip stops being a cosmetic issue and becomes a failed run. If you're on 2.3, use the distilled 1.1 LoRA rather than 1.0 while you're at it; the 1.0 reportedly gives you mumbling audio out of the first sampler stage.

Installing

ComfyUI Manager → search kubakub nodes → install → restart, or:

cd ComfyUI/custom_nodes
git clone https://github.com/kubakubkub/ComfyUI_KubaNodes
python -m pip install -r ComfyUI_KubaNodes/requirements.txt

opencv-python-headless if you don't have OpenCV; ComfyUI 0.37.0 or newer. Torch does the work here, so there's no ffmpeg dependency for this node specifically. The node id predates the current pack layout - it was merged in from the author's older Comfy_KubakubNodes pack, and saved workflows kept their links, so a workflow from that era still loads.

Two things to watch

An empty audio input returns silence of the right length rather than erroring. That's considerate in a batch and confusing in a debug session, so if your output "clip" is quiet, check what's upstream before blaming the trim.

And if you set snap_samples_to to explore a drift, remember it changes num_samples, which is the whole contract of this node. Set it deliberately, and take it back to 0 when you're done.

Categorykubakub/2d/motion

Inputs (6)

NameTypeDefaultDescription
audioAUDIO—
start_secondsFLOAT0.0000–1000000000Start position. Feed your raw cumulative seconds here; with wrap_start on, no upstream modulo is needed.
duration_secondsFLOAT9.9600.001–1000000000Constant clip length. Output sample count is fixed by this.
wrap_startBOOLEANtrueOn: a start past the end of the track wraps around to its beginning (start modulo the track length). Off: the start is used as it is.
overrun_modeCOMBOloopWhen the clip runs past the end of the track: loop = continue from the track start (no silence), silence_pad = fill the rest with silence, clamp = move the clip back so it ends at the end of the track.
snap_samples_tooptINT00–10485760 = off. Rounds the length up to a multiple of this many samples (the audio VAE's sample stride); only for a one-frame drift between sound and picture.

Outputs (3)

NameTypeDescription
audioAUDIOThe clip, always the same number of samples for the same duration.
actual_start_secondsFLOATWhere the clip really starts in the track, in seconds (after wrap / clamp).
num_samplesINTLength of the clip in samples.