From 4d824d3a1ddfafea8ac6fdbe29474ba31501e8ed Mon Sep 17 00:00:00 2001 From: Steve Tietze Date: Tue, 23 Dec 2025 18:34:46 +0700 Subject: [PATCH] fix: return real ComfyUI VIDEO object for Kling 2.6 --- kie_api/seedancev1pro_fast_i2v.py | 2 +- kie_api/video.py | 38 ++++++++++--------------------- 2 files changed, 13 insertions(+), 27 deletions(-) diff --git a/kie_api/seedancev1pro_fast_i2v.py b/kie_api/seedancev1pro_fast_i2v.py index 8fd6b7b..071169d 100644 --- a/kie_api/seedancev1pro_fast_i2v.py +++ b/kie_api/seedancev1pro_fast_i2v.py @@ -129,7 +129,7 @@ def run_seedancev1pro_fast_i2v_video( _log(log, f"Downloading video result from {video_url}...") video_bytes = _download_video(video_url) - video_path = _write_video_to_temp_mp4(video_bytes) + video_path = _write_video_to_temp_file(video_bytes) _log(log, f"Video saved to {video_path}") _log_remaining_credits(log, record_data, api_key, _log) diff --git a/kie_api/video.py b/kie_api/video.py index 4d9d17e..4392c21 100644 --- a/kie_api/video.py +++ b/kie_api/video.py @@ -1,8 +1,7 @@ -"""Video helpers shared across KIE models.""" +# kie_api/video.py from io import BytesIO -from pathlib import Path -from tempfile import NamedTemporaryFile +from typing import Any from .http import requests @@ -15,32 +14,19 @@ def _download_video(url: str) -> bytes: raise RuntimeError(f"Failed to download result video: {exc}") from exc if response.status_code != 200: - raise RuntimeError(f"Failed to download result video (status code {response.status_code}).") + raise RuntimeError( + f"Failed to download result video (status code {response.status_code})." + ) return response.content -def _write_video_to_temp_file(video_bytes: bytes, suffix: str = ".mp4") -> str: - """Persist video bytes to a temporary file and return its path.""" - try: - temp_file = NamedTemporaryFile(delete=False, suffix=suffix) - with temp_file: - temp_file.write(video_bytes) - return str(Path(temp_file.name)) - except OSError as exc: - raise RuntimeError("Failed to write temporary video file.") from exc - - def _video_bytes_to_comfy_video(video_bytes: bytes): - """Convert raw video bytes into a ComfyUI VIDEO object.""" - try: - from comfy_api.latest.input_impl.video_types import VideoFromFile - except ImportError as exc: - raise RuntimeError( - "comfy_api video helpers are unavailable. Update ComfyUI to a version that " - "ships comfy_api.latest.input_impl.video_types." - ) from exc + """ + Convert raw MP4 bytes into a ComfyUI VIDEO object. + This is what SaveVideo expects. + """ + # Import inside function to avoid Comfy startup import issues + from comfy_api.latest.input_impl.video_types import VideoFromFile - buffer = BytesIO(video_bytes) - buffer.name = "kie_temp_video.mp4" - return VideoFromFile(buffer) + return VideoFromFile(BytesIO(video_bytes))