Kling 节点接入官方 4.0 / Flash(文生/图生/Omni)
This commit is contained in:
+224
-51
@@ -28,6 +28,14 @@ from comfy_api.latest import io
|
||||
from ..clients.kling_video_client import (
|
||||
build_kling_v4_body,
|
||||
endpoint_for as kling_v4_endpoint_for,
|
||||
extract_kling_v4_error_message,
|
||||
extract_kling_v4_status,
|
||||
extract_kling_v4_task_id,
|
||||
extract_kling_v4_video_url,
|
||||
is_kling_v4_failure_status,
|
||||
is_kling_v4_model,
|
||||
is_kling_v4_success_status,
|
||||
kling_v4_model_spec,
|
||||
)
|
||||
from ..utils.config import get_api_key_or_raise, get_base_url_by_route
|
||||
from ..utils.image_utils import tensor_to_pil
|
||||
@@ -110,9 +118,14 @@ _REFERENCE_VIDEO_MIN_RATIO = 1 / 2.5
|
||||
_REFERENCE_VIDEO_MAX_RATIO = 2.5
|
||||
_V4_REFERENCE_VIDEO_MAX_BYTES = 300 * 1024 * 1024
|
||||
_V4_REFERENCE_VIDEO_MIN_DURATION = 3.0
|
||||
_V4_REFERENCE_VIDEO_MAX_DURATION = 30.0
|
||||
_V4_REFERENCE_VIDEO_MIN_RATIO = 2 / 5
|
||||
_V4_REFERENCE_VIDEO_MAX_RATIO = 5 / 2
|
||||
_V4_REFERENCE_VIDEO_MIN_SIZE = 700
|
||||
_V4_REFERENCE_VIDEO_MAX_SIZE = 4553
|
||||
_V4_REFERENCE_VIDEO_MAX_PIXELS = 8294400
|
||||
_V4_REFERENCE_VIDEO_MIN_FPS = 24.0
|
||||
_V4_REFERENCE_VIDEO_MAX_FPS = 60.0
|
||||
_V4_IMAGE_MAX_BYTES = 30 * 1024 * 1024
|
||||
|
||||
|
||||
# ── 工具函数 ───────────────────────────────────────────────────────────────────
|
||||
@@ -133,13 +146,14 @@ def _extract_elements(text: str):
|
||||
return text, names
|
||||
|
||||
|
||||
def _prepare_image_for_upload(tensor):
|
||||
def _prepare_image_for_upload(tensor, max_bytes: int = 10 * 1024 * 1024):
|
||||
"""转换并校验图片,不符合约束时自动等比缩放后返回 PIL Image。"""
|
||||
import io as _io
|
||||
|
||||
pil_list = tensor_to_pil(tensor)
|
||||
img = pil_list[0].convert("RGB")
|
||||
w, h = img.size
|
||||
max_bytes = int(max_bytes)
|
||||
|
||||
# 1. 宽高比校验(无法通过等比缩放修复,直接报错)
|
||||
ratio = w / h
|
||||
@@ -153,8 +167,8 @@ def _prepare_image_for_upload(tensor):
|
||||
scale = max(300 / w, 300 / h)
|
||||
img = img.resize((int(w * scale), int(h * scale)), resample=1) # LANCZOS=1
|
||||
|
||||
# 3. 文件大小:循环等比缩小直到 ≤ 10MB
|
||||
MAX_BYTES = 10 * 1024 * 1024
|
||||
# 3. 文件大小:循环等比缩小直到不超过上限
|
||||
MAX_BYTES = max_bytes
|
||||
for _ in range(20): # 最多迭代 20 次,防止死循环
|
||||
buf = _io.BytesIO()
|
||||
img.save(buf, format="PNG")
|
||||
@@ -165,11 +179,13 @@ def _prepare_image_for_upload(tensor):
|
||||
new_h = int(img.height * scale)
|
||||
if new_w < 300 or new_h < 300:
|
||||
raise RuntimeError(
|
||||
f"图片压缩至 10MB 以内后尺寸({new_w}x{new_h})低于最小限制 300px,无法同时满足两项约束。"
|
||||
f"图片压缩至 {MAX_BYTES / 1024 / 1024:.0f}MB 以内后尺寸({new_w}x{new_h})低于最小限制 300px,无法同时满足两项约束。"
|
||||
)
|
||||
img = img.resize((new_w, new_h), resample=1)
|
||||
else:
|
||||
raise RuntimeError("图片经过 20 次缩放仍超过 10MB,请检查原始图片。")
|
||||
raise RuntimeError(
|
||||
f"图片经过 20 次缩放仍超过 {MAX_BYTES / 1024 / 1024:.0f}MB,请检查原始图片。"
|
||||
)
|
||||
|
||||
return img
|
||||
|
||||
@@ -437,27 +453,49 @@ def _validate_reference_video(video_path: str, model: str) -> None:
|
||||
)
|
||||
|
||||
|
||||
def _validate_kling_v4_reference_video(video_path: str) -> float:
|
||||
"""Validate one Kling 4.0 Omni reference clip and return its duration."""
|
||||
def _validate_kling_v4_reference_video(video_path: str, model: str = "v4") -> float:
|
||||
"""Validate one Kling 4.0 / Flash Omni reference clip and return its duration."""
|
||||
spec = kling_v4_model_spec(model)
|
||||
ext = os.path.splitext(video_path)[1].lower()
|
||||
if ext not in (".mp4", ".mov"):
|
||||
raise RuntimeError(f"Kling 4.0 参考视频仅支持 MP4/MOV,当前为 {ext or '无扩展名'}。")
|
||||
raise RuntimeError(f"{spec['display_name']} 参考视频仅支持 MP4/MOV,当前为 {ext or '无扩展名'}。")
|
||||
size = os.path.getsize(video_path)
|
||||
if size > _V4_REFERENCE_VIDEO_MAX_BYTES:
|
||||
raise RuntimeError(
|
||||
f"Kling 4.0 参考视频不能超过 300MB,当前为 {size / 1024 / 1024:.1f}MB。"
|
||||
f"{spec['display_name']} 参考视频不能超过 300MB,当前为 {size / 1024 / 1024:.1f}MB。"
|
||||
)
|
||||
meta = _probe_video_with_ffprobe(video_path) or _probe_video_with_cv2(video_path)
|
||||
if not meta or not meta.get("width") or not meta.get("height") or not meta.get("duration"):
|
||||
raise RuntimeError("无法读取 Kling 4.0 参考视频的尺寸和时长。")
|
||||
raise RuntimeError(f"无法读取 {spec['display_name']} 参考视频的尺寸和时长。")
|
||||
width = int(meta["width"])
|
||||
height = int(meta["height"])
|
||||
duration = float(meta["duration"])
|
||||
if not _V4_REFERENCE_VIDEO_MIN_DURATION <= duration <= _V4_REFERENCE_VIDEO_MAX_DURATION:
|
||||
fps = meta.get("fps")
|
||||
max_duration = float(spec["max_duration"])
|
||||
if not _V4_REFERENCE_VIDEO_MIN_DURATION <= duration <= max_duration:
|
||||
raise RuntimeError(
|
||||
f"Kling 4.0 单段参考视频时长需在 3~30 秒之间,当前为 {duration:.2f} 秒。"
|
||||
f"{spec['display_name']} 单段参考视频时长需在 3~{spec['max_duration']} 秒之间,当前为 {duration:.2f} 秒。"
|
||||
)
|
||||
ratio = float(meta["width"]) / float(meta["height"])
|
||||
if not (
|
||||
_V4_REFERENCE_VIDEO_MIN_SIZE <= width <= _V4_REFERENCE_VIDEO_MAX_SIZE
|
||||
and _V4_REFERENCE_VIDEO_MIN_SIZE <= height <= _V4_REFERENCE_VIDEO_MAX_SIZE
|
||||
):
|
||||
raise RuntimeError(
|
||||
f"{spec['display_name']} 参考视频宽高需在 700~4553px 之间,当前为 {width}x{height}。"
|
||||
)
|
||||
if width * height > _V4_REFERENCE_VIDEO_MAX_PIXELS:
|
||||
raise RuntimeError(
|
||||
f"{spec['display_name']} 参考视频总像素不能超过 8,294,400,当前为 {width * height}。"
|
||||
)
|
||||
if not fps:
|
||||
raise RuntimeError(f"无法读取 {spec['display_name']} 参考视频的帧率。")
|
||||
if not _V4_REFERENCE_VIDEO_MIN_FPS <= float(fps) <= _V4_REFERENCE_VIDEO_MAX_FPS:
|
||||
raise RuntimeError(
|
||||
f"{spec['display_name']} 参考视频帧率需在 24~60fps 之间,当前为 {float(fps):.2f}fps。"
|
||||
)
|
||||
ratio = width / height
|
||||
if not _V4_REFERENCE_VIDEO_MIN_RATIO <= ratio <= _V4_REFERENCE_VIDEO_MAX_RATIO:
|
||||
raise RuntimeError("Kling 4.0 参考视频宽高比需在 2:5~5:2 之间。")
|
||||
raise RuntimeError(f"{spec['display_name']} 参考视频宽高比需在 2:5~5:2 之间。")
|
||||
return duration
|
||||
|
||||
|
||||
@@ -610,6 +648,95 @@ async def _run_video_task(base_url: str, headers: dict, body: dict,
|
||||
return save_path
|
||||
|
||||
|
||||
|
||||
async def _run_kling_v4_task(base_url: str, headers: dict, body: dict,
|
||||
create_path: str, status_path: str, prefix: str):
|
||||
"""Submit, poll, and download using the official Kling 4.0 / Flash envelope."""
|
||||
try:
|
||||
from comfy.utils import ProgressBar
|
||||
pbar = ProgressBar(100)
|
||||
except Exception:
|
||||
pbar = None
|
||||
|
||||
def _stage(s: str):
|
||||
if s == "submitting":
|
||||
print("[Kling 4.0] 提交中...")
|
||||
if pbar: pbar.update_absolute(0, 100)
|
||||
elif s.startswith("submitted:"):
|
||||
print(f"[Kling 4.0] 任务已提交 → {s.split(':', 1)[1]}")
|
||||
if pbar: pbar.update_absolute(5, 100)
|
||||
elif s == "downloading":
|
||||
print("[Kling 4.0] 下载视频...")
|
||||
if pbar: pbar.update_absolute(99, 100)
|
||||
elif s == "done":
|
||||
print("[Kling 4.0] 完成")
|
||||
if pbar: pbar.update_absolute(100, 100)
|
||||
|
||||
def _progress(pct: int):
|
||||
if pbar: pbar.update_absolute(5 + int(pct * 0.94), 100)
|
||||
|
||||
tmp_fd, save_path = tempfile.mkstemp(suffix=".mp4", prefix="k3_")
|
||||
|
||||
connector = aiohttp.TCPConnector(ssl=False, force_close=True)
|
||||
async with aiohttp.ClientSession(connector=connector) as session:
|
||||
check_interrupt()
|
||||
_stage("submitting")
|
||||
create_url = f"{base_url}{create_path}"
|
||||
resp = await run_with_interrupt(async_request_with_retry(
|
||||
session, "POST", create_url, json=body, headers=headers, prefix=prefix
|
||||
))
|
||||
check_interrupt()
|
||||
create_resp = json.loads(await resp.text())
|
||||
if create_resp.get("code") not in (None, 0, "0"):
|
||||
raise RuntimeError(f"Kling 4.0 提交失败:{extract_kling_v4_error_message(create_resp)}")
|
||||
task_id = extract_kling_v4_task_id(create_resp)
|
||||
if not task_id:
|
||||
raise RuntimeError(f"API 未返回任务 ID,响应:{create_resp}")
|
||||
_stage(f"submitted:{task_id}")
|
||||
|
||||
status_url = f"{base_url}{status_path.format(task_id=task_id)}"
|
||||
interval = _POLL_INIT
|
||||
deadline = PollDeadline(label="Kling 4.0")
|
||||
video_url = None
|
||||
while True:
|
||||
deadline.check()
|
||||
check_interrupt()
|
||||
async with session.get(status_url, headers=headers) as resp:
|
||||
text_body = await resp.text()
|
||||
if resp.status != 200:
|
||||
try:
|
||||
err = json.loads(text_body)
|
||||
msg = extract_kling_v4_error_message(err, default=text_body)
|
||||
except Exception:
|
||||
msg = text_body
|
||||
raise RuntimeError(f"状态查询失败 ({resp.status}): {msg}")
|
||||
sr = json.loads(text_body)
|
||||
|
||||
status = extract_kling_v4_status(sr)
|
||||
print(f"[Kling 4.0] 生成中 status={status or 'unknown'}")
|
||||
_progress(50 if status == "processing" else 10)
|
||||
|
||||
if is_kling_v4_success_status(status):
|
||||
video_url = extract_kling_v4_video_url(sr)
|
||||
break
|
||||
if is_kling_v4_failure_status(status, sr):
|
||||
raise RuntimeError(f"Kling 4.0 生成失败:{extract_kling_v4_error_message(sr)}")
|
||||
|
||||
await interruptible_sleep(interval)
|
||||
interval = min(interval * 1.5, _POLL_MAX)
|
||||
|
||||
if not video_url:
|
||||
raise RuntimeError(f"API 未返回视频 URL,响应:{sr}")
|
||||
|
||||
check_interrupt()
|
||||
_stage("downloading")
|
||||
os.close(tmp_fd)
|
||||
await download_video_to_file(session, video_url, save_path, label="Kling 4.0")
|
||||
|
||||
_stage("done")
|
||||
return save_path
|
||||
|
||||
|
||||
# ── 模型 DynamicCombo 选项构建 ────────────────────────────────────────────────
|
||||
|
||||
def _v3_omni_subs():
|
||||
@@ -638,38 +765,70 @@ def _v3_omni_subs():
|
||||
]
|
||||
|
||||
|
||||
def _v4_subs():
|
||||
"""Kling 4.0 generation mode and its capability-limited parameters."""
|
||||
def _v4_common_subs(*, max_duration: int, resolutions: list[str], default_resolution: str, tooltip_prefix: str):
|
||||
"""Shared Kling 4.0 / Flash generation-mode parameters."""
|
||||
return [
|
||||
io.Combo.Input(
|
||||
"生成模式",
|
||||
options=["文生视频", "关键帧", "全能参考"],
|
||||
default="文生视频",
|
||||
tooltip="文生视频:只使用提示词;关键帧:首帧可加中间帧和尾帧;全能参考:使用参考图或参考视频。",
|
||||
tooltip="文生视频:只使用提示词;关键帧:至少一张关键帧,可加中间帧和尾帧;全能参考:使用参考图或参考视频。",
|
||||
),
|
||||
io.Int.Input(
|
||||
"时长",
|
||||
default=5,
|
||||
default=10,
|
||||
min=3,
|
||||
max=30,
|
||||
max=max_duration,
|
||||
display_mode=io.NumberDisplay.slider,
|
||||
tooltip="Kling 4.0 支持 3~30 秒。",
|
||||
tooltip=f"{tooltip_prefix} 支持 3~{max_duration} 秒。",
|
||||
),
|
||||
io.Combo.Input(
|
||||
"模式",
|
||||
options=["720p", "1080p"],
|
||||
default="720p",
|
||||
tooltip="Kling 4.0 支持 720p 和 1080p。",
|
||||
options=resolutions,
|
||||
default=default_resolution,
|
||||
tooltip=f"{tooltip_prefix} 支持 {' / '.join(resolutions)},默认 {default_resolution}。",
|
||||
),
|
||||
io.Combo.Input(
|
||||
"宽高比",
|
||||
options=["智能", "16:9", "9:16", "1:1", "21:9"],
|
||||
default="智能",
|
||||
tooltip="关键帧模式跟随首帧比例;文生和全能参考支持智能、16:9、9:16、1:1、21:9。",
|
||||
tooltip="文生视频默认 16:9(智能按 16:9 提交);全能参考默认 adaptive;图生视频不传宽高比。",
|
||||
),
|
||||
io.Combo.Input(
|
||||
"视频参考类型",
|
||||
options=["特征参考", "待编辑视频"],
|
||||
default="特征参考",
|
||||
tooltip="仅全能参考:特征参考对应 feature_video;待编辑视频把第一段参考视频作为 base_video。",
|
||||
),
|
||||
io.Combo.Input(
|
||||
"音频",
|
||||
options=["原生音频", "保留原声"],
|
||||
default="原生音频",
|
||||
tooltip="仅全能参考:原生音频按画面生成声音;保留原声需提供 base_video 或 feature_video。",
|
||||
),
|
||||
]
|
||||
|
||||
|
||||
def _v4_subs():
|
||||
"""Kling 4.0 generation mode and its capability-limited parameters."""
|
||||
return _v4_common_subs(
|
||||
max_duration=30,
|
||||
resolutions=["720p", "1080p"],
|
||||
default_resolution="1080p",
|
||||
tooltip_prefix="Kling 4.0",
|
||||
)
|
||||
|
||||
|
||||
def _v4_flash_subs():
|
||||
"""Kling 4.0 Flash parameters: 720p only, 3-20 seconds."""
|
||||
return _v4_common_subs(
|
||||
max_duration=20,
|
||||
resolutions=["720p"],
|
||||
default_resolution="720p",
|
||||
tooltip_prefix="Kling 4.0 Flash",
|
||||
)
|
||||
|
||||
|
||||
def _build_model_input():
|
||||
"""构建「模型」DynamicCombo,把「时长」「模式」作为随模型变化的子输入。
|
||||
|
||||
@@ -677,6 +836,7 @@ def _build_model_input():
|
||||
- v3:时长 3~15s;模式 720p/1080p/4K
|
||||
- v2-6:时长 5/10s;模式 720p/1080p(无 4K)
|
||||
- v3-omni:时长 3~15s;模式 720p/1080p/4K;支持多模态参考
|
||||
- v4 / v4-flash:文生、关键帧、全能参考;4.0 为 3~30s、默认 1080p,Flash 为 3~20s、仅 720p
|
||||
"""
|
||||
def _v3_subs():
|
||||
return [
|
||||
@@ -702,11 +862,13 @@ def _build_model_input():
|
||||
io.DynamicCombo.Option("v3-omni", _v3_omni_subs()),
|
||||
io.DynamicCombo.Option("v2-6", _v26_subs()),
|
||||
io.DynamicCombo.Option("v3", _v3_subs()),
|
||||
# Append the new branch so existing DynamicCombo option order and
|
||||
# saved v3/v2.6 workflows remain unchanged.
|
||||
# Append the new branches so existing DynamicCombo option order and
|
||||
# saved v3/v2.6 workflows remain unchanged. "v4" is the stored
|
||||
# value for Kling 4.0; the frontend shows a Chinese display name.
|
||||
io.DynamicCombo.Option("v4", _v4_subs()),
|
||||
io.DynamicCombo.Option("v4-flash", _v4_flash_subs()),
|
||||
],
|
||||
tooltip="v2-6: 5/10s; v3: 3-15s; v3-omni: 多模态参考、视频编辑、主体管理;v4: 文生、关键帧、全能参考,3-30s。",
|
||||
tooltip="v2-6: 5/10s; v3: 3-15s; v3-omni: 多模态参考、视频编辑、主体管理;Kling 4.0: 文生、关键帧、全能参考,3-30s,默认 1080p;Kling 4.0 Flash: 同路径结构,3-20s,仅 720p。",
|
||||
)
|
||||
|
||||
|
||||
@@ -778,22 +940,22 @@ class K3Video(io.ComfyNode):
|
||||
# positional widgets in existing K3Video workflows do not move.
|
||||
*[
|
||||
io.Image.Input(f"中间帧{i}", optional=True,
|
||||
tooltip="Kling 4.0 关键帧模式使用;按连接顺序插入首帧与尾帧之间。")
|
||||
tooltip="Kling 4.0 / Flash 关键帧模式使用;按连接顺序插入首帧与尾帧之间。")
|
||||
for i in range(1, 9)
|
||||
],
|
||||
*[
|
||||
io.Image.Input(f"参考图{i}", optional=True,
|
||||
tooltip="Kling 4.0 全能参考模式使用;最多 10 张参考图。")
|
||||
tooltip="Kling 4.0 / Flash 全能参考模式使用;最多 10 张参考图。")
|
||||
for i in range(6, 11)
|
||||
],
|
||||
io.Image.Input(
|
||||
"参考图1",
|
||||
optional=True,
|
||||
tooltip="Kling 4.0 全能参考模式使用;最多 10 张参考图。",
|
||||
tooltip="Kling 4.0 / Flash 全能参考模式使用;最多 10 张参考图。",
|
||||
),
|
||||
*[
|
||||
io.Video.Input(f"参考视频{i}", optional=True,
|
||||
tooltip="Kling 4.0 全能参考模式使用;最多 5 段参考视频。")
|
||||
tooltip="Kling 4.0 / Flash 全能参考模式使用;最多 5 段参考视频。")
|
||||
for i in range(2, 6)
|
||||
],
|
||||
],
|
||||
@@ -820,7 +982,7 @@ class K3Video(io.ComfyNode):
|
||||
"Content-Type": "application/json",
|
||||
}
|
||||
shots = _collect_shots(分镜模式, 时长)
|
||||
if 模型代号 == "v4":
|
||||
if is_kling_v4_model(模型代号):
|
||||
generation_mode = 模型.get("生成模式", "文生视频")
|
||||
middle_frames = [
|
||||
_kwargs.get(f"中间帧{i}")
|
||||
@@ -859,6 +1021,9 @@ class K3Video(io.ComfyNode):
|
||||
reference_images,
|
||||
reference_videos,
|
||||
shots,
|
||||
模型代号,
|
||||
模型.get("视频参考类型", "特征参考"),
|
||||
模型.get("音频", "原生音频"),
|
||||
)
|
||||
if _FOLDER_PATHS_OK:
|
||||
return io.NodeOutput(InputImpl.VideoFromFile(save_path))
|
||||
@@ -1178,24 +1343,34 @@ class K3Video(io.ComfyNode):
|
||||
reference_image_inputs,
|
||||
reference_video_inputs,
|
||||
shots,
|
||||
model="v4",
|
||||
video_reference_type="特征参考",
|
||||
audio="原生音频",
|
||||
):
|
||||
"""Build and run one Kling 4.0 text/keyframe/Omni task."""
|
||||
"""Build and run one official Kling 4.0 / Flash text, keyframe, or Omni task."""
|
||||
from ..utils.r2_uploader import upload_video
|
||||
|
||||
spec = kling_v4_model_spec(model)
|
||||
|
||||
async def upload_frame(image, label):
|
||||
if image is None:
|
||||
return None
|
||||
print(f"[Kling 4.0] uploading {label}...")
|
||||
return await upload_image(_prepare_image_for_upload(image), base_url=base_url)
|
||||
print(f"[{spec['display_name']}] uploading {label}...")
|
||||
return await upload_image(
|
||||
_prepare_image_for_upload(image, max_bytes=_V4_IMAGE_MAX_BYTES),
|
||||
base_url=base_url,
|
||||
)
|
||||
|
||||
validated_video_paths = []
|
||||
reference_video_seconds = 0.0
|
||||
for video in reference_video_inputs:
|
||||
video_path = _resolve_reference_video_path(video)
|
||||
reference_video_seconds += _validate_kling_v4_reference_video(video_path)
|
||||
reference_video_seconds += _validate_kling_v4_reference_video(video_path, model)
|
||||
validated_video_paths.append(video_path)
|
||||
if reference_video_seconds > _V4_REFERENCE_VIDEO_MAX_DURATION:
|
||||
raise RuntimeError("Kling 4.0 参考视频总时长不能超过 30 秒。")
|
||||
if reference_video_seconds > spec["max_duration"]:
|
||||
raise RuntimeError(
|
||||
f"{spec['display_name']} 参考视频总时长不能超过 {spec['max_duration']} 秒。"
|
||||
)
|
||||
|
||||
first_url = await upload_frame(first_frame, "first frame")
|
||||
middle_urls = [
|
||||
@@ -1210,12 +1385,16 @@ class K3Video(io.ComfyNode):
|
||||
]
|
||||
reference_video_urls = []
|
||||
for index, video_path in enumerate(validated_video_paths, start=1):
|
||||
print(f"[Kling 4.0] uploading reference video {index}...")
|
||||
print(f"[{spec['display_name']}] uploading reference video {index}...")
|
||||
reference_video_urls.append(await upload_video(video_path, base_url=base_url))
|
||||
|
||||
if shots:
|
||||
prompt = "\n".join(str(shot["prompt"]).strip() for shot in shots if shot.get("prompt"))
|
||||
|
||||
body = build_kling_v4_body(
|
||||
generation_mode=generation_mode,
|
||||
prompt=prompt,
|
||||
model=model,
|
||||
negative_prompt=negative_prompt,
|
||||
duration=duration,
|
||||
resolution=resolution,
|
||||
@@ -1225,26 +1404,20 @@ class K3Video(io.ComfyNode):
|
||||
last_frame=last_url,
|
||||
reference_images=reference_image_urls,
|
||||
reference_videos=reference_video_urls,
|
||||
video_reference_type=video_reference_type,
|
||||
audio=audio,
|
||||
)
|
||||
if shots:
|
||||
body["multi_shot"] = True
|
||||
body["shot_type"] = "customize"
|
||||
body["multi_prompt"] = [
|
||||
{"index": shot["index"], "prompt": shot["prompt"], "duration": shot["duration"]}
|
||||
for shot in shots
|
||||
]
|
||||
|
||||
create_path, status_path = kling_v4_endpoint_for(generation_mode)
|
||||
return await _run_video_task(
|
||||
create_path, status_path = kling_v4_endpoint_for(generation_mode, model)
|
||||
return await _run_kling_v4_task(
|
||||
base_url,
|
||||
headers,
|
||||
body,
|
||||
create_path,
|
||||
status_path,
|
||||
f"Kling 4.0 {generation_mode} submit: ",
|
||||
f"{spec['display_name']} {generation_mode} submit: ",
|
||||
)
|
||||
|
||||
@classmethod
|
||||
async def _build_standard(cls, 模型, base_url, headers, 起始帧, 提示词, 负向提示词, 时长, 生成音频, 模式, shots, 尾帧=None):
|
||||
"""标准图生视频接口:POST /kling/v1/videos/image2video
|
||||
|
||||
|
||||
Reference in New Issue
Block a user