{"record":{"id":"317e6c62df1177f7","repo":"affaan-m/ECC","slug":"width-and-height-must-be-even-integers","errorCode":null,"errorMessage":"Width and height must be even integers","messagePattern":"Width and height must be even integers","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"skills/taste-application/scripts/tasteforge/media/common.py","lineNumber":15,"sourceCode":"\"\"\"Validation and transactional output for local media tools.\"\"\"\n\nimport math\nimport os\nimport tempfile\nfrom contextlib import contextmanager\nfrom pathlib import Path\n\n\ndef geometry(width, height, fps, duration=1):\n    for value in (width, height, fps, duration):\n        if isinstance(value, bool) or not math.isfinite(value) or value <= 0:\n            raise ValueError(\"Geometry, fps and duration must be finite and positive\")\n    if width != int(width) or height != int(height) or width % 2 or height % 2:\n        raise ValueError(\"Width and height must be even integers\")\n\n\n@contextmanager\ndef output_file(destination, overwrite=False):\n    destination = Path(destination)\n    if os.path.lexists(destination) and not overwrite:\n        raise FileExistsError(destination)\n    destination.parent.mkdir(parents=True, exist_ok=True)\n    fd, filename = tempfile.mkstemp(\n        prefix=\".media-\", suffix=destination.suffix, dir=destination.parent\n    )\n    os.close(fd)\n    temporary = Path(filename)\n    try:\n        yield temporary\n        if temporary.stat().st_size == 0:\n            raise RuntimeError(\"Media command produced an empty output\")\n        if overwrite:","sourceCodeStart":1,"sourceCodeEnd":33,"githubUrl":"https://github.com/affaan-m/ECC/blob/8321021c54d670126ce3b2969d5deb880b4b0c2a/skills/taste-application/scripts/tasteforge/media/common.py#L1-L33","documentation":"After the finiteness check, geometry() requires width and height to be whole numbers (width == int(width), height == int(height)) and even (divisible by 2), because most video codecs require even frame dimensions. Fractional or odd dimensions abort the export/render.","triggerScenarios":"Calling export_draft/render/make_clip with width=1080.5, height=721, or any non-integral float; computing dimensions from an aspect-ratio calculation without rounding to even values.","commonSituations":"Aspect-ratio math like int(1920/2.35) yielding an odd height; passing heights like 719 or 1081 from UI presets; scaling code producing floats (1920 * 0.577).","solutions":["Round down to an even number: height = int(height) // 2 * 2","Use standard even presets (1920x1080, 1280x720, 1080x1920)","Apply even-rounding after any aspect-ratio computation before calling the API","Reject odd user-supplied dimensions in your UI/config layer"],"exampleFix":"// before\nheight = width / aspect  # e.g. 815.999...\nexport_draft(files, name='edit', width=1920, height=height)\n\n// after\nheight = int(width / aspect) // 2 * 2  # even integer\nexport_draft(files, name='edit', width=1920, height=height)","handlingStrategy":"validation","validationCode":"def dims_even(width, height):\n    return width == int(width) and height == int(height) and width % 2 == 0 and height % 2 == 0\n# normalize first\nwidth, height = int(width), int(height) // 2 * 2\nassert dims_even(width, height)","typeGuard":"def is_even_int_dimension(v):\n    return isinstance(v, int) and not isinstance(v, bool) and v > 0 and v % 2 == 0","tryCatchPattern":"try:\n    render(src, width=w, height=h)\nexcept ValueError as e:\n    if 'even integers' in str(e):\n        render(src, width=w - w % 2, height=h - h % 2)","preventionTips":["Centralize dimension normalization: even-round every computed size","Snap to standard presets (1280x720, 1920x1080) when possible","Apply int() before even-rounding to remove float drift","Validate dimension configs at load time with the guard above"],"tags":["python","geometry","dimensions","video"],"backgroundTag":"value-out-of-range","analyzedSha":"8321021c54d670126ce3b2969d5deb880b4b0c2a","analyzedAt":"2026-09-16T10:08:13.343Z","contentChangedAt":"2026-09-16T10:08:13.343Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}