{"record":{"id":"1599a4e924827e80","repo":"Comfy-Org/ComfyUI","slug":"frame-idx-is-outside-the-video-s-frames","errorCode":null,"errorMessage":"frame_idx {} is outside the video's {} frames","messagePattern":"frame_idx (.+?) is outside the video's (.+?) frames","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"comfy_extras/nodes_minimax_h3.py","lineNumber":212,"sourceCode":"        height = video.shape[3] * 16\n        width = video.shape[4] * 16\n        frame_count = sum(FRAME_PER_TOKEN[k % 5] for k in range(video.shape[2]))\n\n        guide_frames = 1\n        if image is not None:\n            if vae is None:\n                raise ValueError(\"anchoring guide frames needs the vae input\")\n            guide_frames = image.shape[0]\n            if guide_frames < 5:\n                guide_frames = 1\n            else:\n                while guide_frames % 17 != 5:\n                    guide_frames -= 1\n\n        resolved_frame_index = frame_idx if frame_idx >= 0 else frame_count + frame_idx\n        if resolved_frame_index < 0 or resolved_frame_index + guide_frames > frame_count:\n            if guide_frames == 1:\n                raise ValueError(\"frame_idx {} is outside the video's {} frames\".format(frame_idx, frame_count))\n            raise ValueError(\"a {} frame guide clip at frame_idx {} does not fit in the video's {} frames\".format(\n                guide_frames, frame_idx, frame_count))\n\n        keyframe = {\"resolved_frame_index\": resolved_frame_index}\n        if image is not None:\n            frames = _resize(image[:guide_frames], width, height, \"center\")\n            keyframe[\"latent\"] = vae.encode(frames)\n\n        if audio is not None:\n            if audio_vae is None:\n                raise ValueError(\"anchoring guide audio needs the audio_vae input\")\n            audio_latent, audio_rt = _encode_ref_audio(audio_vae, audio)\n            # the streams share one time axis: FRAME_RESCALE per pixel frame, 1.0 per audio latent frame\n            max_rt = math.floor(samples.tensors[1].shape[-1] - FRAME_RESCALE * resolved_frame_index)\n            if max_rt < 1:\n                raise ValueError(\"frame_idx {} is past the end of the video's audio track\".format(frame_idx))\n            if audio_rt > max_rt:\n                audio_latent = audio_latent[..., :max_rt].clone()","sourceCodeStart":194,"sourceCodeEnd":230,"githubUrl":"https://github.com/Comfy-Org/ComfyUI/blob/1c6d8d45b3693bfbb32385b410d813a7fd6be216/comfy_extras/nodes_minimax_h3.py#L194-L230","documentation":"For a single-frame guide (image batch < 5 frames), the requested frame_idx must resolve to a valid frame index within the video: 0 <= resolved < frame_count. Negative indices are resolved relative to the end (frame_count + frame_idx), and the error reports the raw frame_idx against the total frame count.","triggerScenarios":"frame_idx >= frame_count, or a negative frame_idx whose magnitude exceeds frame_count (resolved_frame_index < 0); frame_count is derived from the video latent tokens via the FRAME_PER_TOKEN pattern (variable frames per token, 4+1 cyclic).","commonSituations":"Assuming a 25 fps or per-pixel-frame count when H3 packs frames into tokens with a 4-then-1 pattern; hardcoding frame_idx=81 for a short clip; negative indexing on very short latents.","solutions":["Set frame_idx within [0, frame_count-1]; remember frame_count is the token-derived video frame count, not the latent length.","For negative values use -1 (last frame) style indexing and keep |frame_idx| < frame_count.","Generate a longer latent upstream if the anchor must sit late in the video."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"frame_count = sum(FRAME_PER_TOKEN[k % 5] for k in range(video.shape[2]))\nresolved = frame_idx if frame_idx >= 0 else frame_count + frame_idx\nassert 0 <= resolved < frame_count, f'frame_idx {frame_idx} out of {frame_count} frames'","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Compute frame_count from the token structure (4+1 pattern), not latent length.","Prefer small non-negative indices or -1 for the last frame.","Lengthen the latent if a late anchor is required."],"tags":["minimax-h3","frame-index","bounds","validation"],"backgroundTag":null,"analyzedSha":"1c6d8d45b3693bfbb32385b410d813a7fd6be216","analyzedAt":"2026-08-14T19:37:18.893Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}