ATH-MaaS/Pixelle-Video · error · FileNotFoundError

输入图片不存在: {image_path}

Error message

输入图片不存在: {image_path}

What it means

KlingVideoClient._submit_task validates the image_path argument before building the image2video request. If a path was supplied but the file does not exist on disk, it raises FileNotFoundError immediately, before any network call.

Source

Thrown at pixelle_video/services/api_services/video_kling.py:182

    ) -> str:
        """提交文生视频或图生视频任务。

        Args:
            image_path: 本地图片路径;为空时调用文生视频接口
            prompt: 正向提示词(≤2500字符)
            negative_prompt: 负向提示词(≤2500字符)
            model_name: 可灵模型名 (kling-v3 / kling-v2-6 / kling-v2-5-turbo)
            mode: 生成模式 std (标准) / pro (高品质)
            duration: 视频时长,v3: "3"~"15", v2: "5"或"10"
            cfg_scale: 自由度 [0,1],越大越贴合提示词
            sound: 是否生成声音 "on"/"off"
            aspect_ratio: 文生视频画幅比例

        Returns:
            task_id: 任务 ID
        """
        if image_path and not os.path.exists(image_path):
            raise FileNotFoundError(f"输入图片不存在: {image_path}")

        # 根据模型系列确定 duration 范围
        model_lower = model_name.lower()
        is_v3 = "v3" in model_lower or "video-o1" in model_lower
        is_v26 = any(tag in model_lower for tag in ("v2-6", "v2.6"))

        if is_v3:
            # v3 系列支持 3~15s
            clamped = str(min(max(int(duration), 3), 15))
        else:
            # v2 系列仅支持 5 或 10
            clamped = "10" if int(duration) >= 8 else "5"

        body = {
            "model_name": model_name,
            "mode": mode,
            "duration": clamped,
        }

View on GitHub (pinned to 848b054e4f)

Solutions

  1. Print os.path.abspath(image_path) and verify that exact file exists before calling generate_video.
  2. Fix the CWD mismatch: use absolute paths or os.path.join(BASE_DIR, ...) when constructing image_path.
  3. Confirm the image download/previous pipeline step actually succeeded and the file was not deleted by a cleanup job.
  4. If you intend text-to-video, pass image_path=None instead of a bogus path so the client uses the text2video endpoint.

Example fix

# before
client.generate_video(image_path="assets/input.jpg", prompt="...")  # FileNotFoundError
# after
import os
img = os.path.abspath("assets/input.jpg")
assert os.path.exists(img), f"missing image: {img}"
client.generate_video(image_path=img, prompt="...")
Defensive patterns

Strategy: validation

Validate before calling

import os
image_path = os.path.abspath(image_path)
if image_path and not os.path.isfile(image_path):
    raise FileNotFoundError(f"输入图片不存在: {image_path}")  # 提交前自行校验

Type guard

def image_exists(path: str | None) -> bool:
    return bool(path) and os.path.isfile(os.path.expanduser(path))

Try / catch

try:
    url = client.generate_video(image_path=img, ...)
except FileNotFoundError as e:
    logger.warning(f"图片缺失,回退为文生视频: {e}")
    url = client.generate_video(image_path=None, prompt=prompt, ...)

Prevention

When it happens

Trigger: generate_video -> _submit_task called with a non-None image_path where os.path.exists(image_path) is False (video_kling.py:181-182) — e.g. a relative path resolved from the wrong working directory, a deleted temp file, or a typo in the filename/extension.

Common situations: Passing a relative path while the process CWD differs from the script directory, using a path downloaded earlier but cleaned up, Windows vs POSIX path separators embedded in config, or building the path with an uninitialized variable ('None' string, empty upload).

Understand the failure class

Background: "File not found" and ENOENT errors: why libraries can't find a file that should exist — this error's family across 50 libraries.

Related errors


AI-assisted analysis of ATH-MaaS/Pixelle-Video@848b054e4f (2026-08-30). Data as JSON: /api/errors/e98a6070c7dce757. Report an issue: GitHub.