Audio Pad/Trim Duration
Make your audio exactly N seconds long, however you want it done
- audio
- audio
- output_path
- duration_sec
- summary
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_AUDIOpayload, 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, optionalfilename_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.
Inputs (10)
| Name | Type | Default | Description |
|---|---|---|---|
| audio | * | — | |
| target_duration_sec | FLOAT | 10.000.01–86400 | — |
| pad_position | COMBO | end | 3 options: end, start, both |
| pad_mode | COMBO | silence | 3 options: silence, loop, mirror |
| trim_anchor | COMBO | end | 3 options: end, start, center |
| output_format | COMBO | auto | 5 options: auto, wav, mp3, flac, ogg |
| filename_prefix | STRING | MKR_audio_padtrim | — |
| subfolder | STRING | — | |
| overwrite | BOOLEAN | false | — |
| filename_labelopt | STRING | — |
Outputs (4)
| Name | Type | Description |
|---|---|---|
| audio | MKR_AUDIO | — |
| output_path | STRING | — |
| duration_sec | FLOAT | — |
| summary | STRING | — |