{"record":{"id":"1c2345cb61ae55f6","repo":"Comfy-Org/ComfyUI","slug":"could-not-determine-duration-for-file-self-fil","errorCode":null,"errorMessage":"Could not determine duration for file '{self.__file}'","messagePattern":"Could not determine duration for file '(.+?)'","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"comfy_api/latest/_input_impl/video_types.py","lineNumber":214,"sourceCode":"            )\n            if video_stream and video_stream.frames and video_stream.average_rate:\n                return float(video_stream.frames / video_stream.average_rate)\n\n            # Last resort: decode frames to count them\n            if video_stream and video_stream.average_rate:\n                frame_count = 0\n                container.seek(0)\n                frame_iterator = (\n                    container.decode(video_stream)\n                    if video_stream.codec.capabilities & 0x100\n                    else container.demux(video_stream)\n                )\n                for packet in frame_iterator:\n                    frame_count += 1\n                if frame_count > 0:\n                    return float(frame_count / video_stream.average_rate)\n\n        raise ValueError(f\"Could not determine duration for file '{self.__file}'\")\n\n    def get_frame_count(self) -> int:\n        \"\"\"\n        Returns the number of frames in the video without materializing them as\n        torch tensors.\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            # 1. Prefer the frames field if available and usable\n            if (\n                video_stream.frames\n                and video_stream.frames > 0\n                and not self.__start_time\n                and not self.__duration\n            ):","sourceCodeStart":196,"sourceCodeEnd":232,"githubUrl":"https://github.com/Comfy-Org/ComfyUI/blob/1c6d8d45b3693bfbb32385b410d813a7fd6be216/comfy_api/latest/_input_impl/video_types.py#L196-L232","documentation":"VideoFromFile.get_duration tries container duration, then stream duration, then falls back to decoding/counting packets and dividing by average_rate. If every strategy fails (no usable metadata, and zero decodable/demuxed frames so frame_count == 0), it raises — the file claims to be a video but yields no timing information.","triggerScenarios":"Calling get_duration on a file with missing/zero duration metadata AND zero counted frames — severely truncated downloads, header-only mp4, or a stream where demux yields nothing.","commonSituations":"Interrupted download leaving a stub file; screen-recordings or fragmented mp4s with no header duration; exotic containers where PyAV cannot read duration.","solutions":["Verify the file plays in a player and ffprobe shows a duration; re-download/re-export if not","For fragmented mp4, remux with ffmpeg -i in.mp4 -c copy out.mp4 to write proper header metadata","If duration is genuinely unknown upstream, catch the error and require the user to pass duration explicitly"],"exampleFix":"// before\nd = video_input.get_duration()  # raises on header-only mp4\n\n# after\n# remux first: ffmpeg -i in.mp4 -c copy fixed.mp4\nd = VideoFromFile('fixed.mp4').get_duration()","handlingStrategy":"validation","validationCode":"import av\nwith av.open(path) as c:\n    ok = (c.duration or 0) > 0 or any((s.duration or 0) > 0 for s in c.streams)\nif not ok:\n    raise ValueError('no duration metadata; remux or fix the file before use')","typeGuard":null,"tryCatchPattern":"try:\n    dur = vi.get_duration()\nexcept ValueError:\n    dur = None  # require explicit duration from the caller","preventionTips":["Remux fragmented/header-less mp4s with ffmpeg -c copy before loading","Verify downloads completed before use"],"tags":["video","duration","metadata","pyav","corrupt-file"],"backgroundTag":null,"analyzedSha":"1c6d8d45b3693bfbb32385b410d813a7fd6be216","analyzedAt":"2026-08-14T19:37:18.893Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}