{"record":{"id":"21832cc56b30d1bd","repo":"Comfy-Org/ComfyUI","slug":"required-duration-must-be-less-than-video-length","errorCode":null,"errorMessage":"required_duration must be less than video length","messagePattern":"required_duration must be less than video length","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"comfy_extras/nodes_wan.py","lineNumber":824,"sourceCode":"    features = features.transpose(1, 2)  # [1, 512, T]\n    seq_len = features.shape[2] / float(input_fps)  # T/f_a\n    if output_len is None:\n        output_len = int(seq_len * output_fps)  # f_m*T/f_a\n    output_features = torch.nn.functional.interpolate(\n        features, size=output_len, align_corners=True,\n        mode='linear')  # [1, 512, output_len]\n    return output_features.transpose(1, 2)  # [1, output_len, 512]\n\n\ndef get_sample_indices(original_fps,\n                       total_frames,\n                       target_fps,\n                       num_sample,\n                       fixed_start=None):\n    required_duration = num_sample / target_fps\n    required_origin_frames = int(np.ceil(required_duration * original_fps))\n    if required_duration > total_frames / original_fps:\n        raise ValueError(\"required_duration must be less than video length\")\n\n    if fixed_start is not None and fixed_start >= 0:\n        start_frame = fixed_start\n    else:\n        max_start = total_frames - required_origin_frames\n        if max_start < 0:\n            raise ValueError(\"video length is too short\")\n        start_frame = np.random.randint(0, max_start + 1)\n    start_time = start_frame / original_fps\n\n    end_time = start_time + required_duration\n    time_points = np.linspace(start_time, end_time, num_sample, endpoint=False)\n\n    frame_indices = np.round(np.array(time_points) * original_fps).astype(int)\n    frame_indices = np.clip(frame_indices, 0, total_frames - 1)\n    return frame_indices\n\n","sourceCodeStart":806,"sourceCodeEnd":842,"githubUrl":"https://github.com/Comfy-Org/ComfyUI/blob/1c6d8d45b3693bfbb32385b410d813a7fd6be216/comfy_extras/nodes_wan.py#L806-L842","documentation":"Wan's get_sample_indices computes required_duration = num_sample / target_fps and rejects when it exceeds total_frames / original_fps — the clip is shorter than the sampling window needs. This is the top-level sanity check before any start-frame selection for training/video preprocessing.","triggerScenarios":"Calling get_sample_indices with a short clip (e.g. 16 frames at 30fps ≈ 0.53s) while num_sample/target_fps (e.g. 81/16 ≈ 5.06s) exceeds it; also triggered by an incorrect original_fps that shrinks the computed clip duration.","commonSituations":"Dataset curation with mixed-length videos where some clips are too short for the target sample count; wrong fps metadata read from the container; increasing num_sample (longer training windows) without filtering the dataset.","solutions":["Filter or skip videos shorter than num_sample / target_fps seconds before sampling","Reduce num_sample or raise target_fps so the required duration fits the clip","Verify original_fps matches the actual video (misread fps makes the duration look smaller)"],"exampleFix":"# before\nidx = get_sample_indices(30, total_frames=16, target_fps=16, num_sample=81)\n\n# after: guard before calling\nrequired = num_sample / target_fps\nif total_frames / original_fps < required:\n    continue  # skip clip too short","handlingStrategy":"validation","validationCode":"required = num_sample / target_fps\nif required > total_frames / original_fps:\n    raise SystemExit(f\"clip {total_frames/original_fps:.2f}s < required {required:.2f}s; skip or reduce num_sample\")","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Pre-filter datasets by minimum duration = num_sample / target_fps","Verify fps metadata against the actual container before sampling"],"tags":["wan","video","sampling","duration"],"backgroundTag":null,"analyzedSha":"1c6d8d45b3693bfbb32385b410d813a7fd6be216","analyzedAt":"2026-08-14T19:37:18.893Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}