Nodes/Papcorns ComfyUI Custom Nodes/Papcorns - Audio Trim & Save
ComfyUI Node

Papcorns - Audio Trim & Save

File In, File Out, Four Formats, One Gotcha

By papcorns·Created about a year ago·Updated about a year ago· 0
Papcorns - Audio Trim & Save
    • output_path
    audio_pathinput_audio.mp3
    start_time_ms0
    duration_ms7000
    output_formatmp3
    output_filenametrimmed_audio

    If you just need a clip of audio cut out of a file and written back to disk in one step, Papcorns - Audio Trim & Save is the file-based half of the pack's audio duo. Its sibling Audio Trimmer works in memory on the AUDIO socket; this one takes a file path, slices it, and exports a new file in your choice of format, returning the output path. It's the one you reach for when the audio is sitting on disk and you want a trimmed, converted copy without building a multi-node pipeline.

    How it works

    The node loads the file at audio_path with pydub, checks your start time is sane, slices audio[start:end], and exports with pydub's export(). The inputs:

    • audio_path - path to the source file (default input_audio.mp3, so you must set this to something real).
    • start_time_ms - cut-in point, default 0.
    • duration_ms - how much to keep, default 7000 ms.
    • output_format - one of mp3, wav, ogg, m4a.
    • output_filename - base name without extension (default trimmed_audio).

    The single output is output_path, a STRING with the absolute path to the file it just wrote.

    The gotcha you'll hit first

    The output file lands in ComfyUI's current working directory, not ComfyUI/output and not next to your source file. The code builds the path as f"{output_filename}.{output_format}" and then converts it to an absolute path - which resolves against whatever directory ComfyUI was launched from. So your trimmed_audio.mp3 will materialize somewhere unexpected, and if you're running ComfyUI as a service with a weird working dir, finding it can be a mini-scavenger hunt. There's no output-directory option, so plan around it: either launch from a known folder or just accept the path string it hands you (it does return the real absolute path, so a Show Text node downstream will tell you exactly where it went).

    The second thing worth knowing: pydub only speaks WAV natively. For mp3, ogg, and m4a it shells out to ffmpeg, so you need ffmpeg on your system PATH or those three formats will fail with an "unable to decode" style error. WAV works with zero extras. If you hit that error, install ffmpeg (on most Linux distros sudo apt install ffmpeg; on Windows, add it to PATH) and restart.

    Where it fits

    This is a utility node for prep work more than live generation: trimming a music bed down to 30 seconds before feeding it to an audio-to-video workflow, cutting the dead air off a narration track, converting a source file to the exact format a downstream tool wants. LTX-2 audio workflows and MMAudio pipelines are hungry for precisely-trimmed inputs, and doing it with one node instead of an external editor keeps the whole job inside ComfyUI.

    Install

    It's part of the Papcorns pack:

    cd ComfyUI/custom_nodes
    git clone https://github.com/papcorns/Papcorns-Comfyui-Custom-Nodes
    cd Papcorns-Comfyui-Custom-Nodes
    pip install -r requirements.txt
    

    Restart ComfyUI (or search "Papcorns" in ComfyUI Manager). The requirements bring in pydub; remember the ffmpeg dependency above for anything that isn't WAV.

    One more honest note

    Error handling here is "return an error string as your output_path" - if the input file doesn't exist, you'll get a string that starts with Error: instead of a path. It's a blunt instrument for a small personal pack, but it won't silently eat your audio; it tells you what went wrong in the console. For the same price you get a real trim+convert utility in one node, which is more than most ComfyUI audio setups offer.

    CategoryPapcorns🍿

    Inputs (5)

    NameTypeDefaultDescription
    audio_pathSTRINGinput_audio.mp3
    start_time_msINT00–3600000
    duration_msINT7000100–3600000
    output_formatCOMBOmp34 options: mp3, wav, ogg, m4a
    output_filenameSTRINGtrimmed_audio

    Outputs (1)

    NameTypeDescription
    output_pathSTRING