{"record":{"id":"f02196b11e712d89","repo":"Comfy-Org/ComfyUI","slug":"could-not-determine-frame-count-for-file-self","errorCode":null,"errorMessage":"Could not determine frame count for file '{self.__file}'\\nNo frames exist for start_time {self.__start_time}","messagePattern":"Could not determine frame count for file '(.+?)'\\\\nNo frames exist for start_time (.+?)","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"comfy_api/latest/_input_impl/video_types.py","lineNumber":266,"sourceCode":"                if estimated_frames > 0:\n                    return estimated_frames\n\n            # 3. Last resort: decode frames and count them (streaming)\n            start_time, duration = self.get_active_trim_window()\n            frame_count = 1\n            start_pts = int(start_time / video_stream.time_base)\n            end_pts = int((start_time + duration) / video_stream.time_base)\n            container.seek(start_pts, stream=video_stream)\n            frame_iterator = (\n                container.decode(video_stream)\n                if video_stream.codec.capabilities & 0x100\n                else container.demux(video_stream)\n            )\n            for frame in frame_iterator:\n                if frame.pts >= start_pts:\n                    break\n            else:\n                raise ValueError(f\"Could not determine frame count for file '{self.__file}'\\nNo frames exist for start_time {self.__start_time}\")\n            for frame in frame_iterator:\n                if frame.pts >= end_pts:\n                    break\n                frame_count += 1\n            return frame_count\n\n    def get_frame_rate(self) -> Fraction:\n        \"\"\"\n        Returns the average frame rate of the video using container metadata\n        without decoding all frames.\n        \"\"\"\n        if isinstance(self.__file, io.BytesIO):\n            self.__file.seek(0)\n\n        with av.open(self.__file, mode=\"r\") as container:\n            video_stream = self._get_first_video_stream(container)\n            # Preferred: use PyAV's average_rate (usually already a Fraction-like)\n            if video_stream.average_rate:","sourceCodeStart":248,"sourceCodeEnd":284,"githubUrl":"https://github.com/Comfy-Org/ComfyUI/blob/1c6d8d45b3693bfbb32385b410d813a7fd6be216/comfy_api/latest/_input_impl/video_types.py#L248-L284","documentation":"When counting frames in a trim window, VideoFromFile seeks to start_pts and iterates until the first frame with pts >= start_pts. If the iterator exhausts without any frame reaching start_pts — the requested start_time lies beyond the last frame of the stream — the for/else raises, combining 'Could not determine frame count' with the fact that no frames exist at that start_time.","triggerScenarios":"Calling get_frame_count (or as_trimmed with a window) where start_time is at or after the end of the video, e.g. start_time >= duration, so every decoded frame has pts < start_pts.","commonSituations":"Trim node computes start_time from a larger assumed duration; user requests the last fraction of a clip whose real duration is shorter than metadata claims; off-by-one seek to end_pts exactly.","solutions":["Clamp start_time below the video's actual duration: start = min(start_time, get_duration() - 1/fps)","Validate trim parameters against get_duration() before calling get_frame_count/as_trimmed","If metadata duration was wrong, remux to fix the header (see duration error) so clamping works off real values"],"exampleFix":"// before\ncount = video.get_frame_count(start_time=10.0)  # clip is 8s long\n\n# after\ndur = video.get_duration()\ncount = video.get_frame_count(start_time=min(10.0, dur - 0.1))","handlingStrategy":"validation","validationCode":"dur = video.get_duration()\nif start_time >= dur:\n    start_time = max(0.0, dur - 1.0 / float(video.get_frame_rate()))","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Clamp trim windows against the real duration before seeking","Treat metadata durations as upper bounds and re-check after remux"],"tags":["video","trim","frame-count","seek-out-of-range"],"backgroundTag":null,"analyzedSha":"1c6d8d45b3693bfbb32385b410d813a7fd6be216","analyzedAt":"2026-08-14T19:37:18.893Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}