Comfy-Org/ComfyUI · error · ValueError

Could not convert the input video to {container.value.upper(

Error message

Could not convert the input video to {container.value.upper()} for upload; the file may be corrupted or use an unsupported codec. Try re-exporting it as MP4 (H.264). Original error: {e}

What it means

upload_video_to_comfyapi re-encodes the input via video.save_to(BytesIO, format=container, codec=codec) before uploading. Any exception from that PyAV encode is wrapped as ValueError advising the file may be corrupted or use an unsupported codec, with the original error appended.

Source

Thrown at comfy_api_nodes/util/upload_helpers.py:164

        try:
            actual_duration = video.get_duration()
            if actual_duration > max_duration:
                raise ValueError(
                    f"Video duration ({actual_duration:.2f}s) exceeds the maximum allowed ({max_duration}s)."
                )
        except Exception as e:
            logging.error("Error getting video duration: %s", str(e))
            raise ValueError(f"Could not verify video duration from source: {e}") from e

    upload_mime_type = f"video/{container.value.lower()}"
    filename = f"{uuid.uuid4()}.{container.value.lower()}"

    # Convert VideoInput to BytesIO using specified container/codec
    video_bytes_io = BytesIO()
    try:
        video.save_to(video_bytes_io, format=container, codec=codec)
    except Exception as e:
        raise ValueError(
            f"Could not convert the input video to {container.value.upper()} for upload; "
            f"the file may be corrupted or use an unsupported codec. "
            f"Try re-exporting it as MP4 (H.264). Original error: {e}"
        ) from e
    video_bytes_io.seek(0)

    return await upload_file_to_comfyapi(cls, video_bytes_io, filename, upload_mime_type, wait_label)


_3D_MIME_TYPES = {
    "glb": "model/gltf-binary",
    "obj": "model/obj",
    "fbx": "application/octet-stream",
}


async def upload_3d_model_to_comfyapi(
    cls: type[IO.ComfyNode],

View on GitHub (pinned to 1c6d8d45b3)

Solutions

  1. Read the 'Original error:' suffix — it names the exact PyAV failure.
  2. Re-export the source as MP4 with H.264 and yuv420p: ffmpeg -i in.mov -c:v libx264 -pix_fmt yuv420p -c:a aac out.mp4.
  3. Ensure container and codec arguments are compatible (mp4+h264, webm+vp9).
  4. Upgrade the PyAV/av package if the codec is supported by newer FFmpeg builds.

Example fix

// before
url = await upload_video_to_comfyapi(cls, video, container=Types.VideoContainer.WEBM, codec=Types.VideoCodec.H264)  # codec not allowed in webm

// after
url = await upload_video_to_comfyapi(cls, video, container=Types.VideoContainer.MP4, codec=Types.VideoCodec.H264)
Defensive patterns

Strategy: try-catch

Validate before calling

import av

with av.open(path) as c:
    v = c.streams.video[0]
    if v.codec.name not in ('h264', 'vp9'):
        raise ValueError(f'Pre-convert source codec {v.codec.name} to H.264 first')

Try / catch

try:
    url = await upload_video_to_comfyapi(cls, video, container=Types.VideoContainer.MP4, codec=Types.VideoCodec.H264)
except ValueError as e:
    if 'Could not convert the input video' in str(e):
        # re-encode externally and retry
        raise
    raise

Prevention

When it happens

Trigger: save_to failing: source undecodable (corrupt file, wrong extension), a codec the local PyAV/FFmpeg build cannot decode (e.g. HEVC 10-bit, VP9 without support), or the target encode parameters invalid for the stream (odd dimensions, unusual pixel format).

Common situations: Downloading a partial file and uploading it; HEVC/ProRes/AV1 sources on FFmpeg builds without those decoders; videos from phones with HDR metadata; codec enum mismatch between container and codec (e.g. WEBM container with H264 codec).

Related errors


AI-assisted analysis of Comfy-Org/ComfyUI@1c6d8d45b3 (2026-08-14). Data as JSON: /api/errors/c90e4124815a8fc4. Report an issue: GitHub.