Skip to content

Commit bbb11e2

Browse files
authored
fix(api-nodes): Topaz 4k video upscaling (#11438)
1 parent 0899012 commit bbb11e2

File tree

1 file changed

+28
-7
lines changed

1 file changed

+28
-7
lines changed

comfy_api_nodes/nodes_topaz.py

Lines changed: 28 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,6 @@
2323
"Starlight (Astra) Fast": "slf-1",
2424
"Starlight (Astra) Creative": "slc-1",
2525
}
26-
UPSCALER_VALUES_MAP = {
27-
"FullHD (1080p)": 1920,
28-
"4K (2160p)": 3840,
29-
}
3026

3127

3228
class TopazImageEnhance(IO.ComfyNode):
@@ -214,7 +210,7 @@ def define_schema(cls):
214210
IO.Video.Input("video"),
215211
IO.Boolean.Input("upscaler_enabled", default=True),
216212
IO.Combo.Input("upscaler_model", options=list(UPSCALER_MODELS_MAP.keys())),
217-
IO.Combo.Input("upscaler_resolution", options=list(UPSCALER_VALUES_MAP.keys())),
213+
IO.Combo.Input("upscaler_resolution", options=["FullHD (1080p)", "4K (2160p)"]),
218214
IO.Combo.Input(
219215
"upscaler_creativity",
220216
options=["low", "middle", "high"],
@@ -306,8 +302,33 @@ async def execute(
306302
target_frame_rate = src_frame_rate
307303
filters = []
308304
if upscaler_enabled:
309-
target_width = UPSCALER_VALUES_MAP[upscaler_resolution]
310-
target_height = UPSCALER_VALUES_MAP[upscaler_resolution]
305+
if "1080p" in upscaler_resolution:
306+
target_pixel_p = 1080
307+
max_long_side = 1920
308+
else:
309+
target_pixel_p = 2160
310+
max_long_side = 3840
311+
ar = src_width / src_height
312+
if src_width >= src_height:
313+
# Landscape or Square; Attempt to set height to target (e.g., 2160), calculate width
314+
target_height = target_pixel_p
315+
target_width = int(target_height * ar)
316+
# Check if width exceeds standard bounds (for ultra-wide e.g., 21:9 ARs)
317+
if target_width > max_long_side:
318+
target_width = max_long_side
319+
target_height = int(target_width / ar)
320+
else:
321+
# Portrait; Attempt to set width to target (e.g., 2160), calculate height
322+
target_width = target_pixel_p
323+
target_height = int(target_width / ar)
324+
# Check if height exceeds standard bounds
325+
if target_height > max_long_side:
326+
target_height = max_long_side
327+
target_width = int(target_height * ar)
328+
if target_width % 2 != 0:
329+
target_width += 1
330+
if target_height % 2 != 0:
331+
target_height += 1
311332
filters.append(
312333
topaz_api.VideoEnhancementFilter(
313334
model=UPSCALER_MODELS_MAP[upscaler_model],

0 commit comments

Comments
 (0)