{"record":{"id":"014db56b574a0a3b","repo":"Comfy-Org/ComfyUI","slug":"failed-to-slice-video-nsource-duration-video-ge","errorCode":null,"errorMessage":"Failed to slice video:\\nSource duration: {video.get_duration()}\\nStart time: {start_time}\\nTarget duration: {duration}","messagePattern":"Failed to slice video:\\\\nSource duration: (.+?)\\\\nStart time: (.+?)\\\\nTarget duration: (.+?)","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"comfy_extras/nodes_video.py","lineNumber":302,"sourceCode":"                    tooltip=\"Duration in seconds, or 0 for unlimited duration\",\n                ),\n                io.Boolean.Input(\n                    \"strict_duration\",\n                    default=False,\n                    tooltip=\"If True, when the specified duration is not possible, an error will be raised.\",\n                ),\n            ],\n            outputs=[\n                io.Video.Output(),\n            ],\n        )\n\n    @classmethod\n    def execute(cls, video: io.Video.Type, start_time: float, duration: float, strict_duration: bool) -> io.NodeOutput:\n        trimmed = video.as_trimmed(start_time, duration, strict_duration=strict_duration)\n        if trimmed is not None:\n            return io.NodeOutput(trimmed)\n        raise ValueError(\n            f\"Failed to slice video:\\nSource duration: {video.get_duration()}\\nStart time: {start_time}\\nTarget duration: {duration}\"\n        )\n\n\nclass VideoExtension(ComfyExtension):\n    @override\n    async def get_node_list(self) -> list[type[io.ComfyNode]]:\n        return [\n            SaveWEBM,\n            SaveVideo,\n            CreateVideo,\n            GetVideoComponents,\n            LoadVideo,\n            VideoSlice,\n        ]\n\nasync def comfy_entrypoint() -> VideoExtension:\n    return VideoExtension()","sourceCodeStart":284,"sourceCodeEnd":320,"githubUrl":"https://github.com/Comfy-Org/ComfyUI/blob/1c6d8d45b3693bfbb32385b410d813a7fd6be216/comfy_extras/nodes_video.py#L284-L320","documentation":"The video trim node delegates to video.as_trimmed(start_time, duration, strict_duration=...); when that returns None the requested slice could not be produced (typically the requested window extends beyond the source). The node then raises with source duration, start time, and target duration for diagnosis.","triggerScenarios":"Requesting start_time + duration beyond the video's end with strict_duration=True (exact length required); start_time >= source duration; NaN/negative duration values; a source whose duration could not be determined so as_trimmed cannot guarantee the slice.","commonSituations":"Hardcoded trim values reused across videos of different lengths; off-by-one assumptions about inclusive end time; seeking near the tail of a clip with strict duration enforcement on.","solutions":["Read the reported source duration and clamp start_time/duration so start_time + duration <= source duration","Set strict_duration=False to allow a shorter tail slice instead of failing","Compute trim parameters dynamically from video.get_duration()"],"exampleFix":"# before\ntrimmed = TrimVideo.execute(video, start_time=8.0, duration=5.0, strict_duration=True)\n\n# after: clamp to source duration\ndur = video.get_duration()\nstart = min(8.0, max(0.0, dur - 5.0))\ntrimmed = TrimVideo.execute(video, start_time=start, duration=min(5.0, dur - start), strict_duration=True)","handlingStrategy":"validation","validationCode":"dur = video.get_duration()\nstart_time = max(0.0, min(start_time, dur))\nif start_time + duration > dur:\n    duration = dur - start_time  # or set strict_duration=False","typeGuard":null,"tryCatchPattern":"try:\n    out = TrimVideo.execute(video, start_time, duration, True)\nexcept ValueError as e:\n    if \"Failed to slice\" in str(e):\n        duration = video.get_duration() - start_time\n        out = TrimVideo.execute(video, start_time, duration, False)\n    else:\n        raise","preventionTips":["Derive trim windows from get_duration() instead of constants","Prefer strict_duration=False when tail shortening is acceptable"],"tags":["video","trimming","duration","validation"],"backgroundTag":null,"analyzedSha":"1c6d8d45b3693bfbb32385b410d813a7fd6be216","analyzedAt":"2026-08-14T19:37:18.893Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}