{"record":{"id":"dca7dab2bcaeb247","repo":"Comfy-Org/ComfyUI","slug":"h-264-output-requires-even-dimensions-got-out-wi","errorCode":null,"errorMessage":"H.264 output requires even dimensions, got {out_width}x{out_height}","messagePattern":"H\\.264 output requires even dimensions, got (.+?)x(.+?)","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"comfy_api/latest/_input_impl/video_types.py","lineNumber":658,"sourceCode":"                            video_done = True\n                            if last_video_pts is not None:\n                                # the source continues past the window: hold the last kept frame to the window end\n                                end_offset = video_pts_offset if video_pts_offset is not None else start_pts\n                                last_video_end = max(last_video_end, end_pts - end_offset)\n                            break\n                        # the source's true display duration of this frame; average_rate is not a\n                        # frame duration (sparse/VFR sources), so it is only the fallback\n                        frame_duration = frame.duration if frame.duration else pts_step\n                        if end_pts is not None and frame.pts is not None:\n                            frame_duration = min(frame_duration, end_pts - frame.pts)\n                        if output is None:\n                            rotation_k = int(round(frame.rotation // 90)) % 4 if frame.rotation else 0\n                            if rotation_k % 2:\n                                out_width, out_height = frame.height, frame.width\n                            else:\n                                out_width, out_height = frame.width, frame.height\n                            if out_width % 2 or out_height % 2:\n                                raise ValueError(f\"H.264 output requires even dimensions, got {out_width}x{out_height}\")\n                            source_size = (frame.width, frame.height)\n                            output = av.open(path, **open_kwargs)\n                            # Add metadata before writing any streams\n                            write_output_metadata(container, output, metadata)\n                            out_video = output.add_stream(\"h264\", rate=rate)\n                            # no B-frames: reordering makes mp4 sample durations follow decode order,\n                            # so irregular-VFR spans and trim windows land wrong\n                            out_video.codec_context.max_b_frames = 0\n                            out_video.width = out_width\n                            out_video.height = out_height\n                            out_video.pix_fmt = pix_fmt\n                            if crf is not None:\n                                out_video.options = {\"crf\": str(crf)}\n                            # source pts pass through (rebased to 0), so variable frame rate survives\n                            out_video.codec_context.time_base = video_stream.time_base\n                            if audio_stream is not None:\n                                out_audio = output.add_stream(\"aac\", rate=sample_rate, layout=layout)\n                        if (frame.width, frame.height) != source_size:","sourceCodeStart":640,"sourceCodeEnd":676,"githubUrl":"https://github.com/Comfy-Org/ComfyUI/blob/1c6d8d45b3693bfbb32385b410d813a7fd6be216/comfy_api/latest/_input_impl/video_types.py#L640-L676","documentation":"The H.264 encoder (libx264) requires even width and height because of 4:2:0 chroma subsampling. Before opening the output, the transcode path takes the first frame's dimensions (swapped if the stream carries 90/270-degree rotation metadata) and raises if either dimension is odd, rather than letting libx264 fail obscurely or silently cropping.","triggerScenarios":"Transcoding a video whose first frame has an odd width or height (e.g. 1081x1920, 641x480) — including cases where a rotation flag swaps an odd dimension into the other axis.","commonSituations":"Odd-resolution phone screen recordings; AI-generated videos with non-multiple-of-2 sizes; crops from other tools that land on odd boundaries.","solutions":["Pre-crop/pad the source to even dimensions before loading (ffmpeg -vf crop=even dims or pad)","Add a scale filter to even sizes: scale=trunc(iw/2)*2:trunc(ih/2)*2 in an external pass","If the input is generated in ComfyUI, produce latent/image sizes divisible by 2 before saving"],"exampleFix":"// before\nvideo_input.save_transcoded('out.mp4')  # source is 1081x1920\n\n# after\n# pre-process: ffmpeg -i in.mp4 -vf \"crop=1080:1920:0:0\" even.mp4\nVideoFromFile('even.mp4').save_transcoded('out.mp4')","handlingStrategy":"validation","validationCode":"w, h = video_input.get_size()\nif w % 2 or h % 2:\n    raise ValueError(f'crop/pad {w}x{h} to even dimensions before H.264 output')","typeGuard":"def has_even_dims(size) -> bool:\n    return size[0] % 2 == 0 and size[1] % 2 == 0","tryCatchPattern":null,"preventionTips":["Normalize inputs to even dimensions upstream (crop=trunc(iw/2)*2:trunc(ih/2)*2)","Generate content at even resolutions when it will be H.264 encoded"],"tags":["video","h264","odd-dimensions","transcode"],"backgroundTag":null,"analyzedSha":"1c6d8d45b3693bfbb32385b410d813a7fd6be216","analyzedAt":"2026-08-14T19:37:18.893Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}