mirror of
https://github.com/comfyanonymous/ComfyUI.git
synced 2026-04-12 03:22:37 +08:00
api nodes: added 4K resolution for Veo models; added Veo 3 Lite model
Signed-off-by: bigcat88 <bigcat88@icloud.com>
This commit is contained in:
parent
b615af1c65
commit
3df99f24f2
@ -24,8 +24,9 @@ from comfy_api_nodes.util import (
|
|||||||
AVERAGE_DURATION_VIDEO_GEN = 32
|
AVERAGE_DURATION_VIDEO_GEN = 32
|
||||||
MODELS_MAP = {
|
MODELS_MAP = {
|
||||||
"veo-2.0-generate-001": "veo-2.0-generate-001",
|
"veo-2.0-generate-001": "veo-2.0-generate-001",
|
||||||
"veo-3.1-generate": "veo-3.1-generate-preview",
|
"veo-3.1-generate": "veo-3.1-generate-001",
|
||||||
"veo-3.1-fast-generate": "veo-3.1-fast-generate-preview",
|
"veo-3.1-fast-generate": "veo-3.1-fast-generate-001",
|
||||||
|
"veo-3.1-lite": "veo-3.1-lite-generate-001",
|
||||||
"veo-3.0-generate-001": "veo-3.0-generate-001",
|
"veo-3.0-generate-001": "veo-3.0-generate-001",
|
||||||
"veo-3.0-fast-generate-001": "veo-3.0-fast-generate-001",
|
"veo-3.0-fast-generate-001": "veo-3.0-fast-generate-001",
|
||||||
}
|
}
|
||||||
@ -247,17 +248,8 @@ class VeoVideoGenerationNode(IO.ComfyNode):
|
|||||||
raise Exception("Video generation completed but no video was returned")
|
raise Exception("Video generation completed but no video was returned")
|
||||||
|
|
||||||
|
|
||||||
class Veo3VideoGenerationNode(VeoVideoGenerationNode):
|
class Veo3VideoGenerationNode(IO.ComfyNode):
|
||||||
"""
|
"""Generates videos from text prompts using Google's Veo 3 API."""
|
||||||
Generates videos from text prompts using Google's Veo 3 API.
|
|
||||||
|
|
||||||
Supported models:
|
|
||||||
- veo-3.0-generate-001
|
|
||||||
- veo-3.0-fast-generate-001
|
|
||||||
|
|
||||||
This node extends the base Veo node with Veo 3 specific features including
|
|
||||||
audio generation and fixed 8-second duration.
|
|
||||||
"""
|
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def define_schema(cls):
|
def define_schema(cls):
|
||||||
@ -279,6 +271,12 @@ class Veo3VideoGenerationNode(VeoVideoGenerationNode):
|
|||||||
default="16:9",
|
default="16:9",
|
||||||
tooltip="Aspect ratio of the output video",
|
tooltip="Aspect ratio of the output video",
|
||||||
),
|
),
|
||||||
|
IO.Combo.Input(
|
||||||
|
"resolution",
|
||||||
|
options=["720p", "1080p", "4k"],
|
||||||
|
default="720p",
|
||||||
|
tooltip="Output video resolution. 4K is not available for veo-3.1-lite and veo-3.0 models.",
|
||||||
|
),
|
||||||
IO.String.Input(
|
IO.String.Input(
|
||||||
"negative_prompt",
|
"negative_prompt",
|
||||||
multiline=True,
|
multiline=True,
|
||||||
@ -289,11 +287,11 @@ class Veo3VideoGenerationNode(VeoVideoGenerationNode):
|
|||||||
IO.Int.Input(
|
IO.Int.Input(
|
||||||
"duration_seconds",
|
"duration_seconds",
|
||||||
default=8,
|
default=8,
|
||||||
min=8,
|
min=4,
|
||||||
max=8,
|
max=8,
|
||||||
step=1,
|
step=2,
|
||||||
display_mode=IO.NumberDisplay.number,
|
display_mode=IO.NumberDisplay.number,
|
||||||
tooltip="Duration of the output video in seconds (Veo 3 only supports 8 seconds)",
|
tooltip="Duration of the output video in seconds",
|
||||||
optional=True,
|
optional=True,
|
||||||
),
|
),
|
||||||
IO.Boolean.Input(
|
IO.Boolean.Input(
|
||||||
@ -332,10 +330,10 @@ class Veo3VideoGenerationNode(VeoVideoGenerationNode):
|
|||||||
options=[
|
options=[
|
||||||
"veo-3.1-generate",
|
"veo-3.1-generate",
|
||||||
"veo-3.1-fast-generate",
|
"veo-3.1-fast-generate",
|
||||||
|
"veo-3.1-lite",
|
||||||
"veo-3.0-generate-001",
|
"veo-3.0-generate-001",
|
||||||
"veo-3.0-fast-generate-001",
|
"veo-3.0-fast-generate-001",
|
||||||
],
|
],
|
||||||
default="veo-3.0-generate-001",
|
|
||||||
tooltip="Veo 3 model to use for video generation",
|
tooltip="Veo 3 model to use for video generation",
|
||||||
optional=True,
|
optional=True,
|
||||||
),
|
),
|
||||||
@ -356,21 +354,111 @@ class Veo3VideoGenerationNode(VeoVideoGenerationNode):
|
|||||||
],
|
],
|
||||||
is_api_node=True,
|
is_api_node=True,
|
||||||
price_badge=IO.PriceBadge(
|
price_badge=IO.PriceBadge(
|
||||||
depends_on=IO.PriceBadgeDepends(widgets=["model", "generate_audio"]),
|
depends_on=IO.PriceBadgeDepends(widgets=["model", "generate_audio", "resolution", "duration_seconds"]),
|
||||||
expr="""
|
expr="""
|
||||||
(
|
(
|
||||||
$m := widgets.model;
|
$m := widgets.model;
|
||||||
|
$r := widgets.resolution;
|
||||||
$a := widgets.generate_audio;
|
$a := widgets.generate_audio;
|
||||||
($contains($m,"veo-3.0-fast-generate-001") or $contains($m,"veo-3.1-fast-generate"))
|
$seconds := widgets.duration_seconds;
|
||||||
? {"type":"usd","usd": ($a ? 1.2 : 0.8)}
|
$pps :=
|
||||||
: ($contains($m,"veo-3.0-generate-001") or $contains($m,"veo-3.1-generate"))
|
$contains($m, "lite")
|
||||||
? {"type":"usd","usd": ($a ? 3.2 : 1.6)}
|
? ($r = "1080p" ? ($a ? 0.08 : 0.05) : ($a ? 0.05 : 0.03))
|
||||||
: {"type":"range_usd","min_usd":0.8,"max_usd":3.2}
|
: $contains($m, "3.1-fast")
|
||||||
|
? ($r = "4k" ? ($a ? 0.30 : 0.25) : $r = "1080p" ? ($a ? 0.12 : 0.10) : ($a ? 0.10 : 0.08))
|
||||||
|
: $contains($m, "3.1-generate")
|
||||||
|
? ($r = "4k" ? ($a ? 0.60 : 0.40) : ($a ? 0.40 : 0.20))
|
||||||
|
: $contains($m, "3.0-fast")
|
||||||
|
? ($a ? 0.15 : 0.10)
|
||||||
|
: ($a ? 0.40 : 0.20);
|
||||||
|
{"type":"usd","usd": $pps * $seconds}
|
||||||
)
|
)
|
||||||
""",
|
""",
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
async def execute(
|
||||||
|
cls,
|
||||||
|
prompt,
|
||||||
|
aspect_ratio="16:9",
|
||||||
|
resolution="720p",
|
||||||
|
negative_prompt="",
|
||||||
|
duration_seconds=8,
|
||||||
|
enhance_prompt=True,
|
||||||
|
person_generation="ALLOW",
|
||||||
|
seed=0,
|
||||||
|
image=None,
|
||||||
|
model="veo-3.0-generate-001",
|
||||||
|
generate_audio=False,
|
||||||
|
):
|
||||||
|
if "lite" in model and resolution == "4k":
|
||||||
|
raise Exception("4K resolution is not supported by the veo-3.1-lite model.")
|
||||||
|
|
||||||
|
model = MODELS_MAP[model]
|
||||||
|
|
||||||
|
instances = [{"prompt": prompt}]
|
||||||
|
if image is not None:
|
||||||
|
image_base64 = tensor_to_base64_string(image)
|
||||||
|
if image_base64:
|
||||||
|
instances[0]["image"] = {"bytesBase64Encoded": image_base64, "mimeType": "image/png"}
|
||||||
|
|
||||||
|
parameters = {
|
||||||
|
"aspectRatio": aspect_ratio,
|
||||||
|
"personGeneration": person_generation,
|
||||||
|
"durationSeconds": duration_seconds,
|
||||||
|
"enhancePrompt": True,
|
||||||
|
"generateAudio": generate_audio,
|
||||||
|
}
|
||||||
|
if negative_prompt:
|
||||||
|
parameters["negativePrompt"] = negative_prompt
|
||||||
|
if seed > 0:
|
||||||
|
parameters["seed"] = seed
|
||||||
|
if "veo-3.1" in model:
|
||||||
|
parameters["resolution"] = resolution
|
||||||
|
|
||||||
|
initial_response = await sync_op(
|
||||||
|
cls,
|
||||||
|
ApiEndpoint(path=f"/proxy/veo/{model}/generate", method="POST"),
|
||||||
|
response_model=VeoGenVidResponse,
|
||||||
|
data=VeoGenVidRequest(
|
||||||
|
instances=instances,
|
||||||
|
parameters=parameters,
|
||||||
|
),
|
||||||
|
)
|
||||||
|
|
||||||
|
poll_response = await poll_op(
|
||||||
|
cls,
|
||||||
|
ApiEndpoint(path=f"/proxy/veo/{model}/poll", method="POST"),
|
||||||
|
response_model=VeoGenVidPollResponse,
|
||||||
|
status_extractor=lambda r: "completed" if r.done else "pending",
|
||||||
|
data=VeoGenVidPollRequest(operationName=initial_response.name),
|
||||||
|
poll_interval=5.0,
|
||||||
|
estimated_duration=AVERAGE_DURATION_VIDEO_GEN,
|
||||||
|
)
|
||||||
|
|
||||||
|
if poll_response.error:
|
||||||
|
raise Exception(f"Veo API error: {poll_response.error.message} (code: {poll_response.error.code})")
|
||||||
|
|
||||||
|
response = poll_response.response
|
||||||
|
filtered_count = response.raiMediaFilteredCount
|
||||||
|
if filtered_count:
|
||||||
|
reasons = response.raiMediaFilteredReasons or []
|
||||||
|
reason_part = f": {reasons[0]}" if reasons else ""
|
||||||
|
raise Exception(
|
||||||
|
f"Content blocked by Google's Responsible AI filters{reason_part} "
|
||||||
|
f"({filtered_count} video{'s' if filtered_count != 1 else ''} filtered)."
|
||||||
|
)
|
||||||
|
|
||||||
|
if response.videos:
|
||||||
|
video = response.videos[0]
|
||||||
|
if video.bytesBase64Encoded:
|
||||||
|
return IO.NodeOutput(InputImpl.VideoFromFile(BytesIO(base64.b64decode(video.bytesBase64Encoded))))
|
||||||
|
if video.gcsUri:
|
||||||
|
return IO.NodeOutput(await download_url_to_video_output(video.gcsUri))
|
||||||
|
raise Exception("Video returned but no data or URL was provided")
|
||||||
|
raise Exception("Video generation completed but no video was returned")
|
||||||
|
|
||||||
|
|
||||||
class Veo3FirstLastFrameNode(IO.ComfyNode):
|
class Veo3FirstLastFrameNode(IO.ComfyNode):
|
||||||
|
|
||||||
@ -394,7 +482,7 @@ class Veo3FirstLastFrameNode(IO.ComfyNode):
|
|||||||
default="",
|
default="",
|
||||||
tooltip="Negative text prompt to guide what to avoid in the video",
|
tooltip="Negative text prompt to guide what to avoid in the video",
|
||||||
),
|
),
|
||||||
IO.Combo.Input("resolution", options=["720p", "1080p"]),
|
IO.Combo.Input("resolution", options=["720p", "1080p", "4k"]),
|
||||||
IO.Combo.Input(
|
IO.Combo.Input(
|
||||||
"aspect_ratio",
|
"aspect_ratio",
|
||||||
options=["16:9", "9:16"],
|
options=["16:9", "9:16"],
|
||||||
@ -424,8 +512,7 @@ class Veo3FirstLastFrameNode(IO.ComfyNode):
|
|||||||
IO.Image.Input("last_frame", tooltip="End frame"),
|
IO.Image.Input("last_frame", tooltip="End frame"),
|
||||||
IO.Combo.Input(
|
IO.Combo.Input(
|
||||||
"model",
|
"model",
|
||||||
options=["veo-3.1-generate", "veo-3.1-fast-generate"],
|
options=["veo-3.1-generate", "veo-3.1-fast-generate", "veo-3.1-lite"],
|
||||||
default="veo-3.1-fast-generate",
|
|
||||||
),
|
),
|
||||||
IO.Boolean.Input(
|
IO.Boolean.Input(
|
||||||
"generate_audio",
|
"generate_audio",
|
||||||
@ -443,26 +530,20 @@ class Veo3FirstLastFrameNode(IO.ComfyNode):
|
|||||||
],
|
],
|
||||||
is_api_node=True,
|
is_api_node=True,
|
||||||
price_badge=IO.PriceBadge(
|
price_badge=IO.PriceBadge(
|
||||||
depends_on=IO.PriceBadgeDepends(widgets=["model", "generate_audio", "duration"]),
|
depends_on=IO.PriceBadgeDepends(widgets=["model", "generate_audio", "duration", "resolution"]),
|
||||||
expr="""
|
expr="""
|
||||||
(
|
(
|
||||||
$prices := {
|
|
||||||
"veo-3.1-fast-generate": { "audio": 0.15, "no_audio": 0.10 },
|
|
||||||
"veo-3.1-generate": { "audio": 0.40, "no_audio": 0.20 }
|
|
||||||
};
|
|
||||||
$m := widgets.model;
|
$m := widgets.model;
|
||||||
$ga := (widgets.generate_audio = "true");
|
$r := widgets.resolution;
|
||||||
|
$ga := widgets.generate_audio;
|
||||||
$seconds := widgets.duration;
|
$seconds := widgets.duration;
|
||||||
$modelKey :=
|
$pps :=
|
||||||
$contains($m, "veo-3.1-fast-generate") ? "veo-3.1-fast-generate" :
|
$contains($m, "lite")
|
||||||
$contains($m, "veo-3.1-generate") ? "veo-3.1-generate" :
|
? ($r = "1080p" ? ($ga ? 0.08 : 0.05) : ($ga ? 0.05 : 0.03))
|
||||||
"";
|
: $contains($m, "fast")
|
||||||
$audioKey := $ga ? "audio" : "no_audio";
|
? ($r = "4k" ? ($ga ? 0.30 : 0.25) : $r = "1080p" ? ($ga ? 0.12 : 0.10) : ($ga ? 0.10 : 0.08))
|
||||||
$modelPrices := $lookup($prices, $modelKey);
|
: ($r = "4k" ? ($ga ? 0.60 : 0.40) : ($ga ? 0.40 : 0.20));
|
||||||
$pps := $lookup($modelPrices, $audioKey);
|
{"type":"usd","usd": $pps * $seconds}
|
||||||
($pps != null)
|
|
||||||
? {"type":"usd","usd": $pps * $seconds}
|
|
||||||
: {"type":"range_usd","min_usd": 0.4, "max_usd": 3.2}
|
|
||||||
)
|
)
|
||||||
""",
|
""",
|
||||||
),
|
),
|
||||||
@ -482,6 +563,9 @@ class Veo3FirstLastFrameNode(IO.ComfyNode):
|
|||||||
model: str,
|
model: str,
|
||||||
generate_audio: bool,
|
generate_audio: bool,
|
||||||
):
|
):
|
||||||
|
if "lite" in model and resolution == "4k":
|
||||||
|
raise Exception("4K resolution is not supported by the veo-3.1-lite model.")
|
||||||
|
|
||||||
model = MODELS_MAP[model]
|
model = MODELS_MAP[model]
|
||||||
initial_response = await sync_op(
|
initial_response = await sync_op(
|
||||||
cls,
|
cls,
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user