{"record":{"id":"867d99e01436a4b2","repo":"invoke-ai/InvokeAI","slug":"video-reports-invalid-dimensions-width-x-height","errorCode":null,"errorMessage":"Video reports invalid dimensions {width}x{height}","messagePattern":"Video reports invalid dimensions (.+?)x(.+?)","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"invokeai/app/util/video_decode_worker.py","lineNumber":88,"sourceCode":"    if frame.ndim != 3 or frame.shape[2] != 3:\n        raise ValueError(f\"Decoded frame must be RGB; got shape {frame.shape}\")\n    height, width = frame.shape[:2]\n    if height <= 0 or width <= 0 or height * width > MAX_FRAME_PIXELS:\n        raise ValueError(f\"Decoded frame dimensions {width}x{height} exceed the maximum decodable size\")\n\n\ndef _assert_decodable_dims(video_path: Path) -> None:\n    \"\"\"Refuses to decode frames from a video whose reported dimensions exceed the bound.\n\n    If the dimensions cannot be probed, decoding is refused because the parent's frame\n    record bound and PIL checks run only after the decoder has allocated the frame.\n    \"\"\"\n    try:\n        width, height, _duration, _fps = _probe(video_path)[:4]\n    except Exception as error:\n        raise ValueError(f\"Unable to validate video dimensions for {video_path}\") from error\n    if width <= 0 or height <= 0:\n        raise ValueError(f\"Video reports invalid dimensions {width}x{height}\")\n    if width * height > MAX_FRAME_PIXELS:\n        raise ValueError(f\"Video dimensions {width}x{height} exceed the maximum decodable size\")\n\n\ndef _extract_frame(video_path: Path, frame_index: int) -> Optional[Image.Image]:\n    \"\"\"Extracts a single frame from a video file as a PIL Image. Returns None on failure.\n\n    Tries imageio's FFMPEG plugin first since it's the same encoder we use for output,\n    then falls back to cv2 — uploaded videos with unusual codecs may need that path.\n    \"\"\"\n    try:\n        # iio.imread with index=N seeks to that frame directly. Returns RGB HxWxC uint8.\n        frame = iio.imread(video_path, plugin=\"FFMPEG\", index=frame_index)\n        _validate_decoded_frame(frame)\n        return Image.fromarray(frame)\n    except Exception:\n        pass\n","sourceCodeStart":70,"sourceCodeEnd":106,"githubUrl":"https://github.com/invoke-ai/InvokeAI/blob/0b6a024f2ff6a86bfb953dcdb9cc504ef7397a06/invokeai/app/util/video_decode_worker.py#L70-L106","documentation":"After a successful probe, _assert_decodable_dims checks that width and height are both positive. A video reporting 0 or negative dimensions has unusable metadata, so decoding is refused with this ValueError before any frame allocation.","triggerScenarios":"A probe returning CAP_PROP_FRAME_WIDTH/HEIGHT of 0, typical of files whose container opens but whose stream metadata is missing, zero-sized, or corrupt.","commonSituations":"Zero-byte or header-only video files; streams without a video track (audio-only files); corrupt metadata written by a crashed encoder.","solutions":["Verify the file actually contains a video stream (ffprobe <file>)","Re-encode or re-obtain the source video","Add an explicit ffprobe-based pre-check upstream to reject invalid files before calling the worker"],"exampleFix":null,"handlingStrategy":"validation","validationCode":"import cv2\ndef dims_valid(path) -> bool:\n    cap = cv2.VideoCapture(str(path))\n    ok = cap.isOpened()\n    if ok:\n        w, h = int(cap.get(cv2.CAP_PROP_FRAME_WIDTH)), int(cap.get(cv2.CAP_PROP_FRAME_HEIGHT))\n        ok = w > 0 and h > 0\n    cap.release()\n    return ok","typeGuard":"def dims_valid(w: int, h: int) -> bool:\n    return w > 0 and h > 0","tryCatchPattern":"try:\n    _assert_decodable_dims(video_path)\nexcept ValueError as e:\n    if \"invalid dimensions\" in str(e):\n        logger.error(\"bad metadata for %s\", video_path)  # quarantine file\n    else:\n        raise","preventionTips":["Reject zero-byte/header-only files early (check file size > 0)","Confirm a video stream exists with ffprobe","Re-encode files written by crashed encoders","Quarantine files that fail dimension checks instead of retrying"],"tags":["video","opencv","metadata","validation"],"backgroundTag":"invalid-video-dimensions","analyzedSha":"0b6a024f2ff6a86bfb953dcdb9cc504ef7397a06","analyzedAt":"2026-08-29T04:46:49.967Z","schemaVersion":2},"datasetVersion":"2026-08-29T07:17:48.351Z"}