Nodes/MKRShift_Nodes/Audio Pad/Trim Duration
ComfyUI Node

Audio Pad/Trim Duration

Make your audio exactly N seconds long, however you want it done

By criskb·Created 7 months ago·Updated 5 months ago· 0
Audio Pad/Trim Duration
  • audio
  • audio
  • output_path
  • duration_sec
  • summary
target_duration_sec10.00
pad_positionend
pad_modesilence
trim_anchorend
output_formatauto
filename_prefixMKR_audio_padtrim
subfolder
overwritefalse
filename_label

Synchronization is where AI video projects fall apart, and most of the time the audio is the thing that doesn't match the picture. MKRAudioPadTrimDuration exists for exactly that job: take any audio and force it to a target duration. Too short? It pads. Too long? It trims. Same node, both directions, and you get to choose how the padding and trimming behave - which is where the nuance lives.

It's a Utility in the MKRShift_Nodes audio set, and it's the tool you reach for when a generated voice clip needs to land on a 10-second visual, or when you're building a loop that has to be exactly one bar long, or when you're prepping audio for a timeline that tolerates zero drift.

How it works

Two independent decisions, each with three options:

If the audio is shorter than the target: pad_mode decides what fills the gap. silence (default) pads with digital silence - safe and invisible. loop repeats the audio itself, which is how you extend a music loop or ambience seamlessly. mirror repeats a mirrored (reversed) copy, which keeps energy flowing without a hard seam - great for drones and pads that would sound weird looping straight.

pad_position picks where the padding goes: end (default, keeps the start intact), start, or both (splits the pad across both ends).

If the audio is longer than the target: trim_anchor decides what survives. end keeps the beginning (trim the tail), start keeps the ending (trim the head), center keeps the middle and trims both sides. For dialogue, end is usually right - you never want to cut the first word.

All of it is numpy sample math: target duration converts to a sample count against the input sample rate, and the waveform is sliced, zero-padded, tiled, or mirrored to fit.

Inputs that matter

  • audio - MKR_AUDIO payload, waveform tensor, or file path.
  • target_duration_sec - 0.01 to 86400, default 10. The one number that matters.
  • pad_mode / pad_position - how to fill short audio and where.
  • trim_anchor - what to keep when trimming.
  • Standard save block: output_format, filename_prefix, subfolder, overwrite, optional filename_label.

Outputs: audio (MKR_AUDIO), output_path, duration_sec (the resulting duration - should equal your target within a sample), summary.

Install

ComfyUI Manager (search "MKRShift Nodes"), or:

cd ComfyUI/custom_nodes
git clone https://github.com/criskb/MKRShift_Nodes

Restart. Pure numpy; no ffmpeg needed for the operation itself, only for compressed output formats. No models.

Common issues

The obvious one: if your input is much shorter and you pick loop, you're tiling the whole audio, so a voice clip with a trailing breath will loop with a click at the seam - mirror or silence avoids that. Second, if the audio is exactly target length, nothing happens (no warning, no error), which confuses people the first time. And remember target_duration_sec counts total output length - if you pad both, the original audio shrinks relative to the total by the amount of padding on each side, so plan your numbers accordingly.

CategoryMKRShift Nodes/Media/Audio/Utility

Inputs (10)

NameTypeDefaultDescription
audio*
target_duration_secFLOAT10.000.01–86400
pad_positionCOMBOend3 options: end, start, both
pad_modeCOMBOsilence3 options: silence, loop, mirror
trim_anchorCOMBOend3 options: end, start, center
output_formatCOMBOauto5 options: auto, wav, mp3, flac, ogg
filename_prefixSTRINGMKR_audio_padtrim
subfolderSTRING
overwriteBOOLEANfalse
filename_labeloptSTRING

Outputs (4)

NameTypeDescription
audioMKR_AUDIO
output_pathSTRING
duration_secFLOAT
summarySTRING