{"record":{"id":"be17a582c0a4bd26","repo":"Comfy-Org/ComfyUI","slug":"trimaudioduration-start-time-must-be-less-than-en","errorCode":null,"errorMessage":"TrimAudioDuration: Start time must be less than end time and be within the audio length.","messagePattern":"TrimAudioDuration: Start time must be less than end time and be within the audio length\\.","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"comfy_extras/nodes_audio.py","lineNumber":477,"sourceCode":"            return IO.NodeOutput(None)\n        waveform = audio[\"waveform\"]\n        sample_rate = audio[\"sample_rate\"]\n        audio_length = waveform.shape[-1]\n\n        if audio_length == 0:\n            return IO.NodeOutput(audio)\n\n        if start_index < 0:\n            start_frame = audio_length + int(round(start_index * sample_rate))\n        else:\n            start_frame = int(round(start_index * sample_rate))\n        start_frame = max(0, min(start_frame, audio_length))\n\n        end_frame = start_frame + int(round(duration * sample_rate))\n        end_frame = max(0, min(end_frame, audio_length))\n\n        if start_frame >= end_frame:\n            raise ValueError(\"TrimAudioDuration: Start time must be less than end time and be within the audio length.\")\n\n        return IO.NodeOutput({\"waveform\": waveform[..., start_frame:end_frame], \"sample_rate\": sample_rate})\n\n    trim = execute  # TODO: remove\n\n\nclass SplitAudioChannels(IO.ComfyNode):\n    @classmethod\n    def define_schema(cls):\n        return IO.Schema(\n            node_id=\"SplitAudioChannels\",\n            search_aliases=[\"stereo to mono\"],\n            display_name=\"Split Audio Channels\",\n            description=\"Separates the audio into left and right channels.\",\n            category=\"audio\",\n            inputs=[\n                IO.Audio.Input(\"audio\"),\n            ],","sourceCodeStart":459,"sourceCodeEnd":495,"githubUrl":"https://github.com/Comfy-Org/ComfyUI/blob/1c6d8d45b3693bfbb32385b410d813a7fd6be216/comfy_extras/nodes_audio.py#L459-L495","documentation":"TrimAudioDuration computes start_frame and end_frame in samples (with negative start interpreted as offset-from-end) and clamps both to [0, audio_length]. If after clamping start_frame >= end_frame — zero/negative requested duration, start beyond audio length, or a negative start pushing the window off the end — it raises.","triggerScenarios":"duration=0 or negative; start_time pointing at or past the end of the clip; negative start_time whose absolute offset exceeds remaining audio after clamping (e.g. start=-1000s on a 5s clip); extremely short audio with rounding collapsing the window to zero samples.","commonSituations":"Parameterized/batch trim workflows where duration is computed from metadata and can reach 0; loops trimming successive segments where the final segment's computed start lands past the end.","solutions":["Validate duration > 0 and 0 <= start < audio duration before the node call","For negative starts, ensure abs(start) leaves at least duration seconds of audio: audio_length/sr - abs(start)*sr >= duration*sr","Compute segments against the actual waveform length (waveform.shape[-1] // sample_rate) instead of nominal metadata","Skip or pass-through when the requested window is empty (the node already returns untrimmed audio for some None/empty cases)"],"exampleFix":"// before\nTrimAudioDuration(audio, start_time=120.0, duration=10.0)  # 60s clip\n\n// after\nlength_s = waveform.shape[-1] / sample_rate\nstart_time = min(start_time, max(0.0, length_s - duration))\nTrimAudioDuration(audio, start_time=start_time, duration=duration)","handlingStrategy":"validation","validationCode":"def trim_window_valid(waveform, sample_rate, start, duration) -> bool:\n    n = waveform.shape[-1]\n    if duration <= 0:\n        return False\n    s = n + round(start * sample_rate) if start < 0 else round(start * sample_rate)\n    s = max(0, min(s, n))\n    e = max(0, min(s + round(duration * sample_rate), n))\n    return s < e","typeGuard":null,"tryCatchPattern":"try:\n    out = TrimAudioDuration.execute(audio, start_time, duration)\nexcept ValueError as e:\n    if 'Start time must be less than end time' in str(e):\n        out = audio  # nothing to trim; pass through\n    else:\n        raise","preventionTips":["Clamp start and duration against measured clip length, not metadata","Treat duration <= 0 as an error at the UI/parameter layer","Compute segment boundaries once from waveform.shape[-1]/sample_rate"],"tags":["audio","trim","parameter-validation"],"backgroundTag":null,"analyzedSha":"1c6d8d45b3693bfbb32385b410d813a7fd6be216","analyzedAt":"2026-08-14T19:37:18.893Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}