Comfy-Org/ComfyUI · error · ValueError
Failed to slice video:\nSource duration: {video.get_duration
Error message
Failed to slice video:\nSource duration: {video.get_duration()}\nStart time: {start_time}\nTarget duration: {duration} What it means
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.
Source
Thrown at comfy_extras/nodes_video.py:302
tooltip="Duration in seconds, or 0 for unlimited duration",
),
io.Boolean.Input(
"strict_duration",
default=False,
tooltip="If True, when the specified duration is not possible, an error will be raised.",
),
],
outputs=[
io.Video.Output(),
],
)
@classmethod
def execute(cls, video: io.Video.Type, start_time: float, duration: float, strict_duration: bool) -> io.NodeOutput:
trimmed = video.as_trimmed(start_time, duration, strict_duration=strict_duration)
if trimmed is not None:
return io.NodeOutput(trimmed)
raise ValueError(
f"Failed to slice video:\nSource duration: {video.get_duration()}\nStart time: {start_time}\nTarget duration: {duration}"
)
class VideoExtension(ComfyExtension):
@override
async def get_node_list(self) -> list[type[io.ComfyNode]]:
return [
SaveWEBM,
SaveVideo,
CreateVideo,
GetVideoComponents,
LoadVideo,
VideoSlice,
]
async def comfy_entrypoint() -> VideoExtension:
return VideoExtension()View on GitHub (pinned to 1c6d8d45b3)
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()
Example fix
# before trimmed = TrimVideo.execute(video, start_time=8.0, duration=5.0, strict_duration=True) # after: clamp to source duration dur = video.get_duration() start = min(8.0, max(0.0, dur - 5.0)) trimmed = TrimVideo.execute(video, start_time=start, duration=min(5.0, dur - start), strict_duration=True)
Defensive patterns
Strategy: validation
Validate before calling
dur = video.get_duration()
start_time = max(0.0, min(start_time, dur))
if start_time + duration > dur:
duration = dur - start_time # or set strict_duration=False Try / catch
try:
out = TrimVideo.execute(video, start_time, duration, True)
except ValueError as e:
if "Failed to slice" in str(e):
duration = video.get_duration() - start_time
out = TrimVideo.execute(video, start_time, duration, False)
else:
raise Prevention
- Derive trim windows from get_duration() instead of constants
- Prefer strict_duration=False when tail shortening is acceptable
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- Reference video {i} is too short: {dur:.1f}s. Minimum durati
- Total reference video duration is {total_video_duration:.1f}
- Video duration must be at least {min_duration}s, got {durati
- Video duration must be at most {max_duration}s, got {duratio
- ar_video sampler requires 5-D video latents [B,C,T,H,W], got
AI-assisted analysis of Comfy-Org/ComfyUI@1c6d8d45b3 (2026-08-14).
Data as JSON: /api/errors/014db56b574a0a3b.
Report an issue: GitHub.